public class DriverManager {

    public static ThreadLocal<AppiumDriver> driver = new ThreadLocal<>();

    public static AppiumDriver getDriver() {
        return driver.get();
    }

    public static void setWebDriver(AppiumDriver driver_) {
        driver.set(driver_);
    }
}


 public AppiumDriver<MobileElement> driver;


    public AppiumDriver<MobileElement> getDriver() {
        driver = AppiumDriverManager.getDriver();
        return driver;
    }

    @Test
    @Author(name = "AnsonLiao")
    @RetryCount(maxRetryCount = 2) public void testMethodHomePage3()
        throws InterruptedException, IOException {

        System.out.println(
            "ThreadName: " + Thread.currentThread().getName() + Thread.currentThread()
                .getStackTrace()[1].getClassName());
        getDriver().findElement(By.id("com.android2.calculator3:id/cling_dismiss")).click();
        new ScreenShotManager().captureScreenShot("LoginPage--1");
        getDriver().findElement(By.id("com.android2.calculator3:id/digit4")).click();
        getDriver().findElement(By.id("com.android2.calculator3:id/minus")).click();
        getDriver().findElement(By.id("com.android2.calculator3:id/digit9")).click();
        new ScreenShotManager().captureScreenShot("LoginPage");
        getDriver().findElement(By.id("com.android2.calculator3:id/equal")).click();
    }

在 github 上看到一个 appium 的测试框架,有个地方不太明白,每次对元素操作都要去获取一个 driver,最后获取的不是同一个 driver 吧?


↙↙↙阅读原文可查看相关链接,并与作者交流