自动化测试selenium环境搭建

Chrome 浏览器 + IDEA

1:查看Chrome浏览器版本:

2:下载驱动:Chrome 驱动
我的 Chrome 版本是 121(大版本)

找到对应的下载,Windows 的就下载 win32 那个。

没有自己版本的

点击 Stable 进去,找到对应版本,复制链接即可下载。

3:添加到 java 环境中来:

4:新建一个项目,在 pom.xml 添加依赖:

java 复制代码
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
    </dependencies>

代码复制进去,可能会报红,需要点击右边加载,等待下载刷新后就不会报红了。

5:编写测试代码:

java 复制代码
package org.example;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class Main {
    public static void main(String[] args) {
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver = new ChromeDriver(options);
        webDriver.get("https://www.baidu.com");
    }
}

运行结果如下:

相关推荐
小陈的进阶之路7 小时前
Selenium 滑动 vs Appium 滑动
python·selenium·测试工具·appium
程序员小远11 小时前
软件测试用例总结
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
爱丽_15 小时前
软件测试基础分类与核心概念整理
功能测试·测试工具·测试用例
测试人社区—835217 小时前
‌TCP/IP协议栈参数调优验证:软件测试从业者指南
网络·人工智能·网络协议·tcp/ip·测试工具·语音识别·压力测试
趙卋傑17 小时前
测试开发场景下常见的 MCP 服务
开发语言·python·测试工具·ai编程
oi..18 小时前
CSRF安全攻防:Referer 校验与 Token 防护详解
前端·网络·笔记·测试工具·安全·网络安全·csrf
HoneyMoose1 天前
Postman 测试 API 如何上传文件
测试工具·postman
Tangcan-1 天前
博客系统测试报告
功能测试·测试工具·postman
dexie_tech1 天前
不惧高频挑战,电流传感器带宽升级
功能测试·科技·物联网·测试工具·能源