简体   繁体   English

Appium 的隐式等待不起作用

[英]Appium's implicitlyWait does not work

I am using Appium to automate an iOS app but met a problem, is there anyone meet the same problem before?我正在使用 Appium 来自动化一个 iOS 应用程序,但遇到了一个问题,有没有人遇到过同样的问题?

Appium's implicitlyWait API seems to not work. Appium 的implicitlyWait等待 API 似乎不起作用。 I am using Java and JUnit to run the test, here is the line of code:我正在使用 Java 和 JUnit 来运行测试,这是代码行:

driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);

I have checked the debug info in the appium console, it looks correctly:我已经检查了 appium 控制台中的调试信息,它看起来是正确的:

info: [debug] Set iOS implicit wait to 50000ms信息:[debug] 将 iOS 隐式等待设置为 50000 毫秒

My Environment:我的环境:

Latest Appium 1.2.1, Java client library 1.6.1, Selenium Java language binding 2.42.2 and sample app 'UICatalog'provided by Sauce Lab.最新的 Appium 1.2.1、Java 客户端库 1.6.1、Selenium Java 语言绑定 2.42.2 和 Sauce Lab 提供的示例应用程序“UICatalog”。

Thanks in advance for the reply.预先感谢您的回复。

The code you have posted manages the timeout to wait for a maximum of 50 seconds.您发布的代码管理超时以等待最多 50 秒。 It doesn't make the driver wait 50 seconds.它不会让驱动程序等待 50 秒。 You can use the wait like:您可以像这样使用等待:

 driver.wait(); //this will wait a max of 50 seconds cuz you said so

If you ask me the proper way you would want to use waiting on Webdriver is:如果您问我希望使用等待 Webdriver 的正确方法是:

WebDriverWait wait;
wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.elementToBeClickable(By.id("blabla"));

The code above checks if blabla is clickable until that condition is proved or 60 seconds(stated above) passes the driver waits.上面的代码检查 blabla 是否可点击,直到证明该条件或 60 秒(如上所述)通过驱动程序等待。

In Appium it is possible to set implicit way in this way:在 Appium 中,可以通过这种方式设置隐式方式:

Java code:爪哇代码:

AppiumFieldDecorator decorator = new AppiumFieldDecorator(driver);
decorator.resetImplicitlyWaitTimeOut(50, TimeUnit.SECONDS);
PageFactory.initElements(decorator, this /* refers to current page object class*/);

Such timeout will work for the whole time.这种超时将一直有效。

It is not possible (at least I don't know) to change it.改变它是不可能的(至少我不知道)。

As when web drivers are used you can do this with:与使用网络驱动程序时一样,您可以通过以下方式执行此操作:

driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
// some actions for which you don't want to wait implicitly
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);

Try this:试试这个:

public static void WaitForElementPresent1(String locator, int timeout)
{
    WebDriverWait wait = new WebDriverWait(driver, timeout);
    try{   
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator)));
    } catch (Exception e){
        e.printStackTrace();
    }
 }

If you are using PageFactory model, you can specify the implicit wait with initElements() method as given below -如果您使用的是 PageFactory 模型,则可以使用 initElements() 方法指定隐式等待,如下所示 -

PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS), this);

I have tried this with Appium 1.6 and it works fine.我已经在 Appium 1.6 上尝试过这个,它工作正常。

The new way of setting the implicit time out is using the code设置隐式超时的新方法是使用代码

AppiumFieldDecorator decorator = new AppiumFieldDecorator(mobDriver);
decorator.DEFAULT_IMPLICITLY_WAIT_TIMEOUT = longValue;
decorator.DEFAULT_TIMEUNIT = TimeUnit.TimeUnit ;

Hope this helps希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM