一、打开IDEA编辑器,点击create new project

image
二、该页面中点击maven,选择你下载的SDK目录路径,勾选maven模板,点击next

image
三、填写maven的坐标,groupId是公司域名,artifactId是项目名称,version是该项目的版本号

image
四、接下来,选择本地的maven安装地址,usersettings 选择maven安装文件中的conf里的setting路径,local repository 选择自己的本地库地址(默认在c盘,会占用c盘空间,可新建一个地址);properties 可选择最后一项,点击next

image

image
五、maven会自动下载相关文件,生成目录路径

image
六、根据需要添加相关包,在pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.2</version>
<scope>test</scope>
</dependency>
<!-- 加入reportNG依赖,代替testNG测试报告 -->
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 加入selenium做webUI测试,选用selenium2 -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<!-- 依赖GOOGLE ,Guice -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<!-- 依赖com.alibaba.fastjson,JSONObject jar包 JSON解析包 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.28</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 加入maven-surefire-plugin插件用来使用maven执行用例,其中suiteXmlFile配置的就是testNG用例执行文件的地址 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/java/myTest/mytest/testNG.xml</suiteXmlFile>
</suiteXmlFiles>
<!-- 加入编码设置,否则生成的报告会中文乱码 -->
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
<!-- 添加插件,添加ReportNg的监听器,修改最后的TestNg的报告 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter</value>
</property>
</properties>
<workingDirectory>target/</workingDirectory>
<!-- <forkMode>always</forkMode> -->
</configuration>
</plugin>
</plugins>
</build>
</project>
```
网友评论