How to start WinAppDriver programmatically in the remote machine

2.4k views Asked by At

My test setup consist of 2 windows machines, first one test runner which will have the my test code in c# and the second one test agent machine where winappdriver is installed along with application under test.

I would like to start the winappdriver in the test agent through the C# code and the code would run on the test runner. Also, I would like to close the winappdriver once test execution is over.

How this could be done? Appreciate any lead on this.

2

There are 2 answers

1
Satyendra Sharma On BEST ANSWER

For Java specific projects: You can Do it in following ways- Assumin WinAppDriver is installed in default location-i.e. C:/Program Files (x86)/Windows Application Driver

1st:
String command = "C:/Program Files (x86)/Windows Application Driver/WinAppDriver.exe";
Runtime.getRuntime().exec(command);

2nd:
 String command = "C:/Program Files (x86)/Windows Application Driver/WinAppDriver.exe";
 ProcessBuilder builder = new ProcessBuilder(command).inheritIO();
 Process process = builder.start();

Dont forget to dispose it by-
        winDriver.close();
        winDriver.quit();

or for 2nd approach-
 process.destroy();

Convert them as part of you init or BeforeTest Methods as needed.

1
Avinash On

You can use [BeforeTestRun] attribute in your Test initialize class. Assuming the winappdriver is installed in the same path in the test machines. I use it in my azure agents

[BeforeTestRun]
        public static void TestSetup()
        {
            Process.Start(@"C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe");
            Process.Start(@"Your application Path");
         
        }

After the test run, if you want to close the Winappdriver, you can use AfterTestRun Attribute. Basepage has the static instance of the WinappDriver

 [AfterTestRun]
        public static void TearDownReport()
        {
            BasePage.WindowsDriver.Close();
            BasePage.WindowsDriver.Dispose();            
        }