自动化测试

自动化测试

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

    }
相关推荐
光殿1 天前
性能测试
测试
JenniferSmiling3 天前
Midscene初体验
测试
烧冻鸡翅QAQ4 天前
测试中的Bug
bug·测试
草莓熊Lotso5 天前
《从 0 建立测试开发认知:先搞懂 “是什么”,再学 “怎么做”》
经验分享·笔记·其他·测试
cat_with_cat6 天前
测试:BUG篇
bug·测试
佚明zj6 天前
渗透测试(Penetration Testing)入门指南
测试
Apifox7 天前
如何让 Apifox 发布的在线文档具备更好的调试体验?
前端·后端·测试
康谋自动驾驶8 天前
告别数月等待:数字孪生场景生成从此进入“日级”时代
汽车·测试·数字孪生·仿真·建模·3dgs
漫谈测试8 天前
秒杀系统数据分层校验
测试
虫无涯10 天前
【分享】AgileTC测试用例管理平台使用分享
测试