【问题标题】:Android Appium - Implicit Wait on AndroidDriver Appium Doesn't WorkAndroid Appium - AndroidDriver Appium 的隐式等待不起作用
【发布时间】:2019-04-14 21:34:18
【问题描述】:

我对 Appium 中的 AndroidDriver 有一些问题, 目前我正在使用此代码等待几次以提供我的应用程序登录/注册过程。

BasePage 类:

protected AndroidDriver driver;
public BasePage(AndroidDriver driver) {
    this.driver = driver;
}
public void waitFor(int second)  {
    driver.manage().timeouts().implicitlyWait(second, TimeUnit.SECONDS);
}

并在这个类上实现:

public class RegistrationPage extends base.BasePage {
    public RegistrationPage(AndroidDriver driver) {
    super(driver);
}

public RegistrationPage alreadyExistRegistration()  {
    waitForVisibilityOf(button_login);
    swipeAndroid(1000, 1000, 100, 1000);
    waitFor(1);
    swipeAndroid(1000, 1000, 100, 1000);
    waitFor(1);
    swipeAndroid(1000, 1000, 100, 1000);
    waitFor(1);
    driver.findElement(button_register).click();
    driver.findElement(input_dob).click();
    driver.findElement(ok).click();
    driver.findElement(phone_no).sendKeys("888888888");
    driver.findElement(setup_pin).sendKeys("1111");
    driver.findElement(confirm_pin).sendKeys("1111");
    tapAndroid(840,1832);
    driver.findElement(check_term).click();
    driver.findElement(btn_next).click();
    waitFor(10);
    Assert.assertTrue(driver.findElement(message).getText().equalsIgnoreCase("Your Number is Already Registered"));

我已将参数编辑到 50 秒,但在 Junit 测试中没有等待。在使用 AndroidDriver 之前,我使用的是 WebDriver,它运行良好,但我需要 Android 驱动程序来执行 TouchAction。 所以我的测试用例总是失败,因为当断言运行时它会立即找到元素,而它还不可用。

【问题讨论】:

  • 我也有同样的问题。目前我正在使用 ExplicitWaitThread.sleep() 方法。
  • 是的,现在我正在使用 java 它自己的 Thread.sleep()。将尝试 ExplicitWait,我希望这也有效。

标签: appium appium-android


【解决方案1】:

我认为您对隐式等待的概念有误。我们不需要每次都设置它。我们需要在驱动程序初始化时设置一次,最长超时时间为 60 秒,它会在找到它时等待元素。

除此之外,您还可以使用超时值大于 1 分钟的显式等待,例如,

WebDriverWait wait = new WebDriverWait (driver, 120);

并使用它的方法,

wait.until (ExpectedConditions.visibilityOfElementLocated (By.id ("your ID")));

完成此操作后,您无需在代码中的任何位置调用 waitFor 方法。

这对我来说很好,我从不使用Thread.sleep()?。

【讨论】:

  • 实际上我已经创建了这个函数:protected void waitForVisibilityOf(By locator) { WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); } 并像这样调用实现:waitForVisibilityOf(button_login); 但这不起作用。我想是因为我使用的是 Android 驱动程序,之前使用的是 Web 驱动程序,它可以工作。
猜你喜欢
  • 2020-01-20
  • 2015-07-18
  • 2014-10-23
  • 2018-09-07
  • 2016-01-01
  • 2016-02-22
  • 1970-01-01
  • 2017-07-17
  • 2014-07-10
相关资源
最近更新 更多