dotnet-client icon indicating copy to clipboard operation
dotnet-client copied to clipboard

Failed to locate opened application window with appId

Open EbenZhang opened this issue 4 years ago • 4 comments

Description

I'm using Appnium + WinAppDriver + SpecFlow to test my desktop application. BTW I'm a very beginner to the whole suite.

The project was using v3.0.2 and worked fine, after upgraded to 4.1.1, I got an error Failed to locate opened application window with appId

Any clue will be appriciated.

Environment

  • Windows 10 Pro 64 bits, build 18362
  • WinAppDriver v1.1
  • Appium.WebDriver 4.1.1
  • Selenium.WebDriver 3.141.0
  • Selenium.Support 3.141.0

Details

Looks like 3.0.2 will wait for the application to launch whereas 4.1.1 give the error immediately.

To upgrade to 4.1.1, I have done some small code change to change the DesiredCapacities to AppniumOptions.

The application takes a bit time to start, not sure if this is the cause.

Exception stacktraces

OpenQA.Selenium.WebDriverException : Failed to locate opened application window with appId: 
C:\Program Files (x86)\xxx\yyy.exe, and processId: 32932
   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Appium.AppiumDriver`1..ctor(Uri remoteAddress, ICapabilities appiumOptions)

Sample Code

After upgraded:

var appCapabilities = new AppiumOptions();
appCapabilities.AddAdditionalCapability("app", app.InstallPath);
appCapabilities.AddAdditionalCapability("deviceName", Environment.MachineName);
appCapabilities.AddAdditionalCapability("appWorkingDir", app.Directory);
new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);

Before upgraded:

var appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", app.InstallPath);
appCapabilities.SetCapability("deviceName", Environment.MachineName);
appCapabilities.SetCapability("appWorkingDir", app.Directory);
new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);

Link to Appium logs

I'm not sure where to get Appium the log.

EbenZhang avatar Jul 15 '20 08:07 EbenZhang

I get this from time to time. I just restart the app that I was running and recreate the session. I would like to know how I can avoid it.

peteferraro avatar Jul 15 '20 12:07 peteferraro

Does you window has a splash screen?

anunay1 avatar Aug 17 '20 14:08 anunay1

it has one but not implemented properly, the splashscreen is a WinForms window doesn't show immediately but a few seconds after something loaded

EbenZhang avatar Aug 18 '20 02:08 EbenZhang

Then you need to create a root session and switch to the opened window:

string mainWindowTitle = "";
                var allProcesses1 = Process.GetProcesses();
                foreach (Process process in allProcesses1)
                {
                    if (process.ProcessName.Contains("RobotStudio"))
                    {
                        mainWindowTitle = process.MainWindowTitle;
                        Logger.Logger.LogInfo("The main window title is " + mainWindowTitle);
                        
                    }
                }

                DesiredCapabilities desktopCapabilities = new DesiredCapabilities();
                desktopCapabilities.SetCapability("app", "Root");
                desktopSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), desktopCapabilities);
                Assert.IsNotNull(desktopSession);

                var RSWindow = desktopSession.FindElementByName(mainWindowTitle);
                var RSTopLevelWindowHandle = RSWindow.GetAttribute("NativeWindowHandle");
                RSTopLevelWindowHandle = (int.Parse(RSTopLevelWindowHandle)).ToString("x");

                DesiredCapabilities appcapabilities = new DesiredCapabilities();
                appcapabilities.SetCapability("appTopLevelWindow", RSTopLevelWindowHandle);
                driver = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appcapabilities);

anunay1 avatar Aug 18 '20 11:08 anunay1

@EbenZhang can you confirm the issue persist on the latest beta version? 5.0.0-beta2

Dor-bl avatar Oct 31 '22 05:10 Dor-bl

Closed as no response

Dor-bl avatar Nov 16 '22 19:11 Dor-bl

I had the same issue, there are maybe different problems. Here is mine and how I manage to find my problem.

I am using WPF and I was using an AppSettings.json which for some reason couldn't be read when the app is launched through the specflow automation test.

I used something like that in my Startup.cs : _firebaseKey = context.Configuration.GetValue<string>("API_KEY"); which I replace with a temporary hard coded string.

The thing is you will maybe have a totally different error, that said I used a wonderful native Windows tool : "Event Viewer" / "eventvwr." or "Observateur d'évènements" in French. :)

If you go to WindowsLog, you will be able to check if your app crash and also for which reason. :)

image

DamienChailley avatar Apr 20 '24 20:04 DamienChailley