当前位置: 代码迷 >> CVS/SVN >> Junit+Selenium+Maven+SVN+Eclipse+AutoFrame全自动化测试实践范例(一)
  详细解决方案

Junit+Selenium+Maven+SVN+Eclipse+AutoFrame全自动化测试实践范例(一)

热度:5870   发布时间:2013-02-26 00:00:00.0
Junit+Selenium+Maven+SVN+Eclipse+AutoFrame全自动化测试实践实例(一)

相关博文:

集群式自动化测试框架(平台)设计与实现

应用于全自动化测试体系的应用实现实例(基于SVN跨平台敏捷项目)

Java和.Net版通用工具类实现--生成自定义Web Html/Excel测试用例和测试报告

(一)期望效果

 

开发会将用于测试的源代码版本转存于SVN的一个路径下。

无人值守自动实施工作:每天固定几个时间段检查一次是否有新的需要测试的版本。

如果有: 【则下载源代码到各个Windows和Linux编译环境平台进行编译,编译成功后部署到相应的Windows和Linux测试服务器,然后启动自动化测试脚本或程序,测试完成后发送Summary邮件和测试报告网址。】

如果没有或者过程中有错:【中止测试,发送Summary邮件和错误日志。】

即,中控服务器自动定时任务:检查版本-->多平台多服务器同时编译-->多服务器同时部署-->调用启动测试-->测试结束展现测试结果(如自动发送邮件网页等)

手动工作:本地编写自动化测试代码+维护一套自动控制脚本-->接收邮件、检查测试结果

总之,自动化中控服务器平台执行控制脚本逻辑、调度操控各个可连接服务器有序工作(横向纵向可继续延伸至其他中控集群),本地工作机可一键生成同步资源到中控服务器(基于IP),一键增删查中控服务器定时任务列表(相对路径,控制脚本调度)。

 

(二)Junit+Selenium+Maven+SVN+Eclipse测试环境构建

1.DownloadMaven 

http://maven.apache.org/download 

apache-maven-3.0.4-bin.tar.gz

http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-3.0.4-bin.tar.gz 

2.InstallMaven

(1) Unzip apache-maven-3.0.4-bin.tar.gz to C:\CI 

(2) My Computer --> Property --> EnvironmentVariant--> System Variant-->

Add-->name: M2_HOMEvalue: C:\CI\apache-maven-3.0.4-->OK-->

choosePath-->edit-->add the last: ;%M2_HOME%\bin-->OK-->OK-->OK 

(3) cmd--> mvn -v

Apache Maven 3.0.4 (r1232337; 2012-01-1716:44:56+0800)

Maven home: C:\CI\apache-maven-3.0.4\bin\..

Java version: 1.6.0_31, vendor: SunMicrosystems Inc.

Java home: C:\ProgramFiles\Java\jdk1.6.0_31\jre

Default locale: zh_CN, platform encoding:GBK

OS name: "windows 7", version:"6.1", arch: "x86", family: "windows" 

3.Use Maven in Eclipse

(1) cmd-->mvn help:system (This willdownload many files to .m2 folder) 

(2) copy M3_HOME\conf\settings.xml to .m2/settings.xml 

(3) Start Eclipse-->Help-->Install NewSoftware...-->Add...-->

Name: m2e

Location: http://download.eclipse.org/technology/m2e/releases

-->OK-->Choose m2e- Maven Integration for Eclipse--->Next-->Next-->I accept the terms ofthe license agreement-->Finish-->Restart Now 

(4) Start Eclipse-->Help-->Install NewSoftware...-->Add...-->

Name: subclipse

Location: http://subclipse.tigris.org/update_1.8.x

-->ChooseSubclipse,SVNKit all-->Next-->Next-->I accept the terms of the licenseagreement-->Finish-->OK-->Restart Now 

(5) StartEclipse-->File-->New-->Other...-->Maven-->Maven Project-->Ifyou see Maven Project ,it is said that Maven is installed perfectly. 

(6) Use Maven outside of Eclipse,Windows --> Preferences--> Maven-->Installations--> Add...--> Next--> C:\CI\apache-maven-3.0.4-->OK-->OK

4. First Maven Project : hello-world-m2e (EclipseIDE)(Create a new Maven project)

(1) Start Eclipse-->File-->Other...-->Maven-->MavenProject-->Cancel Use default Workspace location-->Location:...\workspace\hello-world-m2e-->Next-->Next-->

org.apache.maven.archetypes: maven-archetype-quickstart-->

Next-->

Group Id:com.juvenxu.mvnbook

Artifact Id:hello-world-m2e

Version: 0.0.1-SNAPSHOT

Package:com.juvenxu.helloworldm2e

 

-->Finish-->

(2) Run maven(mvn clean install)-->point pom.xml-->Run As-->Maven install-->

 

(3) We want to run mvn clean test -->point pom.xml-->Run As-->Run Configurations-->MavenBuild-->New-->

Name: hello-world-m2e

Base directory:${workspace_loc:/hello-world-m2e}

Goals: clean test

-->JRE-->InstalledJREs...-->Add...-->StandardVM-->Next-->Directory...-->C:\ProgramFiles\Java\jdk1.6.0_31-->Finish-->

choose jdk1.6.0_31-->ok-->AlternateJRE: jdk1.6.0_31-->Apply-->Run

 

(4) Add executablejar--> Edit pom.xml ,add-->

<build>   <plugins>     <plugin>       <groupId>org.apache.maven.plugins</groupId>       <artifactId>maven-shade-plugin</artifactId>       <version>1.5</version>       <executions>         <execution>           <phase>package</phase>           <goals>              <goal>shade</goal>           </goals>           <configuration>              <transformers>                <transformerimplementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">                 <mainClass>com.juvenxu.helloworldm2e.App</mainClass>                </transformer>              </transformers>           </configuration>         </execution>       </executions>     </plugin>   </plugins></build>

 

(5) We want to run mvn clean test -->point pom.xml-->Run As-->Maven build...-->Goals: cleaninstall-->Apply-->Run-->

 

(6) cmd ---> cd /d  (To hello-world-m2e folder ) --> 

java -jartarget\hello-world-m2e-0.0.1-SNAPSHOT.jar

Hello World!

 

5. Import Selenium and full 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/xsd/maven-4.0.0.xsd">	<modelVersion>4.0.0</modelVersion>	<groupId>com.nhn.platform.qa.cwmtest</groupId>	<artifactId>CwmAutoTest</artifactId>	<version>1.0</version>	<dependencies>		<dependency>			<groupId>org.seleniumhq.selenium</groupId>			<artifactId>selenium-java</artifactId>			<version>2.28.0</version>		</dependency>		<dependency>			<groupId>junit</groupId>			<artifactId>junit</artifactId>			<version>4.11</version>			<!--<scope>test</scope> -->		</dependency>		<dependency>			<groupId>com.opera</groupId>			<artifactId>operadriver</artifactId>		</dependency>	</dependencies>	<dependencyManagement>		<dependencies>			<dependency>				<groupId>com.opera</groupId>				<artifactId>operadriver</artifactId>				<version>0.16</version>				<exclusions>					<exclusion>						<groupId>org.seleniumhq.selenium</groupId>						<artifactId>selenium-remote-driver</artifactId>					</exclusion>				</exclusions>			</dependency>		</dependencies>	</dependencyManagement>	<build>		<plugins>			<plugin>				<groupId>org.apache.maven.plugins</groupId>				<artifactId>maven-surefire-plugin</artifactId>				<version>2.5</version>				<configuration>					<includes>						<include>**/*AppTest.java</include>					</includes>					<excludes>						<exclude>**/SampleTest.java</exclude>					</excludes>				</configuration>			</plugin>			<plugin>					<groupId>org.apache.maven.plugins</groupId>					<artifactId>maven-compiler-plugin</artifactId>					<version>2.3.1</version>					<configuration>						<source>1.6</source>						<target>1.6</target>						<encoding>utf8</encoding>  					</configuration>			</plugin>		</plugins>	</build>	<reporting>		<plugins>			<!-- 配置site 的国际化,默认为en,更改为zh_CN,以及设置编码格式,默认utf-8 -->			<plugin>				<groupId>org.apache.maven.plugins</groupId>				<artifactId>maven-site-plugin</artifactId>				<version>2.0-beta-6</version>				<configuration>					<locales>zh_CN</locales>					<outputEncoding>utf-8</outputEncoding>				</configuration>			</plugin>			<!-- 			<plugin>				<groupId>org.codehaus.mojo</groupId>				<artifactId>cobertura-maven-plugin</artifactId>				<version>2.2</version>				<configuration>					<formats>						<format>html</format>						<format>xml</format>					</formats>					<instrumentation>						<excludes></excludes>					</instrumentation>				</configuration>							</plugin>			 -->			<plugin>				<groupId>org.apache.maven.plugins</groupId>				<artifactId>maven-surefire-report-plugin</artifactId>				<version>2.12.2</version>				<configuration>					<showSuccess>true</showSuccess>				</configuration>			</plugin>		</plugins>	</reporting></project>


(三)工程预览

 

 

  相关解决方案