microsoft / WinAppDriver

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

Win app driver not working in Selenium Webdriver Typescript #1988

Open laksman2003 opened 6 months ago

laksman2003 commented 6 months ago

Trying to use Win App Driver with Typescript to automate a Windows Desktop App. And when I run the below code in any test framework I get a 400 error in win app driver and I see a error message browser is mandatory eventhough am testing a desktop app.

And when I give a some value for browserName it still gives 400 error in win app driver with error message either app or appLevelTopWindow should be given

app is Root so I can iterate through all available apps. The same approach works with C# Webdriver and with C# as coding language but not working with Typescript with Selenium Webdriver and Selenium Appium

const capabilities = {
  platformName: 'Windows',
  deviceName: 'WindowsPC',
  app: 'Root' 
};

await driver.startWithCapabilities(capabilities);

Below are libraries used in node js Selenium-webdriver: 4.18.1 Selenium-appium: 4.1.22

anunay1 commented 6 months ago

Selenium 4 will not work, you need to downgrade to selenium 3

laksman2003 commented 5 months ago

Its is working after downgrading to Selenium "selenium-webdriver": "3.6.0" and "selenium-appium": "1.0.2" But its very slow in finding new windows which appear in app. But while using .net C# it is very fast in finding the same windows with same selectors.

Is there a reason why Windows App Driver is quite slow (over 2 minutes) in finding new windows with Typescript but faster with C# .net Webdriver? C# .Net webdriver version am using is Selenium.WebDriver - 3.141.0 and Appium.WebDriver - 4.4.5

MagdelineNg commented 5 months ago

@anunay1 Is Selenium 4 totally out of support? I am writing a Python script to automate a Win app that uses MS WebView2, and i want to automate that webview using Selenium 4's Attach to Session feature, similar to this issue

Edit: It seems like there are users using Selenium 4 https://github.com/microsoft/WinAppDriver/issues/1668

anunay1 commented 5 months ago

Yes it is unfortunately.

anunay1 commented 5 months ago

And python language binding has other issues like action classes does not work properly. You might face issues like right click and all.

MagdelineNg commented 5 months ago

@anunay1 Yep, I realised problems in locating elements using the Selenium webdrivers when I upgrade to Selenium 4. For example,

    time_and_language_menu_bar = settings_driver.find_element_by_xpath(config_file["xpaths"]["TimeAndLanguageMenuBar"])   
    print("time_and_language_menu_bar: ", time_and_language_menu_bar)  #returns a dictionary instead of the WebElement
    time_and_language_menu_bar.click()  #error

Are there any ways to automate the WebView2 using Selenium 3, as I understand WinAppDriver is not able to automate WebViews? Or are there any ways to overcome these issues with Selenium 4?

anunay1 commented 5 months ago

I don't know what your compulsion is with python is? Is it your project call? But moving to C# will be a good option. And follow the link in the ticket you have mentioned above.

MagdelineNg commented 5 months ago

@anunay1 hi, my project is able to switch to C#, but I would still have to use selenium 3 as winappdriver does not support selenium 4. Will automating Microsoft webview be a problem with selenium 3 (I am referring to this link https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/webdriver#attaching-microsoft-edge-webdriver-to-the-launched-webview2-app)

anunay1 commented 5 months ago

I don't think so. As long as you are on selenium 3.

MagdelineNg commented 5 months ago

@anunay1 Hi, Selenium 3 does not actually support webview2 according to https://github.com/MicrosoftEdge/WebView2Feedback/discussions/3892#discussioncomment-7244130 . Will WinAppDriver work with Selenium 4 in C# Nunit?

anunay1 commented 5 months ago

I don't know I have not tried.