java+maven+selenium+testng+reportng项目环境搭建

整合网络资源,加上自己的实际操作,记录一下java+maven+selenium+testng+reportng项目环境搭建的步骤:

1.创建maven项目

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的版本映射表(转自: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依赖.不添加此依赖包,运行时会报错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.编写测试类

9.通过xml方式运行测试类

<?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.运行完成后,可在target下打开index.html查看报告

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容