Continuous Integration with Selenium
I have seen a lot of queries from people who basically want to know how to blend Selenium, Maven, and hudson to achieve continous integration.
So I thought I would write up my own recipe which has worked for me.
The ingredients that you would need for this recipe .
- Maven Standalone : A standalone installation of maven. (You can refer here for instructions on how to get it done )
- An IDE : I have used only eclipse. As a popular saying goes “a known devil is better than the unknown angel” I am sticking to eclipse. You can download a copy of eclipse from here
- Maven plugin : The newer versions of eclipse by default comes bundled with the maven plugin. But if you already have an eclipse copy with you and just want to add the maven plugin, you can add it from here
- TestNG plugin : You can add TestNG plugin to your eclipse installation from here. If you are not very familiar with adding plugins to eclipse, you can refer here
- Jenkins/Hudson instance for your continuous integration runs. For setting up hudson you can refer here
So lets start, now that we have our environment all setup and ready.
To begin with lets create a simple maven project from the command line. (for detailed help, you can refer here )
Let us first start by creating a simple maven project, from the command line. You would need to ensure you have maven available in your local machine.
Run the command :
|
1
2
|
mvn archetype:generate -DgroupId=organized.chaos -DartifactId=insanity -DpackageName=organized.chaos.insanity -Dversion=1.0-SNAPSHOT |
So here maven would create a directory named “insanity” which represents the root directory of my new maven project.
Once the project is created, create a folder under src/test and call it as “resources”.
Now lets take a look at the folder structure of our empty project (the folder name would be ‘insanity’)
|
1
2
3
4
5
6
7
8
9
10
11
12
|
$ find . -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' . |____src | |____main | | |____java | | | |____organized | | | | |____chaos | |____test | | |____java | | | |____organized | | | | |____chaos | | |____resources |
(I found this cool unix command from here)
Lets go ahead and add TestNG and selenium as dependencies to our pom file. Open up the pom file in eclipse or any other editor of your choice and add the below :
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.4</version>
</dependency>
<!-- Adding Selenium dependency -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.21.0</version>
</dependency>
So, lets add a <build> section to our pom file, and then lets add the compiler plugin as below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
Now go ahead and add all of your TestNG tests as desired and then create a suite file out of them. The simplest way of creating a suite file out of your TestNG tests from within eclipse would be to
multi-select them (using shift/ctrl + click) and then right click and say convert to TestNG.
The TestNG plug-in should give you a nice IDE using which you can create your suite file on the fly.
So our suite file is ready, and we need to just let maven know, that it has to pick up our suite file, whenever the test phase is invoked within maven.
This is where we leverage surefire-plugin. You can read more about surefire-plugin and all the options that it comes with here
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- We use a property here, because we want the ability to change the suite file on the fly
during runs '-DsuiteXmlFile=src/test/resources/testng-sample.xml' -->
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<!-- Build with '-DskipTests=true' to bypass test execution @ build time Default: false -->
<skipTests>${skipTests}</skipTests>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
|
|
Now our project is all ready. Here I have used two custom defined properties viz., “suiteXmlFile” and “skipTests”. This is how their definition looks like.
<properties>
<suiteXmlFile>
<strong>src/test/resources/test1.xml</strong>
</suiteXmlFile>
<skipTests>false</skipTests>
</properties>
Well I am doing this, so that when I am running tests from the command line, I can have the luxury of changing my suite file or telling maven to ignore my tests.
Something like this:
|
1
|
mvn test -DskipTests=true |
(This would tell maven not to run my unit tests at all)
|
1
|
mvn test -DsuiteXmlFile=src/test/resources/test2.xml |
(This would tell maven to run tests from test2.xml and not from test1.xml as defined in the pom file)
Make sure that you check-in your project into some version control system such as git/svn because hudson/jenkins pulls source code from version control systems and not from file systems.
Once you have your hudson instance setup, and are in the configure job page of your jenkins/fusion instance, look for a “build” section.
There in the Goals and options section, all you would do is specify the goals
for e.g.,
|
1
|
test -DsuiteXmlFile=src/test/resources/test2.xml |
(if you want this job to run unit tests from test2.xml) or just
|
1
|
test |
(if you want to by default run the tests from test1.xml). Here’s how my complete pom file looks like :
<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>organized.chaos</groupId>
<artifactId>insanity</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>insanity</name>
<properties>
<suiteXmlFile>src/test/resources/test1.xml</suiteXmlFile>
<skipTests>false</skipTests>
</properties>
<dependencies>
<!-- Adding TestNG for unit test support -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.4</version>
</dependency>
<!-- Adding Selenium dependency -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.21.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- using the compiler plug-in to specify that this project is to be compiled with JDK 1.6 -->
<!-- This is needed so that we get the JDK annotation support that was introduced recently -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- You can specify a specific testng.xml file here <suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng-sample.xml</suiteXmlFile> </suiteXmlFiles> -->
<!-- Or dynamically with something like '-DsuiteXmlFile=src/test/resources/testng-sample.xml' -->
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<!-- Build with '-DskipTests=true' to bypass test execution @ build time Default: false -->
<skipTests>${skipTests}</skipTests>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
</project>
Continuous Integration with Selenium的更多相关文章
- 持续集成(Continuous Integration)基本概念与实践
本文由Markdown语法编辑器编辑完成. From https://blog.csdn.net/inter_peng/article/details/53131831 1. 持续集成的概念 持续集成 ...
- TeamCity vs Jenkins: Which is the Better Continuous Integration (CI) Server for .NET Software Development?
原文:http://www.excella.com/insights/teamcity-vs-jenkins-better-continuous-integration-server So, you’ ...
- [转]GitLab Continuous Integration (GitLab CI/CD)
本文转自:https://docs.gitlab.com/ee/ci/README.html GitLab Continuous Integration (GitLab CI/CD) The bene ...
- 读《Top benefits of continuous integration》有感
看到一片文章<Top benefits of continuous integration>,这张图画的很棒.将整个CI流程各阶段,列举出来了. 作者在文章里面介绍了CI和TDD,以及采用 ...
- Continuous Integration for iOS Apps with Visual Studio Team Services
原文引用自:https://blog.xamarin.com/continuous-integration-for-ios-apps-with-visual-studio-team-services/ ...
- 关于CI/CD/CD (Continuous Integration/Continuous Delivery/Continuous Deployment)
Continuous Integration (CI) Continuous integration (CI) is the process that ensures the stability of ...
- 持续集成(CI – Continuous Integration)
持续集成(CI – Continuous Integration) 在传统的软件开发中,整合过程通常在每个人完成工作之后.在项目结束阶段进行.整合过程通常需要数周乃至数月的时间,可能会非常痛苦.持续集 ...
- Jenkins实现CI(Continuous Integration)到CD(Continuous Delivery)
Pipeline as Code是2.0的精髓所在,是帮助Jenkins实现CI(Continuous Integration)到CD(Continuous Delivery)华丽转身的关键推手.所谓 ...
- What is Continuous Integration?
什么叫持续集成? 原文: https://docs.microsoft.com/en-us/azure/devops/what-is-continuous-integration ---------- ...
随机推荐
- 【python接口自动化】logger
#! /usr/bin/env python # coding=GBK import logging, os class Logger: def __init__(self, path, clevel ...
- Xode 8 的那些坑
刚发布完Xcode的8.0果断更新了,发现用起来非常容易闪退,关键是我编辑项目时默认使用Xcode8打开,导致我用Xcode7打开Xib是报错: This version does not suppo ...
- static变量的生命周期
static生命周期 2011-07-15 16:01 静态变量的类型说明符是static.静态变量当然是属于静态存储方式,但是属于静态存储方式的量不一定就是静态变量,例如外部变量虽属于静态存储方式, ...
- VirtualBox 與 Vmware 差異
VirtualBox 4.3.36_Ubuntu r105129 與 VMware® Workstation 12 Player 12.5.2 build-4638234, 分別在各自的 Ubunt ...
- 在4418平台上如何配置GPIO口的状态
硬件 ------------------------------------------------------------------------------------------------- ...
- SQL Server 触发器 详细讲解
最近在做微信活动,需要用到存储过程,在网上找了下感觉使用触发器更好些,和大家分享下 希望对你有用. 触发器是一种特殊类型的存储过程,它不同于之前的我们介绍的存储过程.触发器主要是通过事件进行触发被自动 ...
- C#读取Excel 几种方法的体会
(1) OleDb: 用这种方法读取Excel速度还是非常的快的,但这种方式读取数据的时候不太灵活,不过可以在 DataTable 中对数据进行一些删减修改 这种方式将Excel作为一个数据源,直接用 ...
- 使用Naive Bayes从个人广告中获取区域倾向
RSS源介绍:https://zhidao.baidu.com/question/2051890587299176627.html http://www.rssboard.org/rss-profil ...
- 微信小程序 使用HMACSHA1和md5为登陆注册报文添加指纹验证签名
对接口请求报文作指纹验证签名相信在开发中经常碰到, 这次在与java后端一起开发小程序时,就碰到需求对登陆注册请求报文添加指纹验证签名来防止信息被修改 先来看下我们与后端定制签名规则 2.4. 签名规 ...
- Java泛型总结---基本用法,类型限定,通配符,类型擦除
一.基本概念和用法 在Java语言处于还没有出现泛型的版本时,只能通过Object是所有类型的父类和类型强制转换两个特点的配合来实现类型泛化.例如在哈希表的存取中,JDK1.5之前使用HashMap的 ...