import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class AgreementDepositTest {
    WebDriver driver;
    String url1;
    @BeforeTest
    public void beforeTest() {
        // 初始化 WebDriver
        // ...
        // 打开目标页面
        driver.get("目标页面URL");
        url1 = driver.getCurrentUrl();
    }
    @Test
    public void testAgreementDeposit() throws InterruptedException {
        // 点击存款协议
        WebElement element = driver.findElement(By.xpath("//div[@class='agreement']//p[contains(text(),'存款协议')]"));
        log.info('点击:存款协议');
        element.click();
        Thread.sleep(2000);
        // 点击返回
        driver.findElement(By.xpath("//span[text()='返回']")).click();
        Thread.sleep(2000);
        // 勾选同意
        log.info('勾选同意');
        driver.findElement(By.xpath("//span[@class='iconfont icon-checked']")).click();
        Thread.sleep(2000);
        // 点击确定
        log.info('点击确定');
        driver.findElement(By.xpath("//button[@class='el-button el-button--primary']")).click();
        Thread.sleep(2000);
        // 跳转页面,验证是否跳转
        String url2 = driver.getCurrentUrl();
        log.info('url2:' + url2);
        Assert.assertNotEquals(url1, url2);
    }
    @AfterTest
    public void afterTest() {
        driver.quit();
    }
}

原文地址: https://www.cveoy.top/t/topic/llVG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录