核心代码
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("测试不通过");
}
}
}
本文介绍了如何在自动化测试中使用Selenium进行网页登录功能的实现。首先,在POM.XML文件中引入Selenium的依赖库,版本为3.141.59。接着,创建了测试用例包testcases,并在其中编写LoginCase类,实现了线性的登录功能代码。代码中包含了打开浏览器、定位元素、输入用户名和密码、点击登录按钮以及使用WebDriverWait进行页面等待和测试结果判断。这是一个基础的自动化测试用例示例。
1406

被折叠的 条评论
为什么被折叠?



