WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

failed to Locate opened application window ?

Open sudeeppaudyal opened this issue 7 years ago • 18 comments

POST /session HTTP/1.1 Accept: application/json, image/png Connection: Keep-Alive Content-Length: 241 Content-Type: application/json;charset=utf-8 Host: 127.0.0.1:4723

HTTP/1.1 500 Internal Error Content-Length: 169 Content-Type: application/json

{"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: C:\Jericho\JerichoLauncher.exe, and processId: 20108"}}

sudeeppaudyal avatar Mar 27 '19 21:03 sudeeppaudyal

Capture

sudeeppaudyal avatar Mar 27 '19 22:03 sudeeppaudyal

Applications opens up after getting system.invalidOperationException.How to resolve this issue?

sudeeppaudyal avatar Mar 27 '19 22:03 sudeeppaudyal

Is there an update on the issue? I am facing this same problem when trying to execute the WinAppDriver tests on Bamboo. Locally the tests work OK.

CataUdrea avatar Apr 09 '19 09:04 CataUdrea

@CataUdrea How are you able to run locally?

sudeeppaudyal avatar Apr 10 '19 22:04 sudeeppaudyal

On my local machine, the tests are executed without any issues. I only get this problem when executing the tests on Bamboo.

I implemented the following steps:

  • I start the winAppDriver
  • define capabilities
  • launch the app
capabilities.setCapability("platformName", "Windows");
capabilities.setCapability("deviceName", "WindowsPC");
capabilities.setCapability("app", applicationUnderTest);
windowsApplicationDriver = new WindowsDriver(new URL("http://127.0.0.1:4723"), capabilities);
windowsApplicationDriver.launchApp();

I get the error from above only on Bamboo

CataUdrea avatar Apr 11 '19 13:04 CataUdrea

I am still getting that error message.Would you mind sharing your email address?

On Thu, Apr 11, 2019 at 8:06 AM CataUdrea [email protected] wrote:

On my local machine, the tests are executed without any issues. I only get this problem when executing the tests on Bamboo.

I implemented the following steps:

  • I start the winAppDriver
  • define capabilities
  • launch the app

capabilities.setCapability("platformName", "Windows"); capabilities.setCapability("deviceName", "WindowsPC"); capabilities.setCapability("app", applicationUnderTest); windowsApplicationDriver = new WindowsDriver(new URL("http://127.0.0.1:4723"), capabilities); windowsApplicationDriver.launchApp();

I get the error from above only on Bamboo

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Microsoft/WinAppDriver/issues/641#issuecomment-482105971, or mute the thread https://github.com/notifications/unsubscribe-auth/ArToDqOsaf6IlaXCanzsRFR8I8eqBYCmks5vfzM-gaJpZM4cO3AZ .

sudeeppaudyal avatar Apr 11 '19 16:04 sudeeppaudyal

Any update on this issue? I'm running into similar issue when running tests in jenkins. The tests work perfectly when I run it locally. One thing I noticed is that my app starts as a background process when running via jenkins script, not very sure if that might be a cause

sdhoka avatar Jun 04 '19 22:06 sdhoka

I am running into similar issue with jenkins. Any updates would be great.

orion-test avatar Jun 26 '19 16:06 orion-test

I just reached this bug after sucesfully making few automated clicks work yesterday. Logging into app, having fun on login screen. Targeting proper .exe file as yesterday, nothing changed and yet application fails to start and I get same error as you: [STDOUT] {"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: my path to .exe..

ghost avatar Jul 31 '19 08:07 ghost

I am running into a similar issue. I found a temporary solution to figure out.

try {
       driver = new WindowsDriver(new URL("http://127.0.0.1:4723"), cap);   
 }
catch (Exception e){
       driver = new WindowsDriver(new URL("http://127.0.0.1:4723"), cap);    
 }

lucas234 avatar Aug 09 '19 03:08 lucas234

Any update on this? I also have this, the tests run fine on my local with both mvn command in within Intellij IDE, but when I execute it on jenkins, it produces this.

I set up my locale machine as a jenkins node and run on this node too, the problem persists though. I tried to get into the jenkins workspace on my local machine, and run the same command I ran on jenkins, and the tests run just fine. So this problem happens on jenkins only.

Please suggest at least a workaround for this.

nhhai avatar Jan 02 '20 04:01 nhhai

Any update on this? I also have this, the tests run fine on my local with both mvn command in within Intellij IDE, but when I execute it on jenkins, it produces this.

I set up my locale machine as a jenkins node and run on this node too, the problem persists though. I tried to get into the jenkins workspace on my local machine, and run the same command I ran on jenkins, and the tests run just fine. So this problem happens on jenkins only.

Please suggest at least a workaround for this.

you can have a try to add try-catch. when some Exception happen, renew a driver instance, just a try, it's suited for me

lucas234 avatar Jan 03 '20 01:01 lucas234

@lucas234 solution worked (try/catch).

See my releases logs it it helps... https://dev.azure.com/jonwolfdev/SimpleWPFTimer/_release?definitionId=1&view=mine&_a=releases

jonvwolf avatar Feb 05 '20 06:02 jonvwolf

I have a clean working solution in Java using the jna library to get the Native Window Handle dynamically and pass it to Desired Capabilities. You will need to use inspect.exe or another similar tool the first time to get the window name, but after that you're done. The only thing is, instead of launching your app with the WinAppSession you need to do it with a Process Builder and use the desired capability of "appTopLevelWindow" like this:

ProcessBuilder pb = new ProcessBuilder();
            String folder  = "Users\\MyAppFolder";
            pb.command(folder +"Myapp.exe");
            pb.start();
            Thread.sleep(7000);

            windowHandle = JNA_Test2.getHex();

            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("appTopLevelWindow", windowHandle);
            capabilities.setCapability("platformName", "Windows");
            capabilities.setCapability("deviceName","WindowsPC");
           driver = new WindowsDriver<WindowsElement>(new URL("http://127.0.0.1:4728"), capabilities);

public class JNA_Test2 {

        public static String  getHex() {
            Pointer foundWindowPointer = new Memory(4096);
            JNA_Test2.isWindowOpen("My app window name", foundWindowPointer);
            String handle = null;
            if (foundWindowPointer.getPointer(0) != null) {
                WinDef.HWND foundWindow = new WinDef.HWND(foundWindowPointer.getPointer(0));
                handle = String.valueOf(foundWindow);
            }
            return handle.substring(7);

        }
        public static void main(String []args){
            getHex();
        }

Here is the maven dependency of jna to add to your pom file:

<dependency>
           <groupId>net.java.dev.jna</groupId>
           <artifactId>jna-platform</artifactId>
           <version>5.5.0</version>
       </dependency>

benzionyunger avatar Feb 24 '20 10:02 benzionyunger

Try to include below capability which solved my issue of Failed to locate opened application window with appId"xxx" and process "xxx"

My exe file present in C:\Program Files\MT

appCapabilities.SetCapability("appWorkingDir", "C:\Program Files\MT");

balaji-githubstore avatar Oct 12 '20 09:10 balaji-githubstore

Hi , Im also facing the similar issue. "Failed to locate opened application window with appId:" . sometimes its launched but not able to see the launched application. so getting "element not found " error. Im trying to automate the applciaion that was developed by Eclipse RCP and launching the exe file to test.

anitakalyanasundaram avatar Oct 29 '20 10:10 anitakalyanasundaram

Run your WinApp driver and eclipse as an administrator. this solved my problem of launching the application.

anitakalyanasundaram avatar Oct 29 '20 12:10 anitakalyanasundaram

@sudeeppaudyal You can create WindowsDriver instance by NativeWindowHandle.

            // Create a session for Desktop
            DesiredCapabilities desktopCapabilities = new DesiredCapabilities();
            desktopCapabilities.SetCapability("app", "Root");
            desktopSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), desktopCapabilities);
            Assert.IsNotNull(desktopSession);

            // Launch Cortana Window using Windows Key + S keyboard shortcut to allow session creation to find it
            desktopSession.Keyboard.SendKeys(OpenQA.Selenium.Keys.Meta + "s" + OpenQA.Selenium.Keys.Meta);
            Thread.Sleep(TimeSpan.FromSeconds(1));
            WindowsElement CortanaWindow = desktopSession.FindElementByName("Cortana");
            string CortanaTopLevelWindowHandle = CortanaTopLevelWindowHandle = (int.Parse(CortanaWindow.GetAttribute("NativeWindowHandle"))).ToString("x");

            // Create session for already running Cortana
            DesiredCapabilities appCapabilities = new DesiredCapabilities();
            appCapabilities.SetCapability("appTopLevelWindow", CortanaTopLevelWindowHandle);
            cortanaSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
            Assert.IsNotNull(cortanaSession);

            // Set implicit timeout to 5 seconds to make element search to retry every 500 ms for at most ten times
            cortanaSession.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

huster-songtao avatar Nov 24 '21 19:11 huster-songtao