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

运行结果如下:

相关推荐
我的xiaodoujiao5 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 39--生成 Allure测试报告
python·学习·测试工具·pytest
_OP_CHEN6 小时前
【测试理论与实践】(九)Selenium 自动化测试常用函数全攻略:从元素定位到文件上传,覆盖 99% 实战场景
自动化测试·python·测试开发·selenium·测试工具·测试工程师·自动化工具
我的xiaodoujiao8 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 38--Allure 测试报告
python·学习·测试工具·pytest
废弃的小码农17 小时前
功能测试--Day02--Web项目测试
功能测试·测试工具
悟能不能悟18 小时前
怎么使用postman批量的给api做测试
测试工具·lua·postman
猿小路2 天前
抓包工具-Wireshark
网络·测试工具·wireshark
智航GIS2 天前
10.4 Selenium:Web 自动化测试框架
前端·python·selenium·测试工具
廖圣平2 天前
从零开始,福袋直播间脚本研究【三】《多进程执行selenium》
python·selenium·测试工具
合兴软件@2 天前
芯片适配快讯:合兴软件ISDT成功适配英飞凌TC3/TC4系列MCU
测试工具·车载系统·嵌入式实时数据库
Wpa.wk2 天前
性能测试-初识性能测试基础(性能测试流程,计划等)
java·运维·经验分享·测试工具·性能测试