1.首先是自动化测试系统架构如下图:
2.测试脚本的应用架构:
3实际应用后的工程结构:
框架的配置文件(只是简单的用properties文件)
#------------------#
# 测试框架配置
#------------------#
#启动目标浏览器驱动运行测试
#Browser.Type=ec.qa.autotest.ui.framewrok.webdriverfactory.IEBrowserDriver 暂不支持此浏览器
Browser.Type=ec.qa.autotest.ui.framewrok.webdriverfactory.ChromeBrowserDriver
#Browser.Type=ec.qa.autotest.ui.framewrok.webdriverfactory.FireFoxBrowserDriver
#用例失败重试次数
testcase.failedcase.retrycount=1
#开启用例失败自动截图功能
testcase.failedcase.screenShotEnabled=true
#失败截图保存的目录
testcase.failedcase.screenShotPath=test-output/screen-shot
#是否生成自定义HTML报告
testcase.reporter.htmlreport=true
#自定义HTML报告存放路径
testcase.reporter.htmlreport.path=test-output/html-report
#测试数据文件夹地址
testcase.testdata.path=test-data
#测试图片文件夹地址
testcase.testpic.path=\\test-data\\pic\\
#扫描page对象的包将页面对象自动注入到用力中
init.pageobj.Package = ec.qa.autotest.ui.admin.portal.pageobject,ec.qa.autotest.ui.common.action,ec.qa.autotest.ui.supplier.portal.pageobject,ec.qa.autotest.ui.dao.impl
#mybatis配置文件路径
init.mybatis.config.path = mybatis-config/mybatis.xml
#测试用例包
init.pageobj.suplier.testcase.Package = ec.qa.autotest.ui.supplier.portal.testcases
init.pageobj.admin.testcase.Package = ec.qa.autotest.ui.admin.portal.testcases
4.jenkins的job启动自动测试的批处理(因为是基于UI的自动化测试,所以测试代理机是windows系统,使用的是DOS批处理):
@echo off
set workspace=%1%
if not exist %workspace% mkdir %workspace%
cd /d %workspace%
if exist EC_Automation_Test goto cleanENV
goto AutoTest
:cleanENV
echo "project folder exist"
rd /s /q %workspace%\EC_Automation_Test
goto AutoTest
:AutoTest
git clone git@192.168.0.156:root/EC_Automation_Test.git
cd EC_Automation_Test
mvn clean test > %workspace%\%date:~5,2%-%date:~8,2%-%time:~0,2%-%time:~3,2%.txt
5.jenkins job 脚本配置(上述脚本保存在 RunAutoTest.bat中):
6.使用jenkins 启动自动测试:
Started by user qa
Building remotely on AutoMation_Test_Agent (AutoTest) in workspace D:\jenkins\workspace\EC_AutoMation_Test
[EC_AutoMation_Test] $ cmd /c call C:\Users\QA\AppData\Local\Temp\hudson2390304531070066944.bat
The Test Base On Chrome
找不到进程: chromedriver
找不到进程: iedriverserver
"project folder exist"
Cloning into 'EC_Automation_Test'...
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building EC_UI_Auto_Test 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ EC_UI_Auto_Test ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ EC_UI_Auto_Test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\jenkins\workspace\EC_AutoMation_Test\EC_Automation_Test\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ EC_UI_Auto_Test ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 55 source files to D:\jenkins\workspace\EC_AutoMation_Test\EC_Automation_Test\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ EC_UI_Auto_Test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\jenkins\workspace\EC_AutoMation_Test\EC_Automation_Test\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ EC_UI_Auto_Test ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ EC_UI_Auto_Test ---
[INFO] No tests to run.
[INFO] Surefire report directory: D:\jenkins\workspace\EC_AutoMation_Test\EC_Automation_Test\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
...
... TestNG 6.9.4 by Cédric Beust (cedric@beust.com)
...
======测试用例: AddProductDemo 开始执行======
===测试用例运行的浏览器类型:Chrome ===
测试网站地址: http://xxx.xxx.com/
Starting ChromeDriver 2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067) on port 26146
Only local connections are allowed.
上传图片中
=====测试用例: AddProductDemo 运行成功=====
killed the useless process
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 104.861 sec - in TestSuite
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:50 min
[INFO] Finished at: 2015-12-09T16:42:52+08:00
[INFO] Final Memory: 21M/222M
[INFO] ------------------------------------------------------------------------
Recording test results
Sending e-mails to: qa.group@xxxxx.com
Finished: SUCCESS
7.POM.XML配置:
<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>EC_Auto_Test</groupId>
<artifactId>EC_UI_Auto_Test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>EC_UI_Auto_Test</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src\main\java\testng-config\test.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.4</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.47.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.47.1</version>
</dependency>
</dependencies>
</project>
用例代码编写文档及实例:
作者:王鑫
日期:Sep.16.2015
最后更新日期:None
****************************************************************************************************************************
代码目录结构:
目前测试代码只有一个工程,在该工程中,类文件(.java)的分组及其存在意义如下:
1.Src/main/java - ec.qa.autotest.ui.constants 用来保存全局变量/常量/其他信息
2.Src/main/java - ec.qa.autotest.ui.pageobject用来保存页面的元素信息或其他从属信息,每个类对应一个页面,每个页面对应一个类;
3.Src/main/java - ec.qa.autotest.ui.testbase 用来保存基本测试逻辑,比如每个测试用例的初始化环境步骤;
4.