System.InvalidOperationException : Failed to locate opened application window with appId: {PackageFamilyName}!App, and processId: if UWP app tests are run from Jenkins
Hello,
Could you please take a look this issue with catching of UWP application if test is executed via Jenkins?
I have got error when I executed test from Jenkins.
10:10:24 System.InvalidOperationException : Failed to locate opened application window with appId: {PackageFamilyName}!App, and processId: 22944
10:10:24 at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
10:10:24 at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters)
10:10:24 at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
10:10:24 at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
10:10:24 at OpenQA.Selenium.Appium.AppiumDriver1..ctor(Uri remoteAddress, ICapabilities desiredCapabilities)
The code is failed on
AppSession = new WindowsDriver<WindowsElement>(new Uri(uri), (DesiredCapabilities)appCapabilities, DefaultCommandTimeout);
Tested Application is launched and visible on UI, but the app is not caught by winappdriver.
I've modified code as recommended in last comment from https://github.com/Microsoft/WinAppDriver/issues/283:
// Launch the application
try
{
AppSession = new WindowsDriver<WindowsElement>(new Uri(uri), DesiredCapabilities)appCapabilities, DefaultCommandTimeout);
}
catch (Exception e)
{
// Create a session for Desktop
DesiredCapabilities desktopCapabilities = new DesiredCapabilities();
desktopCapabilities.SetCapability("app", "Root");
desktopCapabilities.SetCapability("platformName", "Windows");
desktopCapabilities.SetCapability("deviceName", "WindowsPC");
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.FindElementByName("Search Windows").Click();
//DesktopSession.Keyboard.SendKeys(OpenQA.Selenium.Keys.Meta + "s" + OpenQA.Selenium.Keys.Meta);
DesktopSession.Keyboard.SendKeys("{TestedApp}");
DesktopSession.FindElementByName("{TestedApp}, Windows app").Click();
Thread.Sleep(TimeSpan.FromSeconds(1));
WindowsElement TestedAppWindow = DesktopSession.FindElementByName("{TestedApp}");
String TestedAppTopLevelWindowHandle = TestedAppWindow.GetAttribute("NativeWindowHandle");
TestedAppTopLevelWindowHandle = (int.Parse(TestedAppTopLevelWindowHandle)).ToString("x");
// Create session for already running app
DesiredCapabilities appCapabilities1 = new DesiredCapabilities();
appCapabilities1.SetCapability("appTopLevelWindow", TestedAppTopLevelWindowHandle);
AppSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities1);
Assert.IsNotNull(AppSession);
}
As the result I have got another error:
13:09:57 System.InvalidOperationException : An element could not be located on the page using the given search parameters.
13:09:57 at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
13:09:57 at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters)
13:09:57 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
13:09:57 at OpenQA.Selenium.Appium.AppiumDriver1.FindElementByName(String name)
The code was failed on
DesktopSession.FindElementByName("Search Windows").Click();
if I use DesktopSession.Keyboard.SendKeys(OpenQA.Selenium.Keys.Meta + "s" + OpenQA.Selenium.Keys.Meta);
I've got error: 12:02:13 System.InvalidOperationException : An unknown error occurred in the remote end while processing the command. 12:02:13 at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) 12:02:13 at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) 12:02:13 at OpenQA.Selenium.Remote.RemoteKeyboard.SendKeys(String keySequence)
Note: ExecutionPolicy is 'Unrestricted' on tested environment. Locally all code variants work ok.
The issue is not reproduced after re-creation of new slave agent for Jenkins.
Thank you for the update @svchig!