簡體   English   中英

Appium,Cucumber和Junit如何在多個設備上並行運行測試

[英]Appium, Cucumber and Junit how to run tests in parallel on multiple devices

嘗試在多個設備上並行執行我的appium測試。

我目前可以在一台Android設備上執行測試用例。 經過修改和修改后,我無法使測試並行運行。

這是我當前的設置。 希望可以並行執行測試,而不需要醬實驗室或硒網格。

我的Junit跑步者示例

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"json:target/cucumber.json", "pretty"}, features = {
    "src/test/resources/features/
},
    glue = "com.test.stepdefs")
public class RunCukesTest {

  private static AppiumDriverLocalService service;
  public static File file;

  @BeforeClass
  public static void startAppium() throws IOException {

    System.out.println("YOUR OS NAME : " + osName);

    String nodePath = null;
    String appiumPath = null;

    ServerArgument argument;

    if (osName.contains("mac")) {
//            mac paths
      nodePath = "/usr/local/bin/node";
      appiumPath = "/usr/local/lib/node_modules/appium/build/lib/main.js";

      service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
                                                          .usingDriverExecutable(new File(nodePath))
                                                          .usingPort(4723)
                                                          .withArgument(GeneralServerFlag.LOG_LEVEL,
                                                                        "error")                                                         
                                                          .withAppiumJS(new File(appiumPath)));
    } else if (osName.contains("windows")) {

      service = AppiumDriverLocalService.buildDefaultService();

    } else if (osName.contains("linux")) {
//    linuxs path
      nodePath = System.getenv("PRODUCTION") + "/.linuxbrew/bin/node";
      appiumPath =
          System.getenv("PRODUCTION") + "/.linuxbrew/lib/node_modules/appium/build/lib/main.js";
      service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
                                                          .usingDriverExecutable(new File(nodePath))
                                                          .usingPort(4723)
                                                          .withAppiumJS(new File(appiumPath)));
    }

    service.addOutPutStream(stream);
    service.start();
  }

  @AfterClass
  public static void stopAppium() {
    service.stop();
  }

還有我的一個例子

@Configuration
public class AppUtils {
    @Value("${explicit.wait}")
    public int explicitWaitTime;
    @Value("${implicit.wait}")
    public int implicitWaitTime;
    @Value("${default.wait}")
    public int defaultWaitTime;
    public String applicationName;
    public DesiredCapabilities capabilities;
    @Value("${appium.server.port}")
    private String appiumPort;
    @Value("${automation.instrumentation}")
    private String instrumentation;
    @Value("${browser.name}")
    private String browserName;
    @Value("${platform.name}")
    private String platformName;
    @Value("${device.name}")
    private String deviceName;
    @Value("${platform.version}")
    private String platformVersion;
    @Value("${new.command.timeout}")
    private String newCommandTimeout;
    @Value("${app.package}")
    private String appPackage;
    @Value("${device.ready.timeout}")
    private String deviceReadyTimeout;
    private URL serverUrl;
    private AppiumDriver<? extends MobileElement> driver;

    @Bean(destroyMethod = "quit")
    @Scope("cucumber-glue")
    public AndroidDriver getDriver() throws MalformedURLException {
        capabilities = new DesiredCapabilities();
        capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, platformVersion);
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, platformName);
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
        capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, instrumentation);
        capabilities.setCapability("appPackage", "com.android.chrome"); //To be moved to properties
        capabilities.setCapability("appActivity", "com.google.android.apps.chrome.Main"); //To be moved to properties
        serverUrl = new URL("http://localhost:" + appiumPort + "/wd/hub");
//        LoggingPreferences logPrefs = new LoggingPreferences();
//        logPrefs.addPreferences()
//        capabilities.setCapability(CapabilityType.LOGGING_PREFS, logs);
        driver = new AndroidDriver(serverUrl, capabilities);

        driver.manage().timeouts().implicitlyWait(implicitWaitTime, TimeUnit.SECONDS);
        //driver.setLogLevel(Level.OFF);
        return (AndroidDriver) driver;
    }
}

找不到與此相關的任何文檔,希望對您有所幫助。

您應該啟動另一個監聽不同端口的appium服務器實例,然后使用此新服務器端口功能啟動測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM