Search code examples
c#white-frameworkmicrosoft-ui-automation

How do White work on already running application?


I am using testStack/White library to automate an application. Right now its working fine but it throws exception if the application is already running. Is there any way to put a check e.g if application is already running then do not invoke it. i mean, then we can skip this line of code

Application application = Application.Launch(@"someapplication.exe");

I could not find any good documentation of White. Any help will be appreciated.


Solution

  • you could do:

    Application application;
    Process[] processes = Process.GetProcessesByName(@"someapplication");
    if (processes.Length == 0)
      application = Application.Launch(@"someapplication");
    else
      application = Application.Attach(@"someapplication");
    

    happy coding