整合網(wǎng)絡(luò)資源,加上自己的實(shí)際操作,記錄一下java+maven+selenium+testng+reportng項(xiàng)目環(huán)境搭建的步驟:
1.創(chuàng)建maven項(xiàng)目
2.在maven的配置文件pom.xml中,添加testng依賴
<dependency>
? ? <groupId>org.testng</groupId>
? ? <artifactId>testng</artifactId>
? ? <version>6.14.3</version>
</dependency>
3.在maven的配置文件pom.xml中,添加selenium依賴
<dependency>
? ? <groupId>org.seleniumhq.selenium</groupId>
? ? <artifactId>selenium-java</artifactId>
? ? <version>2.44.0</version>
</dependency>
附:Chromedriver與selenium的版本映射表(轉(zhuǎn)自:https://blog.csdn.net/xc_zhou/article/details/80687819)
4.在maven的配置文件pom.xml中,添加reportng依賴
<dependency>
? ? <groupId>org.uncommons</groupId>
? ? <artifactId>reportng</artifactId>
? ? <version>1.1.4</version>
? ? <scope>test</scope>
</dependency>
5.在maven的配置文件pom.xml中,添加guice依賴.不添加此依賴包,運(yùn)行時(shí)會(huì)報(bào)錯(cuò)ClassNotFoundException
<dependency>
? ? <groupId>com.google.inject</groupId>
? ? <artifactId>guice</artifactId>
? ? <version>4.0</version>
? ? <scope>test</scope>
</dependency>
6.在maven的配置文件pom.xml中,添加maven-surefire-plugin
<build>
? ? <plugins>
? ? ? <plugin>
? ? ? ? ? ? <groupId>org.apache.maven.plugins</groupId>
? ? ? ? ? ? <artifactId>maven-surefire-plugin</artifactId>
? ? ? ? ? ? <version>2.17</version>
? ? ? ? ? ? <configuration>
? ? ? ? ? ? ? ? ? ? <suiteXmlFile>xml/testxml.xml</suiteXmlFile>
? ? ? ? ? ? </configuration>
? ? ? ? </plugin>
? ? ? ? <plugin>
? ? ? ? ? ? <groupId>org.apache.maven.plugins</groupId>
? ? ? ? ? ? <artifactId>maven-surefire-plugin</artifactId>
? ? ? ? ? ? <version>2.19.1</version>
? ? ? ? ? ? <configuration>
? ? ? ? ? ? ? ? ? ?<properties>
? ? ? ? ? ? ? ? ? ? ? <property>
? ? ? ? ? ? ? ? ? ? ? ? <name>usedefaultlisteners</name>
? ? ? ? ? ? ? ? ? ? ? ? <value>false</value>
? ? ? ? ? ? ? ? ? ? ? </property>
? ? ? ? ? ? ? ? ? ? ? <property>
? ? ? ? ? ? ? ? ? ? ? ? <name>listener</name>
? ? ? ? ? ? ? ? ? ? ? ? <value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
? ? ? ? ? ? ? ? ? ? </property>
? ? ? ? ? ? ? ? ? ? </properties>
? ? ? ? ? ? ? ? <workingDirectory>target/</workingDirectory>
</configuration>
</plugin>
</plugins>
</build>
7.更新下載依賴包
8.編寫測(cè)試類
9.通過xml方式運(yùn)行測(cè)試類
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
? <test name="Test">
? ? <classes>
? ? ? <class name="com.seleniumhq.www.TestCase2"/>
? ? </classes>
</test>
? ? <listeners>
? ? ? ? ? <listener class-name="org.uncommons.reportng.HTMLReporter"/>
? ? ? ? ? <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
? ? </listeners>
</suite>
10.運(yùn)行完成后,可在target下打開index.html查看報(bào)告