自动化测试

自动化测试

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

    }
相关推荐
不能只会打代码15 小时前
Day 002 — Python 工程化 & FastAPI & 数据库速通
数据库·redis·python·docker·fastapi·测试
狂师19 小时前
还在手写测试报告?推荐一款 AI 测试Skill:只需一句指令,自动生成专业定制化测试报告!
人工智能·测试·全栈
xixingzhe21 天前
软件开发测试分层与CI/CD、沙箱使用完整指南
ci/cd·测试
ClouGence2 天前
8 款好用的 Web 自动化测试工具大盘点:怎么选、适合谁?
selenium·测试
狂师2 天前
测试人员必备:推荐一款智能测试数据清理AI Skill,支持db、redis、mq等
数据库·aigc·测试
ckjoker3 天前
让AI给AI当法官:手敲LLM-as-a-Judge评估系统,25次调用跑出最弱维度
llm·agent·测试
程序员天天困4 天前
JaCoCo 代码覆盖率:Spring Boot 集成与报告解读
单元测试·测试
一孤程5 天前
Airtest自动化测试第五篇:小程序与Web测试——跨平台自动化全覆盖
前端·自动化测试·小程序·自动化·测试·airtest
一孤程6 天前
PerfDog性能测试实战——从入门到性能优化全覆盖
性能优化·性能测试·测试·perfdog