【问题标题】:How to start WinAppDriver programmatically in the remote machine如何在远程机器上以编程方式启动 WinAppDriver
【发布时间】:2021-01-11 20:36:01
【问题描述】:

我的测试设置由两台 Windows 机器组成,第一台测试运行器将在 c# 中包含我的测试代码,第二台测试代理机器安装了 winappdriver 以及被测应用程序。

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

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

【问题讨论】:

    标签: automation winappdriver


    【解决方案1】:

    对于 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 方法的一部分。

    【讨论】:

      【解决方案2】:

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

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

      测试运行后,如果要关闭 Winappdriver,可以使用 AfterTestRun 属性。 Basepage 有 WinappDriver 的静态实例

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-10-02
        • 1970-01-01
        • 2015-08-10
        • 2017-10-22
        • 2010-09-22
        • 2011-06-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多