question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple Instances of WinForms application being loaded up

See original GitHub issue

Hello,

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:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
hicks86commented, Jul 29, 2021

@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:

                DesiredCapabilities appCapabilities = new DesiredCapabilities();
                appCapabilities.SetCapability("platformName", "Windows");
                appCapabilities.SetCapability("deviceName", "WindowsPC");
                appCapabilities.SetCapability("app", "C:\MyApp.exe");
                appCapabilities.SetCapability("ms:waitForAppLaunch", "10");

                WindowsDriver<WindowsElement> appSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);

                // 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));

                return appSession;
0reactions
hicks86commented, Jul 29, 2021

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How can I prevent launching my app multiple times?
At program startup check if same process is already running: using System.Diagnostics; static void Main(string[] args) { String ...
Read more >
When running multiple instances of ...
Running the 3rd instance of VS while 1st is in idle and the 2nd is running in debug (F5) a Winform app the...
Read more >
How can I set up a many-formed WinForms application to ...
I have a WinForms app with several forms where, in order to avoid behavioral conflicts with other apps, including other instances of itself...
Read more >
How do I run multiple instances of same exe with different ...
Second approach what I thought is to create one windows application which will create different directory and copy exe's, dll , configuration ...
Read more >
How to Restrict the Application to Just One Instance
This article provides an introduction to Mutexes and their usage to restrict the application to just one instance.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found