一。安装pom依赖
1.修改setting.xml依赖为国内镜像
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<!-- junit镜像地址 -->
<mirror>
<id>junit</id>
<name>junit Address/</name>
<url>http://jcenter.bintray.com/</url>
<mirrorOf>central</mirrorOf>
</mirror>
二.修改 IDEA,mavn方式
importing
-Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true
Runner
-Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true -DarchetypeCatalog=internal
三.下载selenium依赖
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.5</version>
</dependency>
四.找到本地浏览器的webDriver,也就是启动程序,复制其路径。
五.编写测试代码。
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/Applications/Google Chrome 2.app/Contents/MacOS/Google Chrome");
WebDriver webDriver = new ChromeDriver();
webDriver.get("www.baidu.com");
}
六.成功打开浏览器。
tip:如果不能正常打开,可能由于浏览器和webdriver不匹配。可在如下网址下载相同版本的webdriver:
http://chromedriver.storage.googleapis.com/index.html
下载后,可以放在项目目录里下,直接进行调用