microsoft / WinAppDriver

Windows Application Driver
MIT License
3.7k stars 1.41k forks source link

Not able to interact with window due to "error":"unknown error","message":"Failed to locate opened application window with appId: C:\\Windows\\System32\\calc.exe error #1372

Open radhakrishnanakireddy opened 3 years ago

radhakrishnanakireddy commented 3 years ago

Hi, I am using Ruby, selenium-webdriver and winapp driver to automate calculator to try it, but I am facing the issue when I launch calculator app with below code

Selenium::WebDriver.logger.level = :info
Selenium::WebDriver.logger.level = :debug
Selenium::WebDriver.logger.output = 'selenium.log'
caps = Selenium::WebDriver::Remote::Capabilities.new
caps['platform'] = 'Windows'
   caps['app'] =  "C:\\windows\\system32\\calc.exe"
   wait = Selenium::WebDriver::Wait.new :timeout => 60
   driver = Selenium::WebDriver.for :remote, url: "http://127.0.0.1:4723", desired_capabilities: caps

Every time I am getting below error from WinAppdriver

status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: C:\\Windows\\System32\\calc.exe, and processId: 14656" Is there anyway to solve this isse in Ruby with selenium-webdriver or any suggestion for it

Note: Above code is working fine when we use ApplicationID as 'Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge' etc, but it is not working If we have any custom apps like PostMan, or Notepad++

Anyone could you please help with this issue and it would be great helpful for RUBY guys

I had referred old questions also, but it did not help me to solve this issue

Thank a lot!

licanhua commented 3 years ago

Can you try C:\Windows\System32\notepad.exe and C:\Windows\notepad.exe? If you are using 1.2RC or 1.2.x WinAppDriver, you may change the timer like this appCapabilities.SetCapability("ms:waitForAppLaunch", "25");. Here 25 is seconds. For the calculator, you should be able to use Microsoft.WindowsCalculator_8wekyb3d8bbwe!App.

radhakrishnanakireddy commented 3 years ago

@licanhua thanks a lot for your reply, I tried using "ms:waitForAppLaunch", but still getting the same issue for calculator if we use "C:\\windows\\system32\\calc.exe" path, but its working fine for C:\Windows\notepad.exe. could you please explain me that what could be reason and it would be useful for all users 👍

licanhua commented 3 years ago

I can reproduce your problem and I think it's a bug of WinAppDriver. I'm not the developer of WinAppDriver, so need @kat-y to confirm it.

If you use procmon, you will find that you launched calc.exe, but the actual application is calculator.exe.(A process launched another process and then killed itself).

There are two possible issues in WinAppDriver:

  1. launched a UWP app from win32 code path. Just like the calculator here. UWP and other app has difference code path, but it's still possible to launch UWP app from CLI and WinAppDriver doesn't know about it
  2. It's possible that WinAppDriver try to match the application root with classname: window, ApplicationFrameWindow. Postman and notepad++ may belongs to this.

I can think of the only workaround for you is(I didn't do the testing):

  1. Launch the application just like what you did here.
  2. If the app is killed, You have to wait for the WinAppDriver fix. If the application is still alive like calculator, you can continue
  3. ignore the failure, and start another session with
        appCapabilities.SetCapability("app", "Root");
        appCapabilities.SetCapability("appTopLevelWindow", "Calculator");

    then continue the testing just like before.