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

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


(一)期望效果

【 用逻辑脚本和指令控制各个服务器、服务器上的程序和脚本7*24小时自动、并行、有序地工作,无人值守,本地资源代码一“丢”,报告和邮件会及时自动来找你汇报,接受检查。应用如自动化测试、自动部署维护等。】

 

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

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

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

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

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

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

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

 

(二)Junit+Selenium+Maven+SVN+Eclipse测试环境构建(此1-4步骤来自我的同事Tonny)

1.DownloadMaven 

http://maven.apache.org/download.html 

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-->

  1. <span style="font-size:14px;"><build>  
  2.   
  3.    <plugins>  
  4.   
  5.      <plugin>  
  6.   
  7.        <groupId>org.apache.maven.plugins</groupId>  
  8.   
  9.        <artifactId>maven-shade-plugin</artifactId>  
  10.   
  11.        <version>1.5</version>  
  12.   
  13.        <executions>  
  14.   
  15.          <execution>  
  16.   
  17.            <phase>package</phase>  
  18.   
  19.            <goals>  
  20.   
  21.               <goal>shade</goal>  
  22.   
  23.            </goals>  
  24.   
  25.            <configuration>  
  26.   
  27.               <transformers>  
  28.   
  29.                 <transformerimplementationtransformerimplementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">  
  30.   
  31.                  <mainClass>com.juvenxu.helloworldm2e.App</mainClass>  
  32.   
  33.                 </transformer>  
  34.   
  35.               </transformers>  
  36.   
  37.            </configuration>  
  38.   
  39.          </execution>  
  40.   
  41.        </executions>  
  42.   
  43.      </plugin>  
  44.   
  45.    </plugins>  
  46.   
  47. </build>  
  48. </span>  

 

(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

 

  1. <span style="font-size:14px;"><?xml version="1.0" encoding="UTF-8"?>  
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  4.     <modelVersion>4.0.0</modelVersion>  
  5.     <groupId>com.nhn.platform.qa.cwmtest</groupId>  
  6.     <artifactId>CwmAutoTest</artifactId>  
  7.     <version>1.0</version>  
  8.     <dependencies>  
  9.         <dependency>  
  10.             <groupId>org.seleniumhq.selenium</groupId>  
  11.             <artifactId>selenium-java</artifactId>  
  12.             <version>2.28.0</version>  
  13.         </dependency>  
  14.         <dependency>  
  15.             <groupId>junit</groupId>  
  16.             <artifactId>junit</artifactId>  
  17.             <version>4.11</version>  
  18.             <!--<scope>test</scope> -->  
  19.         </dependency>  
  20.         <dependency>  
  21.             <groupId>com.opera</groupId>  
  22.             <artifactId>operadriver</artifactId>  
  23.         </dependency>  
  24.     </dependencies>  
  25.     <dependencyManagement>  
  26.         <dependencies>  
  27.             <dependency>  
  28.                 <groupId>com.opera</groupId>  
  29.                 <artifactId>operadriver</artifactId>  
  30.                 <version>0.16</version>  
  31.                 <exclusions>  
  32.                     <exclusion>  
  33.                         <groupId>org.seleniumhq.selenium</groupId>  
  34.                         <artifactId>selenium-remote-driver</artifactId>  
  35.                     </exclusion>  
  36.                 </exclusions>  
  37.             </dependency>  
  38.         </dependencies>  
  39.     </dependencyManagement>  
  40.     <build>  
  41.         <plugins>  
  42.             <plugin>  
  43.                 <groupId>org.apache.maven.plugins</groupId>  
  44.                 <artifactId>maven-surefire-plugin</artifactId>  
  45.                 <version>2.5</version>  
  46.                 <configuration>  
  47.                     <includes>  
  48.                         <include>**/*AppTest.java</include>  
  49.                     </includes>  
  50.                     <excludes>  
  51.                         <exclude>**/SampleTest.java</exclude>  
  52.                     </excludes>  
  53.                 </configuration>  
  54.             </plugin>  
  55.             <plugin>  
  56.                     <groupId>org.apache.maven.plugins</groupId>  
  57.                     <artifactId>maven-compiler-plugin</artifactId>  
  58.                     <version>2.3.1</version>  
  59.                     <configuration>  
  60.                         <source>1.6</source>  
  61.                         <target>1.6</target>  
  62.                         <encoding>utf8</encoding>    
  63.                     </configuration>  
  64.             </plugin>  
  65.         </plugins>  
  66.     </build>  
  67.     <reporting>  
  68.         <plugins>  
  69.             <!-- 配置site 的国际化,默认为en,更改为zh_CN,以及设置编码格式,默认utf-8 -->  
  70.             <plugin>  
  71.                 <groupId>org.apache.maven.plugins</groupId>  
  72.                 <artifactId>maven-site-plugin</artifactId>  
  73.                 <version>2.0-beta-6</version>  
  74.                 <configuration>  
  75.                     <locales>zh_CN</locales>  
  76.                     <outputEncoding>utf-8</outputEncoding>  
  77.                 </configuration>  
  78.             </plugin>  
  79.             <!--   
  80.             <plugin>  
  81.                 <groupId>org.codehaus.mojo</groupId>  
  82.                 <artifactId>cobertura-maven-plugin</artifactId>  
  83.                 <version>2.2</version>  
  84.                 <configuration>  
  85.                     <formats>  
  86.                         <format>html</format>  
  87.                         <format>xml</format>  
  88.                     </formats>  
  89.                     <instrumentation>  
  90.                         <excludes></excludes>  
  91.                     </instrumentation>  
  92.                 </configuration>                
  93.             </plugin>  
  94.              -->  
  95.             <plugin>  
  96.                 <groupId>org.apache.maven.plugins</groupId>  
  97.                 <artifactId>maven-surefire-report-plugin</artifactId>  
  98.                 <version>2.12.2</version>  
  99.                 <configuration>  
  100.                     <showSuccess>true</showSuccess>  
  101.                 </configuration>  
  102.             </plugin>  
  103.         </plugins>  
  104.     </reporting>  
  105. </project>  
  106. </span>  


(三)工程预览

 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值