自动化测试

自动化测试

1、quit() 和 close()的区别

1、quit() 是关闭整个浏览器;而close() 是关闭当前的页面;

2、quit() 操作会清空缓存;close() 不会清空缓存;

2、窗口切换

java 复制代码
 private static void test07() throws InterruptedException {
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver = new ChromeDriver(options);
        webDriver.get("https://www.baidu.com/");
        webDriver.findElement(By.cssSelector("#s-top-left > a:nth-child(1)")).click();//新闻超链接
        //跳转到新页面了
        sleep(3000);

        // 需要先获取所有页面的句柄  否则没找到元素  是因为 默认是在get 打开的页面找元素
        //getWindowHandles()获取所有窗口的句柄      getWindowHandle() 获取get打开的页面的句柄
        Set<String> handles = webDriver.getWindowHandles();
        String targetHandle = "";
        for (String handle : handles) {
            targetHandle = handle;
        }
        webDriver.switchTo().window(targetHandle);
        sleep(3000);
        webDriver.findElement(By.cssSelector("#ww")).sendKeys("你好");
        webDriver.findElement(By.cssSelector("#s_btn_wr")).click();
    }

3、截图操作

添加依赖:

java 复制代码
<dependency>
	    <groupId>commons-io</groupId>
	    <artifactId>commons-io</artifactId>
	    <version>2.11.0</version>
</dependency>
java 复制代码
 private static void test08() throws InterruptedException, IOException {
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver = new ChromeDriver(options);
        webDriver.get("https://www.baidu.com/");
        webDriver.findElement(By.cssSelector("#kw")).sendKeys("测试");
        webDriver.findElement(By.cssSelector("#su")).click();
        sleep(3000);
        File file = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(file,new File("F:/1111.png"));

    }
相关推荐
狂师11 小时前
爆火!新一代e2e AI测试框架,单日狂揽1500 star
前端·人工智能·测试
冬奇Lab1 天前
LLM 驱动的自动化测试系列(10):自愈定位——当启发式打分撞上语义理解的天花板
人工智能·测试
狂师1 天前
2026年APP自动化测试工具大全,12款主流工具一次看懂
前端·开源·测试
冬奇Lab2 天前
LLM 驱动的自动化测试系列(09):移动端自动化(五)——当通用 Agent 框架下沉到测试场景
人工智能·agent·测试
andyweike2 天前
iOS App 测试
ios·测试·ad hoc·分发
匠测AI说2 天前
AI for Testing 提效实战·执行自动化(一):别让AI凭空写脚本,让它在你的框架里写,产出才能直接合入
人工智能·测试
Zelman2 天前
测试层级与测试类型
后端·面试·测试
Ikalus19882 天前
预注册的答案表把正控判成「通过」,盲测判成「不通过」——而两个都不对
测试
小元同学2 天前
一个大三测试实习生的自白:实习重不重要?我在往测开的路上找到了答案
测试
冬奇Lab3 天前
LLM 驱动的自动化测试系列(08):移动端自动化(四)——AppAgent:解析树与视觉特征的结合
人工智能·测试