Java & Selenium & Appium four kinds of standby mode

This blog post introduces automated testing, whether or selenium are the four ways to wait Appium, rational use of waiting for the stability of the code, testing efficiency has greatly improved

Implicit wait: is when trying to find an element of, if not immediately able to find the time to wait for a fixed length. The default setting is 0 seconds. Once the wait time provided implicit, its scope is the whole life cycle of the object instance Webdriver
display wait: wait condition is defined, only the trigger condition, before the implementation of subsequent code.
Forced to wait: Specifies the length of waiting time fixed in seconds
Fluent Wait: He is a display with a waiting, he allows us to define the polling interval, ignore any abnormality, timeout, etc.
 Second, the example code
// the Java
/ *
* @ Wait_Demo FileName:
* @author davieyang
* @Create 2018-11-29 14:10
* /
Package testscript;
Import io.appium.java_client.android.AndroidDriver;
Import org.openqa.selenium.WebDriver;
Import org.openqa.selenium. remote.DesiredCapabilities;
Import org.openqa.selenium.support.ui *;.
Import org.testng.annotations.BeforeClass;
Import org.testng.annotations.Test;
Import org.testng.annotations.AfterClass;
import org.apache.log4j.xml.DOMConfigurator;
import org.openqa.selenium.*;
import org.testng.annotations.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

@Listeners({util.TestReport.class})
public class Wait_Demo {
AndroidDriver driver;
static {
//指定log4j配置文件为log4j.xml
DOMConfigurator.configure("log4j.xml");
}
@BeforeClass
public void setUp()throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
// des.setCapability("app", "c:\\");
caps.setCapability("automationname", "Epochs ");
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "23");
caps.setCapability("udid", "WTKDU17105005171");
caps.setCapability("deviceName", "Honor");
caps.setCapability("appPackage", "com.tencent.Q108");//com.android.contacts
caps.setCapability("appActivity", "com.tencent.Q108.SplashActivity");//.activities.PeopleActivity
caps.setCapability("appWaitActivity", "com.tencent.Q108.SplashActivity");
caps.setCapability("unicodeKeyboard", "True");
caps.setCapability("resetKeyboard", "True");
caps.setCapability("newCommandTimeout", "15");
caps.setCapability("nosign", "True");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),caps);
//隐式等待
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void test_() {
     // 强制等待
     Thread.sleep(10);
// 显式等待
WebDriverWait explicitwait = new WebDriverWait(driver, 10);
explicitwait.until(ExpectedConditions.visibilityOfElementLocated(By.id("text1")));

// 流畅等待
FluentWait<WebDriver> fluentwait = new FluentWait<WebDriver>(driver)
.withTimeout(10, TimeUnit.SECONDS)
.pollingEvery(250, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class)
.ignoring(TimeoutException.class);
fluentwait.until(ExpectedConditions.visibilityOfElementLocated(By.id("text1")));

}
@AfterClass
public void tearDown() {
driver.closeApp();
}

}

Guess you like

Origin www.cnblogs.com/ali-test/p/11221594.html