场景:目前由于机房搬迁、平台门户测试人员严重不足。重点我们引入自动化测试,减少门户的测试时间,提高测试用例全覆盖,故引入selenium自动化测试
环境:Eclipse+WebDirver
工具:Eclipse,JDK1.6,selenium-server-standalone-2.33.0.jar,Firefox(我采用的version:14.0,最新版本使用中(如:30.0)),Maven,TestNG
详细介绍每一步操作步骤:
一、安装MAVEN
下载MAVEN2解压后:D:\Dev\tools\maven2
配置HOME变量:M2_HOME=D:\Dev\tools\maven2
二、在Eclipse下集成TestNG
在eclipse下直接下载插件或者导入eclipse下载后的插件完成TestNG。
可以参考:http://www.spasvo.com/ceshi/open/kygncsgj/Selenium/201443141155.html
三、Maven集成ReportNG,可以已报表形式查看测试用例情况
父目录pom.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.maven.jenkins</groupId>
<artifactId>jenkins_parent</artifactId>
<packaging>pom</packaging>
<version>3.0.2</version>
<name>jenkins_parent</name>
<prerequisites>
<maven>2.0.9</maven>
</prerequisites>
<build>
<plugins>
<!-- 解决JUnit compiler插件默认只支持Java1.3,需要配置插件使其支持Java5 -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<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></span>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${commons.logging.version}</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${commons.lang.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>releases</id>
<name>Internal Releases</name>
<url>${releases.url}</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Internal Snapshots</name>
<url>${snapshots.url}</url>
</snapshotRepository>
</distributionManagement>
<properties>
<commons.logging.version>1.0.4</commons.logging.version>
<log4j.version>1.2.13</log4j.version>
<commons.lang.version>2.4</commons.lang.version>
<jenkins.version>0.0.1-SNAPSHOT</jenkins.version>
</properties>
</project>
运行工程目录:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>com.maven.jenkins</groupId>
<artifactId>jenkins_parent</artifactId>
<version>3.0.2</version>
<relativePath>../jenkins_parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>SeleniumReportNG</artifactId>
<packaging>jar</packaging>
<version>${jenkins.version}</version>
<name>SeleniumReportNG</name>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.3</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server-standalone</artifactId>
<version>2.33.0</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency></span>
</dependencies>
</project>
对于ReportNG集成Maven,是查看单元测试报告的重点。
Nexus环境
下载nexus,部署到tomcat服务器上即可,比较简单,不在说明