自动化测试

自动化测试

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"));

    }
相关推荐
爱尔兰极光14 分钟前
软件测试--接口测试
接口测试·测试
Apifox21 小时前
Apifox + AI:接口自动化测试的智能化实践
前端·后端·测试
狗哥哥2 天前
AI 驱动前端自动化测试:一套能落地、能协作、能持续的工程化方案
前端·测试
charlie1145141914 天前
编写INI Parser 测试完整指南 - 从零开始
开发语言·c++·笔记·学习·算法·单元测试·测试
王喵喵喵6 天前
每天一个安卓测试开发小知识之 (七)---常用的adb 命令第五期
测试
Apifox9 天前
如何在 Apifox 中借助 AI 设计一份规范的接口文档?
前端·后端·测试
H_unique11 天前
自动化常见函数
自动化·测试
morn_venus13 天前
自动化测试之自定义UI探测器
测试
爱尔兰极光15 天前
软件测试--BUG篇
bug·压力测试·测试
国家不保护废物16 天前
Vitest 学习与实践总结:在 React + TypeScript 项目中快速上手单元测试
单元测试·测试