核心代码
3.1POM.XML导入依赖
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
3.2新建包结构:testcases包,用来保存测试用例
新建一个LoginCase类,先线性代码实现单个登录功能
public class LoginTest {
public static void main(String[] args) {
WebDriverUtils.openBrower("chrome");
WebDriver d = WebDriverUtils.driver;
d.get("登录测试地址url");
d.findElement(By.name("phone")).sendKeys("有效用户名");
d.findElement(By.name("password")).sendKeys("有效密码");
d.findElement(By.xpath("//button[text()='登录']")).click();
//显示等待应用
WebDriverWait w = new WebDriverWait(d, 5);
try {
w.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//button[text()='退出']")));
System.out.println("测试通过");
} catch (Exception e) {
System.out.println("测试不通过");
}
}
}