appium java动态等待_appium三种等待元素的方法

import org.openqa.selenium.NotFoundException;

import org.openqa.selenium.TimeoutException;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebDriverException;

import org.openqa.selenium.remote.RemoteWebDriver;

import org.openqa.selenium.support.ui.Clock;

import org.openqa.selenium.support.ui.FluentWait;

import org.openqa.selenium.support.ui.Sleeper;

import org.openqa.selenium.support.ui.SystemClock;

import io.appium.java_client.android.AndroidDriver;

import java.util.concurrent.TimeUnit;

/**

* A specialization of {@link FluentWait} that uses WebDriver instances.

*/

public class AndroidDriverWait extends FluentWait {

public final static long DEFAULT_SLEEP_TIMEOUT = 500;

private final WebDriver driver;

/**

* Wait will ignore instances of NotFoundException that are encountered (thrown) by default in

* the 'until' condition, and immediately propagate all others.  You can add more to the ignore

* list by calling ignoring(exceptions to add).

*

* @param driver The WebDriver instance to pass to the expected conditions

* @param timeOutInSeconds The timeout in seconds when an expectation is called

* @see AndroidDriverWait#ignoring(java.lang.Class)

*/

public AndroidDriverWait(AndroidDriver driver, long timeOutInSeconds) {

this(driver, new SystemClock(), Sleeper.SYSTEM_SLEEPER, timeOutInSeconds, DEFAULT_SLEEP_TIMEOUT);

}

/**

* Wait will ignore instances of NotFoundException that are encountered (thrown) by default in

* the 'until' condition, and immediately propagate all others.  You can add more to the ignore

* list by calling ignoring(exceptions to add).

*

* @param driver The WebDriver instance to pass to the expected conditions

* @param timeOutInSeconds The timeout in seconds when an expectation is called

* @param sleepInMillis The duration in milliseconds to sleep between polls.

* @see AndroidDriverWait#ignoring(java.lang.Class)

*/

public AndroidDriverWait(AndroidDriver driver, long timeOutInSeconds, long sleepInMillis) {

this(driver, new SystemClock(), Sleeper.SYSTEM_SLEEPER, timeOutInSeconds, sleepInMillis);

}

/**

* @param driver The WebDriver instance to pass to the expected conditions

* @param clock The clock to use when measuring the timeout

* @param sleeper Object used to make the current thread go to sleep.

* @param timeOutInSeconds The timeout in seconds when an expectation is

* @param sleepTimeOut The timeout used whilst sleeping. Defaults to 500ms called.

*/

public AndroidDriverWait(AndroidDriver driver, Clock clock, Sleeper sleeper, long timeOutInSeconds,

long sleepTimeOut) {

super(driver, clock, sleeper);

withTimeout(timeOutInSeconds, TimeUnit.SECONDS);

pollingEvery(sleepTimeOut, TimeUnit.MILLISECONDS);

ignoring(NotFoundException.class);

this.driver = driver;

}

@Override

protected RuntimeException timeoutException(String message, Throwable lastException) {

TimeoutException ex = new TimeoutException(message, lastException);

ex.addInfo(WebDriverException.DRIVER_INFO, driver.getClass().getName());

if (driver instanceof RemoteWebDriver) {

RemoteWebDriver remote = (RemoteWebDriver) driver;

if (remote.getSessionId() != null) {

ex.addInfo(WebDriverException.SESSION_ID, remote.getSessionId().toString());

}

if (remote.getCapabilities() != null) {

ex.addInfo("Capabilities", remote.getCapabilities().toString());

}

}

throw ex;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值