自动化测试就是将人工测试变为让代码进行测试,可提高效率。自动化分类有:单元测试、接口测试、UI自动化测试等。
selenium 是用来做 web 自动化测试框架,它支持各种浏览器(Chrome等),各种平台(Windows、Linux等),支持各种语言(Python、Java等),具有丰富的 API。
idea 编写自动化脚本代码后,通过 WebDriver 浏览器驱动,将自动化脚本中的指令转换为浏览器能够理解的操作。


查看浏览器版本,并复制版本号前三位,如我的版本号为 135

进入 chromedriver 官网

找到你对应版本号的 win 64 下载即可。



将你下载好的文件路径保存到 Path 底下。



找到你想下载的版本,并复制。
粘贴至 idea 中 pom.xml 里,刷新 maven 。
|
1 2 3 4 5 6 7 8 |
public class Test { 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"); } } |
运行代码后自动跳出百度网页则代表成功,"---remote-allow-origins=*" 为允许所有版本。

将 selenium 依赖版本改为 3.141.59 。
|
1 2 3 4 5 6 7 8 |
<dependencies> <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version> </dependency> </dependencies> |
