一.前沿
目前公司需要做自动化测试,减少测试人员的压力
二.需求
使用Selenium写一个测试脚本
三.使用工具
1.java 1.8开发
2. Selenium
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0</version>
</dependency>
3.Webdriver 根据谷歌浏览器版本下载(在设置关于Chrome里面) 下载地址
使用Selenium 需要 Webdriver 及 谷歌浏览器
4.搭建一个Spring boot 工程 具体百度
四.开发代码
1.首先使用基础代码
public class SeleniumDemo {
//访问地址
private static final String url = "http://localhost/system/dict";
public static void main(String[] args) throws InterruptedException {
//设置驱动,后面的路径自己要选择正确,也可以放在本地 chromedriver上边已提供下载方式
System.setProperty("webdriver.chrome.driver", "D:\\WORK\\selenium\\chromedriver.exe");
//创建浏览器参数
ChromeOptions options = new ChromeOptions();
//使用远程连接方式
options.setExperimentalOption("debuggerAddress", "127.0.0.1:9222");
//加载驱动
WebDriver driver = new ChromeDriver(options);
//打开页面
driver.get(url);
}
}