Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WinAppDriver using deprecated JSON wire protocol #1610

Open
TroyWalshProf opened this issue Oct 1, 2021 · 27 comments
Open

WinAppDriver using deprecated JSON wire protocol #1610

TroyWalshProf opened this issue Oct 1, 2021 · 27 comments

Comments

@TroyWalshProf
Copy link

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.
@licanhua
Copy link
Contributor

licanhua commented Oct 7, 2021

Have you tried

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

@TroyWalshProf
Copy link
Author

TroyWalshProf commented Oct 11, 2021

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
Copy link

@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
Copy link
Author

@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
Copy link
Contributor

licanhua commented Oct 12, 2021

@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
Copy link
Author

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
Copy link
Member

DHowett commented Oct 15, 2021

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

@oyzar
Copy link

oyzar commented Oct 28, 2021

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

@Wolfe1
Copy link

Wolfe1 commented Nov 3, 2021

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

@TroyWalshProf
Copy link
Author

@DHowett - Any update on this?

@TroyWalshProf
Copy link
Author

@DHowett - Is this a dead project?

@maslovskyj
Copy link

any updates?

@TroyWalshProf
Copy link
Author

Bueller, Bueller, Bueller, Bueller
Anyone?
Bueller

@Ezzysci
Copy link

Ezzysci commented Feb 17, 2022

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

@licanhua
Copy link
Contributor

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
Copy link
Author

@licanhua - using the Appium client works-ish
Basically you are fine until you need to leverage actions:
appium/appium#16268

@licanhua
Copy link
Contributor

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
Copy link

Ezzysci commented Feb 18, 2022

@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
Copy link

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
Copy link
Contributor

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

@farnsword
Copy link

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

@maielgendy
Copy link

maielgendy commented Sep 8, 2022

@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
Copy link
Contributor

licanhua commented Sep 8, 2022

Maybe you can start with Java Sample

@manwalrachi
Copy link

manwalrachi commented Oct 28, 2022

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

@bwomsm1
Copy link

bwomsm1 commented Nov 1, 2022

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

@jonathangiber
Copy link

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
Copy link

bwomsm1 commented Dec 8, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests