Multiple Instances of WinForms application being loaded up
See original GitHub issueHello,
I have setup some tests using WinAppDriver and the Appium nuget package. I am having a problem when starting up the WinForms app for the first time. I use the recommended way of starting up apps (as seen in the code samples) this is what I have:
WindowsDriver<WindowsElement> appSession = null;
if (appSession == null)
{
// Create a new session to bring up an instance of the Calculator application
// Note: Multiple calculator windows (instances) share the same process Id
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("platformName", "Windows");
appCapabilities.SetCapability("deviceName", "WindowsPC");
appCapabilities.SetCapability("app", "C;\MyApp.exe");
for (int attempt = 0; attempt < 10; attempt++)
{
try
{
appSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723/wd/hub"), appCapabilities, TimeSpan.FromSeconds(30));
if (appSession != null)
{
break;
}
}
catch (Exception)
{
Thread.Sleep(TimeSpan.FromSeconds(2));
}
}
Assert.IsNotNull(appSession);
// Set implicit timeout to 1.5 seconds to make element search to retry every 500 ms for at most three times
appSession.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1.5));
This works fine but I find about 2 or three other version of my application are started at the same time. The tests do not struggle they know which one to hook onto and test etc, however when it comes to cleaning up the test I can obviously close down the current app that my tests are testing, however I need to manually close these other instances.
Has anyone come across something like this before? As I say it is a WinForms app so not sure if that is an issue? Is there something I am missing in the above code?
Any help would be appreciated. Thanks
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top GitHub Comments
@anunay1 thank you that worked. So I set the “ms:waitForAppLaunch” initially to “50”, but managed to reduce it down to “10”. I also removed the Timeout parameter in the new WindowsDriver ctor as this seemed to be causing issues with the new capability.
For reference (for anyone else making this mistake etc) this is the code:
@anunay1 OK fair point. I have seen this approach used somewhere else, maybe it is relating to opening up Microsoft Office programs (I’ll try and link it), but can confirm this approach isn’t used in the samples. OK I will try that but 50ms isn’t very long really.