如何在远程机器上以编程方式启动 WinAppDriver

How to start WinAppDriver programmatically in the remote machine

我的测试设置包括 2 windows 台机器,第一个测试 运行ner 将在 c# 中包含我的测试代码,第二个测试代理机器安装了 winappdriver 和应用程序正在测试中。

我想通过 C# 代码在测试代理中启动 winappdriver,代码将 运行 用于测试 运行ner。另外,我想在测试执行结束后关闭 winappdriver。

如何做到这一点?感谢这方面的任何线索。

您可以在测试初始化​​中使用 [BeforeTestRun] 属性 class。假设 winappdriver 安装在测试机器的相同路径中。我在我的天蓝色代理中使用它

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

经过测试运行,如果要关闭Winappdriver,可以使用AfterTestRun属性。底页有 WinappDriver

的静态实例
 [AfterTestRun]
        public static void TearDownReport()
        {
            BasePage.WindowsDriver.Close();
            BasePage.WindowsDriver.Dispose();            
        }

针对Java个具体项目:您可以通过以下方式进行- Assumin WinAppDriver 安装在默认位置 - 即C:/Program Files (x86)/Windows 应用程序驱动程序

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

根据需要将它们作为 init 或 BeforeTest 方法的一部分进行转换。