WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

WinAppDriver using deprecated JSON wire protocol

Open TroyWalshProf opened this issue 2 years ago • 23 comments

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

Notes*

  • Without this update new version of Appium many not be able to work with WinAppDriver.
  • The Edge WebDriver is already W3C compliant so I am guessing @bwalderman may have some sort of cheatsheet or guidance for becoming W3C compliant.

TroyWalshProf avatar Oct 01 '21 15:10 TroyWalshProf

Have you tried

appCapabilities.SetCapability("ms:experimental-webdriver", true);

licanhua avatar Oct 07 '21 23:10 licanhua

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

TroyWalshProf avatar Oct 11 '21 20:10 TroyWalshProf

@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.

bwalderman avatar Oct 11 '21 21:10 bwalderman

@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

TroyWalshProf avatar Oct 11 '21 21:10 TroyWalshProf

@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,

licanhua avatar Oct 12 '21 01:10 licanhua

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

TroyWalshProf avatar Oct 12 '21 13:10 TroyWalshProf

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:

DHowett avatar Oct 15 '21 18:10 DHowett

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

oyzar avatar Oct 28 '21 05:10 oyzar

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

Wolfe1 avatar Nov 03 '21 14:11 Wolfe1

@DHowett - Any update on this?

TroyWalshProf avatar Jan 18 '22 22:01 TroyWalshProf

@DHowett - Is this a dead project?

TroyWalshProf avatar Feb 07 '22 21:02 TroyWalshProf

any updates?

maslovskyj avatar Feb 11 '22 10:02 maslovskyj

Bueller, Bueller, Bueller, Bueller Anyone? Bueller

TroyWalshProf avatar Feb 15 '22 14:02 TroyWalshProf

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

Ezzysci avatar Feb 17 '22 22:02 Ezzysci

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

licanhua avatar Feb 17 '22 22:02 licanhua

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

TroyWalshProf avatar Feb 18 '22 13:02 TroyWalshProf

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.

licanhua avatar Feb 18 '22 17:02 licanhua

@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.

Ezzysci avatar Feb 18 '22 17:02 Ezzysci

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?

farnsword avatar Feb 22 '22 13:02 farnsword

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

licanhua avatar Feb 22 '22 17:02 licanhua

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

farnsword avatar Feb 22 '22 17:02 farnsword

@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 !!

maielgendy avatar Sep 08 '22 10:09 maielgendy

Maybe you can start with Java Sample

licanhua avatar Sep 08 '22 16:09 licanhua

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

manwalrachi avatar Oct 28 '22 10:10 manwalrachi

@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: [email protected] thanks.

bwomsm1 avatar Nov 01 '22 07:11 bwomsm1