自动化测试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");
    }
}

运行结果如下:

相关推荐
程序员三藏12 小时前
Postman持久化保存/设置断言详解
自动化测试·软件测试·python·测试工具·职场和发展·接口测试·postman
测试199814 小时前
如何写出一个完整的测试用例?
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·接口测试
我的xiaodoujiao1 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 22--数据驱动--参数化处理 Json 文件
python·学习·测试工具·pytest
安冬的码畜日常1 天前
【JUnit实战3_23】 第十四章:JUnit 5 扩展模型(Extension API)实战(上)
测试工具·junit·单元测试·jdbc·h2·extension模型·junit5扩展
景彡先生1 天前
Python Selenium详解:从入门到实战,Web自动化的“瑞士军刀”
前端·python·selenium
安冬的码畜日常1 天前
【JUnit实战3_22】 第十三章:用 JUnit 5 做持续集成(下):Jenkins + JUnit 5 + Git 持续集成本地实战演练完整复盘
git·测试工具·ci/cd·jenkins·集成测试·持续集成·junit5
天才测试猿1 天前
Jmeter基础知识详解
自动化测试·软件测试·测试工具·jmeter·测试用例·接口测试·性能测试
程序员三藏1 天前
软件测试之环境搭建及测试流程
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
xiecoding.cn2 天前
Selenium IDE下载和安装教程(附安装包)
selenium·测试工具·selenium安装·selenium ide·selenium ide下载·selenium下载
.又是新的一天.2 天前
04-Fiddler详解+抓包定位问题
前端·测试工具·fiddler