自动化测试:java + testng + maven + reportng + jenkins + selenium (一)_基于win环境

集成环境:jdk1.7 + tomcat1.7+ eclipse mars + maven + testng6.14.2 + selenium-java2.40.0 + reportng1.1.4 + Jenkins2.19

 1.Java集成环境:jdk1.7 + tomcat1.7+ eclipse mars + maven

  1) jdk1.7 :

    第一种方式:下载jdk安装包,安装并配置环境(下载地址:http://www.oracle.com/technetwork/java/javase/downloads/)

    第二种方式:无需安装,直接下载jre包(即:jdk安装后生成的包)并配置环境,建议将jre包放置D盘

    配置环境变量:JAVA_HOME:jdk的安装目录填入变量

           CLASSPATH:.;%JAVA_HOME%libdt.jar;%JAVA_HOME%lib ools.jar; (前面还有一个点也要复制)

              Path:Jdk的bin目录

    配置完成后测试Java环境是否配置或安装成功,cmd命令行:进入安装目录后,输入JAVAC,出现一堆信息则成功,无内部命令则失败

  2)eclipse mars.1:

    下载后双击安装就可以使用

  3)maven :

    eclipse mars.1中 : help->Install New Software   在work with中输入:http://download.eclipse.org/technology/m2e/releases/1.5/1.5.0.20140606-0033,接下来把下面的勾选好,一路点击next,安装好重启eclipse就可以了,安装好后会在Window->Preferences中有Maven选项。

    环境变量:M2_HOME:maven的安装路径(eclipse中自带的无需配置)

           Path:;%M2_HOME%in;(eclipse中自带的无需配置)

    配置maven本地仓库,我们需要打开maven的配置文件settings.xml,在文件中添加本地仓库路径。不修改则默认为C盘用户目录下的m2文件

    将settings.xml放到本地仓库.m2文件夹下

  4)tomcat1.7 :

    下载zip压缩包,解压后放置D盘

    配置环境变量:TOMCAT_HOME:tomcat的目录

           CATALINA_HOM:tomcat的目录

           Path:;%CATALINA_HOME%in;%CATALINA_HOME%lib

    在cmd命令窗口下输入startup回车,

    测试Tomcat服务器是否安装成功,在浏览器中输入http://http://localhost:8080或http://127.0.0.1:8080

    eclipse配置tomcat:Preferences->Server->Runtime Environment->add

2.testng插件安装

  第一种,离线安装:

    TestNG Eclipse插件下载地址http://testng.org/doc/download.html
    下载下来以后,放在eclipse的plugins文件夹下,然后启动eclipse,点击Help -> software update -> Installed Software, 查找到TestNG Eclipse插件,点击Install(安装),安装完成后,重启eclipse,然后去Windows -> show view -> other,java文件夹下,有TestNG,双击图标,在eclipse界面下面便会出现TestNg的窗体。


  第二种,在线安装:
    1. 选择菜单:Help->Install New Software,然后在弹出的窗口中的Work with后面的输入框中输入:http://beust.com/eclipse
    2. 然后点击Add按钮,选中TestNG后一路点击Next下去安装即可,直到Finished之后,重启Eclipse完成安装。

3.selenium+reportng+testng

  使用maven下载jar包,pom文件的依赖配置:

<dependencies>
<!-- https://mvnrepository.com/artifact/org.uncommons/reportng -->
<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>

<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.2</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.1.0</version>
<classifier>no_aop</classifier>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.40.0</version>
</dependency>

</dependencies>

4.jenkins

  用tomcat打开,将jenkins.war文件放入tomcat下的webapps目录下,启动jenkins时,会自动在webapps目录下建立jenkins目录,所以在地址栏上需要输入的地址于上一种方法有点不一样,输入:localhost:8080/jenkins
原文地址:https://www.cnblogs.com/shadow-yin/p/9559751.html