查看edge版本:

​image​

下载edge驱动:

Microsoft Edge WebDriver |Microsoft Edge 开发人员

​image​

在官网下载依赖包:

Downloads | Selenium

​image​

​image​

安装edge扩展:

​image

​image​​

解压下载到的jar到一个文件夹,添加jar包:

​image​

写一个自动化测试类:

import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;

import java.io.IOException;

/**
 * @author Ayano
 * @version 1.0
 * @description:
 * @date 2024/4/22 14:41
 */
// 自动化测试类
public class AutoTest  {
    public void Test() throws InterruptedException, IOException {
        // Edge驱动
        EdgeOptions edgeOptions = new EdgeOptions();
        // 允许所有请求(允许浏览器通过远程服务器访问不同源的网页,即跨域访问)
        edgeOptions.addArguments("--remote-allow-origins=*");
        EdgeDriver edgeDriver = new EdgeDriver(edgeOptions);
        // 启动需要打开的网页
        edgeDriver.get("https://www.baidu.com");
        // 退出
        edgeDriver.quit();
    }
}

写一个启动类:

import java.io.IOException;

// 启动类
public class RunAutoTest {
    public static void main(String[] args) throws InterruptedException, IOException {
        AutoTest autoTest = new AutoTest();
        autoTest.Test();
    }
}

配置java启动:

​image​

​image​

运行项目:

​image​

​image会弹出一个edge打开百度的窗口,随后一闪而过,为测试成功。

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐