UI测试工具类初步提交演示
This commit is contained in:
@@ -24,7 +24,7 @@ public class UITestUtil {
|
||||
|
||||
try {
|
||||
// 打开目标网页的登录页面
|
||||
String url = "https://demo.halo.run/login"; // 替换为实际的登录页面 URL
|
||||
String url = "https://sso.gxnews.com.cn/"; // 替换为实际的登录页面 URL
|
||||
driver.get(url);
|
||||
|
||||
// 最大化浏览器窗口
|
||||
@@ -34,28 +34,23 @@ public class UITestUtil {
|
||||
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(60));
|
||||
|
||||
// 等待用户名输入框可见并输入用户名
|
||||
WebElement usernameInput = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username")));
|
||||
WebElement usernameInput = wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("username")));
|
||||
usernameInput.sendKeys("ldlspace"); // 替换为实际用户名
|
||||
|
||||
// 等待密码输入框可见并输入密码
|
||||
WebElement passwordInput = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("plainPassword")));
|
||||
passwordInput.sendKeys("Ldlspace@163"); // 替换为实际密码
|
||||
WebElement passwordInput = wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("password")));
|
||||
passwordInput.sendKeys("Ldl08844"); // 替换为实际密码
|
||||
|
||||
// 等待登录按钮可点击并点击
|
||||
WebElement loginButton = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(.,'登录')]")));
|
||||
WebElement loginButton = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"button\"]")));
|
||||
loginButton.click();
|
||||
Thread.sleep(3000);
|
||||
String currentUrl = driver.getCurrentUrl();
|
||||
System.out.println(currentUrl);
|
||||
String targetUrl = "https://demo.halo.run/uc/profile"; // 替换为实际的目标页面 URL
|
||||
wait.until(ExpectedConditions.urlToBe(targetUrl)); // 验证 URL 是否为目标页面
|
||||
|
||||
// 等待登录成功后的页面标题变为预期值
|
||||
wait.until(ExpectedConditions.titleContains("我的 - Halo 演示站点")); // 根据实际情况修改标题内容
|
||||
|
||||
// 验证是否登录成功
|
||||
if (driver.getTitle().contains("我的 - Halo 演示站点")) {
|
||||
System.out.println("登录成功!");
|
||||
WebElement welcome = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"list\"]/ul/li[1]")));
|
||||
String welcomeText = welcome.getText();
|
||||
if (welcomeText.equals("ldlspace,欢迎您登录")) {
|
||||
System.out.println("登录成功!");
|
||||
} else {
|
||||
System.out.println("登录失败!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user