public class AutoConfig {
public static WebDriver driver;
public AutoConfig(){
createDriver();
}
public WebDriver createDriver(){
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
//创建驱动对象,添加选项
driver = new ChromeDriver(options);
//设置隐式等待
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
return driver;
}
}
具体的思路就是,其他测试类继承这个父类,自动调用我们的的构造函数,间接调用我们的创建驱动方法;
🚀2.4设置cookie
此时我们创建另一个类,继承上述的父类后,设置我们的cookie属性;
java复制代码
@Test(priority = 2)
public void cookie() throws NoSuchMethodException, InterruptedException {
//拿到我们的cookie
String value = "17B63B2D3686F19DC921FDDEFE775505";
Cookie cookie = new Cookie.Builder("JSESSIONID",value).domain("47.97.70.52").path("/").build();
driver.get("http://47.97.70.52:8081/index.html");
driver.manage().addCookie(cookie);
driver.get("http://47.97.70.52:8081/index.html");
}