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

运行结果如下:

相关推荐
测试界的海飞丝6 小时前
10道软件测试面试题及其答案:
服务器·测试工具·职场和发展
REDcker7 小时前
tcpdump 网络数据包分析工具完整教程
网络·测试工具·tcpdump
程序员念姐18 小时前
软件测试系统流程和常见面试题
测试工具·面试
Hacker_Oldv18 小时前
Python技能进阶:探索Selenium库,实现网页自动化测试与爬虫
自动化测试·软件测试·爬虫·python·selenium·职场和发展
西游音月20 小时前
(5)pytest+Selenium自动化测试-元素定位之XPath定位
selenium·测试工具·pytest
L.Ru21 小时前
SIP抓包工具-sngrep的使用
测试工具·信息与通信·sngrep
卓码软件测评1 天前
第三方软件测评机构:【Gatling与JMeter的架构对比:异步与非阻塞I/O模型如何实现更高并发】
测试工具·jmeter·架构·测试用例·负载均衡·压力测试
美团程序员1 天前
一篇文章教你搞定:”xx 功能如何测试?“常见面试题型!
测试工具·面试·职场和发展·测试用例
软件测试雪儿2 天前
高频Postman软件测试面试题
测试工具·lua·postman
2501_915106322 天前
iOS App 测试工具全景分析,构建从开发调试到线上监控的多阶段工具链体系
android·测试工具·ios·小程序·uni-app·iphone·webview