1. Jenkins本地执行测试 or 服务器端执行测试

测试代码计划通过jenkins执行时,通过网上查询各种教程,大多数为本地执行测试,由此可见,本地执行是大多数人的选择。

经过探讨,最终决定采用服务端执行测试。自动化测试代码上传到测试服务器,通过jenkins部署并执行,可减少本地资源占用。

2. 服务器端执行测试,需要的browser & webDriver

鉴于公司测试服务器为无界面的Linux系统,浏览器采用无界面的chrome。即,在服务器安装Headless Chrome。

webDriver选用chromeDriver对应版本。chromeDriver下载:http://npm.taobao.org/mirrors/chromedriver/

 ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
return new ChromeDriver(options);

3. 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>com.hebg3</groupId>
<artifactId>UITest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>UITest</name>
<url>http://maven.apache.org</url>
<profiles>
<profile>
<id>saveOrder</id>
<build>
<plugins>
<!-- 测试运行器,用于运行测试用例 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<!-- 添加testng.xml文件,相当于run as testngSuite -->
<suiteXmlFile>src/test/resources/saveOrder.xml</suiteXmlFile>
</suiteXmlFiles>
<source>${java.version}</source>
<target>${java.version}</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<!-- 可执行jar插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<!-- 将src/test文件夹打成jar包 -->
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<!-- 打包配置 -->
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
<!-- 打包时不包含以下格式的文件 -->
<excludes>
<exclude>**/*.xml</exclude>
<exclude>**/*.properties</exclude>
<exclude>**/*.csv</exclude>
</excludes>
</configuration>
</plugin> <!-- maven资源文件复制插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<!-- 复制src/main/resources路径的文件 -->
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/src/main/resources</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.csv</include>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<encoding>UTF-8</encoding>
</configuration>
</execution>
<!-- 复制src/test/resources路径的文件 -->
<execution>
<id>copy-test-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/src/test/resources</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/test/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.csv</include>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<encoding>UTF-8</encoding>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<!-- 设置jdk版本与编码格式 -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<encoding>UTF-8</encoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties> <dependencies>
……
</dependencies>
</project>

4. 打包命令

4.1 打包命令的执行

eclipse中右击项目名称 - 【Run As】-【Maven Build ...】,在goals处输入以下命令并运行;

4.2 打包:package -DskipTests=true -PsaveOrder

说明:-D跳过测试,直接打包,首先需要进行测试能否正常打包,之后再执行测试;

-P选择profile id(Line:15),不选择profile id会按默认执行,执行所有testng.xml,各插件版本也与设置的不同;

4.3 执行测试:test -PsaveOrder

4.4 配置jenkins:以上命令均能正常执行 -> 代码上传到git -> 运维大佬帮忙布置jenkins,jenkins执行的本质即,执行以上两条命令;

5. 多个testSuite的配置

当存在多个testng.xml文件,包含多个testSuite时,可以通过pom.xml设置多个profile来分别执行;

以上,Line14~123即为一个profile,可同时设置多个,根据不同情境,执行不同的profile;

我们目前的做法是:在部署jenkins项目时,输入profile id方可执行,实现了一个项目,多个测试情境按需使用;

6. 测试结果的查看

目前做法:在jenkins中添加了HTML Report、TestNG Results插件。

Java+Selenium 3.x 实现Web自动化 - Maven打包TestNG,利用jenkins执行测试的更多相关文章

  1. Java+Selenium 3.x 实现Web自动化 - 1.自动化准备

    (一)自动化准备 说明:本文主要记录了基于公司现有项目(一个电子商务平台),从0开始实现UI自动化的历程.从准备阶段,部分内容直接省略了基础知识,一切以最终做成自动化项目为目标,难免会有晦涩之处.文章 ...

  2. 《手把手教你》系列基础篇(五)-java+ selenium自动化测试- 创建首个自动化脚本(详细教程)

    1.简介 前面几篇宏哥介绍了两种(java和maven)环境搭建和三大浏览器的启动方法,这篇文章宏哥将要介绍第一个自动化测试脚本.前边环境都搭建成功了,浏览器也驱动成功了,那么我们不着急学习其他内容, ...

  3. windiows下搭建python+selenium+unittest+Chrome的Web自动化环境

    一.selenium.unittest概念 Selenium 是用于测试 Web 应用程序用户界面 (UI) 的常用框架.它是一款用于运行端到端功能测试的超强工具.您可以使用多个编程语言编写测试,并且 ...

  4. requests库结合selenium库共同完成web自动化和爬虫工作

    我们日常工作中,单纯的HTTP请求,程序员都倾向于使用万能的python Requests库.但大多数场景下,我们的需求页面不是纯静态网页,网页加载过程中伴随有大量的JS文件参与页面的整个渲染过程,且 ...

  5. java web 使用maven打包绕过单元测试

    <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-suref ...

  6. 【jenkins】jenkins+maven+gitlab+testng,jenkins配置

    电脑版本:windows10企业版 jenkins配置: 1.general配置,这里的配置比较简单,基本默认就可以了 2.源码管理 2.1填写git地址,从你的gitlib项目里去找.不会的自行百度 ...

  7. maven 打包成 .jar 文件执行:没有主清单属性错误

    报错原因是pom.xml配置文件中没有指定main入口信息,在pom.xml文件中添加如下代码: <build> <plugins> <plugin> <gr ...

  8. MAVEN打包时跳过Junit测试

    我们知道,通常情况下使用maven package命令打包时,会自动执行test包下的各个单元测试. 这是因为spring-boot-maven-plugin插件已经集成了maven-surefire ...

  9. maven打包配置

    maven打包配置,到底要打包哪些文件,如何配置?? <build> <finalName>weatherAdminSys</finalName> <plug ...

随机推荐

  1. URL列表

    MySql函数大全:http://www.cnblogs.com/xuyulin/p/5468102.html

  2. CSU 1598 最长公共前缀 (简单KMP或者暴力)

    Submit Page    Summary    Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitted: 226     Solved: ...

  3. css让不同大小的图片适应div的大小,且不变形。

    做成背景图片 单个 .imgdiv { width: 100px; // 你要的正方形 height: 100px; // 你要的正方形 background-image: url(/your/ima ...

  4. 常用 超全局数组$_server

    $_SERVER 是一个包含了诸如头信息(header).路径(path).以及脚本位置(script locations)等等信息的数组.这个数组中的项目由 Web 服务器创建.不能保证每个服务器都 ...

  5. 查询优化百万条数据量的MySQL表

    转自https://www.cnblogs.com/llzhang123/p/9239682.html 1.两种查询引擎查询速度(myIsam 引擎 ) InnoDB 中不保存表的具体行数,也就是说, ...

  6. (Les16 执行数据库恢复)-控制文件恢复

    测试丢失所有控制文件恢复[20180517]     rman target /   show all;   configure channel 1 device type disk format ' ...

  7. JavaScript日期格式转换

    //日期格式转换 function dateFormat(val) {//val需要转换的日期 var fmt = "yyyy-MM-dd";//日期格式 val = val.re ...

  8. 大数据时代的结构化存储--HBase

    迄今,相信大家肯定听说过 HBase,但是对于 HBase 的了解可能仅仅是它是 Hadoop 生态圈重要的一员,是一个大数据相关的数据库技术. 今天我带你们一起领略一下 HBase 体系架构,看看它 ...

  9. centos 安装 telnet

    (转)centos7安装telnet服务 场景:在进行Telnet测试时候,发现无法连接,所以还得把这个软件也安装了 1 CentOS7.0 telnet-server 启动的问题 解决方法:   先 ...

  10. usb驱动之打印usb设备信息(二)

    以下是打印鼠标左右键及其他输入的源代码,详细说明见https://www.cnblogs.com/zhu-g5may/p/9309381.html /*参考/drivers/hid/usbhid/us ...