microsoft / WinAppDriver

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

OpenQA.Selenium.WebDriverException: Currently selected window has been closed #1599

Open azharashra05 opened 3 years ago

azharashra05 commented 3 years ago

Hii,

I am running UI testing testcases for UWP(C#) application.It is working fine on my local machine,when i tried to run on ms hosted agent,most testcases are failing with error like Currently selected windows has closed.I have verified,i am prroviding same configuration for ms hosted agent like local machine.

I request your kind help in this regard.

Thank you in advance.

naeemakram commented 3 years ago

Try to use the following AppiumOption with a value like 3 or 5. This will introduce a short delay when your application will be started and WAD will try to find the application window a little later and most likely succeed. ms:waitForAppLaunch

azharashra05 commented 3 years ago

Thanks @naeemakram,I have tried your specified capibilities,still some testcases are failing due to currently selected window has been closed.Some testcases are passing in one run but it's uncertain in next run.It is failing due to this error.

Sample code, var appiumoptions = new AppiumOptions(); appiumoptions.AddAdditionalCapability("ms:waitForAppLaunch","40"); var session = new WindowsDriver(new Uri(WindowsApplicationDriverUrl), appiumoptions); session.Manage().Timeouts().ImplicitWait = TimeSpan.FromMinutes(2);

anunay1 commented 3 years ago

Your application has a splash screen, you need to create a root session and then switch to the application. Read the FAQ

azharashra05 commented 3 years ago

Your application has a splash screen, you need to create a root session and then switch to the application. Read the FAQ

My application does not have splash screen

anunay1 commented 3 years ago

Then your application might not be launching on the hosted machine.

Shakevg commented 3 years ago

@azharashra05 Is this error appeared just after creating a session? If yes try to use try cache and then create a session from root session or by the process.

azharashra05 commented 3 years ago

@Shakevg I have run testcase manually on self hosted agent,I figured out,it failed in odd times and failed after 3-4 mins.I am using method to create session.

Shakevg commented 3 years ago

@azharashra05 Could you post a code example that failed?