自动化测试

自动化测试

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

    }
相关推荐
qq_白羊座1 天前
测试资产复用维护方法
测试·测试资产
HuskyYellow3 天前
第 1 篇:没有专职测试的小团队,为什么需要 ai-phone?
人工智能·开源·测试
康谋自动驾驶3 天前
智驾仿真测试团队必看:ADAS HiL测试引入3DGS的ROI测算与结论!
自动驾驶·测试·3dgs·hil测试·场景生成·智驾仿真
wangruofeng4 天前
Playwright 深度调研:为什么它成了浏览器自动化的新底座
前端·测试
祁白_5 天前
[HCTF 2018]WarmUp1
安全·渗透·测试·ctf·writeup
祁白_6 天前
无字母数字 Webshell 绕过
笔记·web安全·测试·ctf
AdCj36 天前
放弃第三方框架,用系统自带工具玩转 Shell 测试
shell·测试
技术落地手记8 天前
把AI塞进测试环节,我踩出了一条能用的路
人工智能·测试
大飞记Python8 天前
从“驱动地狱”到一行代码:WebDriverManager使用手记(附模板)
python·测试
甜甜圈圈子9 天前
JMeter开启TLSv1.3进行性能测试
测试