自动化测试

自动化测试

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

    }
相关推荐
冬奇Lab2 天前
一天一个开源项目(第224篇):ARTEMIS —— 谷歌开源的移动端 AI 自动化框架,让 AI 助手像人一样操作手机
人工智能·开源·测试
BullSmall2 天前
RAG 知识库专项测试
功能测试·大模型·测试
liulilittle3 天前
mock 规范总纲
ai·自动化·llm·mock·测试·tools
liulilittle3 天前
麻将结算全链路语义(SETTLE_SEMANTICS)
ai·自动化·llm·mock·lua·测试
liulilittle3 天前
麻将服务器崩溃补偿与异常处理语义(CRASH_SEMANTICS)
ai·自动化·llm·mock·lua·测试·tools
liulilittle3 天前
麻将 UI 层可观察行为(UI_BEHAVIOR)
ai·自动化·llm·mock·lua·测试·tools
liulilittle3 天前
麻将节点间路由转发链:失败回退与错误传播语义(ROUTE_SEMANTICS)
ai·自动化·llm·mock·测试·script·tools
liulilittle3 天前
mock 框架架构
ai·架构·自动化·llm·mock·测试·tools
liulilittle3 天前
C++ 引擎接口到 mock 的映射(INTERFACE_MAP)
ai·自动化·llm·mock·lua·测试·tools
我要学脑机4 天前
软件测试体系笔记:从模型到落地
测试