microsoft / WinAppDriver

Windows Application Driver
MIT License
3.66k stars 1.4k forks source link

WinAppDriver using deprecated JSON wire protocol #1610

Open TroyWalshProf opened 2 years ago

TroyWalshProf commented 2 years ago

This driver is still using the old JsonWireProtocol, which is obsolete . The driver should get updated to the W3C standard standard.

Notes*

licanhua commented 2 years ago

Have you tried

appCapabilities.SetCapability("ms:experimental-webdriver", true);
TroyWalshProf commented 2 years ago

I tried with both https://github.com/microsoft/WinAppDriver/releases/tag/v1.2.1 and https://github.com/microsoft/WinAppDriver/releases/tag/v1.2.99

When I try to connect using a compliant session JSON I get: {"status":100,"value":{"error":"invalid argument","message":"Bad capabilities. Specify either app or appTopLevelWindow to create a session"}}

**Notes***

  1. Here is what the start session json body, which works using Appium, looks like {"capabilities":{"firstMatch":[{"platformName":"Windows","appium:app":"Microsoft.WindowsCalculator_8wekyb3d8bbwe!App","appium:deviceName":"WindowsPC","ms:experimental-webdriver":true}]}}

  2. Also, when we find an element we would expect to get the response in this format: {"value":{"element-6066-11e4-a52e-4f735466cecf":"VALUE.VALUE","ELEMENT":"VALUE.VALUE"}} or {"value":{"element-6066-11e4-a52e-4f735466cecf":"VALUE.VALUE"}} Per the W3C standard But it comes back in this format {"sessionId":"GUID","status":0,"value":{"ELEMENT":"VALUE.VALUE"}}

  3. Jonathan Lipps does a really good job out outline when Appium drives need to know about adhering to the W3C standard https://github.com/jlipps/simple-wd-spec

@licanhua

bwalderman commented 2 years ago

@TroyWalshProf the best cheat sheet I can point you to for W3C compliance is the webdriver spec itself as this is what we used to update the legacy Edge implementation (MicrosoftWebDriver). Our current implementation is inherited from the Chromium project so I wasn't involved in their efforts to match the spec.

In MicrosoftWebDriver, we treat "w3c" and "jwp" (JSON wire protocol) as two separate "dialects" the client may use, but the underlying implementation of the commands is the same. If we detect the client is using W3C-style capabilities in their session request then we switch to w3c mode. The mode determines what commands are available. For example, actions is only available in w3c mode. For commands that are common between both w3c and jwp dialects (such as click), there is only one actual command implementation and the only difference is how the parameters are parsed. The dialect that the client choses will also affect how results and errors are returned. For example, JWP uses numeric error codes but W3C uses strings. Either way, the internal representation of errors in our C++ code is the same, and the choice of dialect only affects how they are rendered in the HTTP response.

TroyWalshProf commented 2 years ago

@bwalderman - That is great news. So how does WinAppDriver detect that the you are using using W3C-style capabilities? AKA what JSON body would you expect *Hopefully I am just doing something dumb

licanhua commented 2 years ago

@TroyWalshProf Are you using appium to connect with WinAppDriver? ms:experimental-webdriver mimics some of the response of W3c, but not all of them.

For {"status":100,"value":{"error":"invalid argument","message":"Bad capabilities. Specify either app or appTopLevelWindow to create a session"}}, likely you send the appium message directly to WinAppDriver without appium. Please remove the appium: prefix in capabilities. appium will remove the prefix before it forwards message to WinAppDriver. but you didn't start appium, it's expected to run into error.

Here is the capabilities I used long time ago to support both appium and without appium connection(I don't know if it's still compatible with appium). Please pay attention to appium:app and app

      platformName: 'windows',
      'appium:deviceName': 'WindowsPC',
      'appium:app': 'ReactUWPTestApp_cezq6h4ygq1hw!App',
      'deviceName': 'WindowsPC',
      'app': 'ReactUWPTestApp_cezq6h4ygq1hw!App',
      'winAppDriver:experimental-w3c': true,
TroyWalshProf commented 2 years ago

This is only an issue when connecting to the WinAppDriver directly.

A little more context: The Appium.Net team is working on an a Selenium 4 related update. The Selenium 4 changes have affected the format of the new session JSON body.
*For better or worse we are largely tied to the Selenium project when it comes to the JSON body format.

I have been unable to make this format work with WinAppDriver 1.2.1 or 1.2.99 Unless I can find a good solution, the next release of Appium.Net will not be able to work with WinAppDriver directly.

Here are the new session bodies I have tried: {"capabilities":[{"platformName":"Windows","appium:app":"Microsoft.WindowsCalculator_8wekyb3d8bbwe!App","app":"Microsoft.WindowsCalculator_8wekyb3d8bbwe!App","appium:deviceName":"WindowsPC","winAppDriver:experimental-w3c":true}]}

{"capabilities":[{"platformName":"Windows","app":"Microsoft.WindowsCalculator_8wekyb3d8bbwe!App","appium:deviceName":"WindowsPC","winAppDriver:experimental-w3c":true}]}

{"capabilities":{"firstMatch":[{"platformName":"Windows","app":"Microsoft.WindowsCalculator_8wekyb3d8bbwe!App","appium:app":"Microsoft.WindowsCalculator_8wekyb3d8bbwe!App","appium:deviceName":"WindowsPC","winAppDriver:experimental-w3c":true}]}}

{"capabilities":{"firstMatch":[{"platformName":"Windows","app":"Microsoft.WindowsCalculator_8wekyb3d8bbwe!App","appium:deviceName":"WindowsPC","winAppDriver:experimental-w3c":true}]}}

And not to be that guy, but it seems like things would be a little easier if WinAppDriver was actually open source :)

@licanhua

DHowett commented 2 years ago

I'm digging into this right now so that I can form an engineering plan for updating it. This is a lot, and I can't promise that my nascent familiarity with the codebase is going to be of much help. Stay tuned. :smile:

oyzar commented 2 years ago

Great to hear someone is working on this. Hope it's feasible to figure out a solution for this.

Wolfe1 commented 2 years ago

@DHowett Really great to hear, thank you for the update.

TroyWalshProf commented 2 years ago

@DHowett - Any update on this?

TroyWalshProf commented 2 years ago

@DHowett - Is this a dead project?

maslovskyj commented 2 years ago

any updates?

TroyWalshProf commented 2 years ago

Bueller, Bueller, Bueller, Bueller Anyone? Bueller

Ezzysci commented 2 years ago

who is working on this? I had to downgrade everything for it to work.

licanhua commented 2 years ago

Instead of the direct connection with WinAppDriver, you can use Appium as the bridge between. I saw appium-windows-driver is open sourced and supports W3C

Here are two kinds of connections:

  1. client <-> appium <-> appium-windows-driver <-> WinAppDriver
  2. client <-> WinAppDriver
TroyWalshProf commented 2 years ago

@licanhua - using the Appium client works-ish Basically you are fine until you need to leverage actions: https://github.com/appium/appium/issues/16268

licanhua commented 2 years ago

Apparently, the community projects like Appium iterate faster than WinAppDriver. My opinion:

  1. Keep your test framework in old version, and wait for WinAppDriver fix
  2. Alternatively, you may drive and fix it from the community side and contribute your fix to existing open-source projects. I don't think Appium accepts deprecated JWP PRs, so appium-windows-driver or other open-source project are your options. appium-windows-driver plays some magic in the middle which can convert W3C action chains to JWP ones, so it's possible for you to fix it here too.

The second one is the one you can see the progress and control it fully from your side.

Ezzysci commented 2 years ago

@licanhua Thank you for the advice. I will test. I've already downgraded so it'll be in the future. I'm an amateur at this. Trying to set up automated QA as a side project for the company I work at.

farnsword commented 2 years ago

Instead of the direct connection with WinAppDriver, you can use Appium as the bridge between. I saw appium-windows-driver is open sourced and supports W3C

Here are two kinds of connections:

  1. client <-> appium <-> appium-windows-driver <-> WinAppDriver
  2. client <-> WinAppDriver

Hi @licanhua Could you, please, drive me in the direction of the first approach? How do I use Appium as the bridge?

At this point, I have a Java project with appium.java_client dependency and when I create WindowsDriver I pass the URL to where WinAppDriver is running. Should have an Appium server running as well? And if so - how would I redirect requests from the Appium server to WinAppDriver? Or does it run WinAppDriver somewhere inside?

licanhua commented 2 years ago

Please follow https://github.com/microsoft/WinAppDriver/blob/master/Docs/UsingAppium.md

farnsword commented 2 years ago

Awesome, I'll follow it. Thanks a lot!

maielgendy commented 2 years ago

@licanhua

Apparently, the community projects like Appium iterate faster than WinAppDriver. My opinion:

  1. Keep your test framework in old version, and wait for WinAppDriver fix
  2. Alternatively, you may drive and fix it from the community side and contribute your fix to existing open-source projects. I don't think Appium accepts deprecated JWP PRs, so appium-windows-driver or other open-source project are your options. appium-windows-driver plays some magic in the middle which can convert W3C action chains to JWP ones, so it's possible for you to fix it here too.

The second one is the one you can see the progress and control it fully from your side.

is there any example how to use it in java project? I'm totaly lost with node !!

licanhua commented 2 years ago

Maybe you can start with Java Sample

manwalrachi commented 1 year ago

Is there any update on this? Can we now use WinAppDriver with Selenium 4?

bwomsm1 commented 1 year ago

@licanhua @DHowett I can help you guys to reproduce the problem in debug mode (if you have issue in that), you can contact me on email: boaz.warshawsky@sbdinc.com thanks.

jonathangiber commented 1 year ago

Hi guys, Is there any example out there how to use winappdriver without appium when trying to automate windows applications? I couldn't find anything. Any help will be appreciated

bwomsm1 commented 1 year ago

Hi guys, Is there any example out there how to use winappdriver without appium when trying to automate windows applications? I couldn't find anything. Any help will be appreciated

@jonathangiber yes, you should use the same appium python libs, but connect to WinAppDriver server instead of appium server. Launch the WinAppDriver server from cli.

You can reach me in LinkedIn if you are stuck.