Continuous integration with Jenkins & selenium2

Source: Internet
Author: User
Tags seleniumhq

Ui testing automation can continuously manage tedious UI tests, so that test cases and specific cases are separated to facilitate case tracking and instant feedback.

1. To give you a little history:

Jenkins is an excellent continuous integration tool developed on the basis of Hudson. selenium2 adds a powerful WebDriver driver on the basis of selenium1, so that the test case can be completely separated from selenium-server.

2. Prerequisites:

Subversion (http://subversion.tigris.org/getting.html) selenium2 WebDriver (http://seleniumhq.org/projects/webdriver/) Jenkins (http://jenkins-ci.org/) maven2 (http://maven.apache.org/) vncserver (http://www.realvnc.com /)InstallVncserver: 1 xhost + localhostInstallJenkinsservice Jenkins restart check whether the system attribute of Jenkins has display =: 1InstallMaven2mvn-version

3. Create a Maven project (I .e. create 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>web_driver</groupId><artifactId>web_driver</artifactId><version>0.0.2-SNAPSHOT</version><name>web_driver</name><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.8.1</version><scope>test</scope></dependency><dependency><groupId>commons-httpclient</groupId><artifactId>commons-httpclient</artifactId><scope>compile</scope><version>3.1</version></dependency><dependency><groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-java</artifactId><version>2.11.0</version></dependency></dependencies><build><plugins><plugin><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.5</source><target>1.5</target><encoding>UTF8</encoding></configuration></plugin><plugin><groupId>org.codehaus.mojo</groupId><artifactId>emma-maven-plugin</artifactId><version>1.0-alpha-3</version></plugin><plugin><groupId>org.codehaus.mojo</groupId><artifactId>findbugs-maven-plugin</artifactId><version>2.3.2</version><configuration><findbugsXmlOutput>true</findbugsXmlOutput><findbugsXmlWithMessages>true</findbugsXmlWithMessages><xmlOutput>true</xmlOutput><findbugsXmlOutputDirectory>target/site</findbugsXmlOutputDirectory></configuration></plugin></plugins></build><reporting><plugins><plugin><groupId>org.codehaus.mojo</groupId><artifactId>emma-maven-plugin</artifactId><version>1.0-alpha-3</version><inherited>true</inherited></plugin><plugin><groupId>org.codehaus.mojo</groupId><artifactId>surefire-report-maven-plugin</artifactId><inherited>true</inherited></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></configuration></plugin></plugins></reporting></project>

4. Add the webdrivertestsproject into Subversion:

Add case:

Public class demo {Public String case10 () {return "Google query ";}}

Add case implementation:

Public class webtest {demo = new demo (); Private Static WebDriver driver; private webelement element; private string weburl = "http://www.google.com/"; private stringbuffer verificationerrors = new stringbuffer (); @ beforeclasspublic static void setupbeforeclass () throws exception {firefoxprofile profile = new firefoxprofile (); profile. setpreference ("General. useragent. override "," Mozilla/4.0 (compati Ble; MSIE 8.0; Windows NT 6.1) "); driver = new firefoxdriver (profile); driver. manage (). timeouts (). implicitlywait (5, timeunit. seconds) ;}@ afterclasspublic static void teardownafterclass () throws exception {driver. quit () ;}@ beforepublic void setup () throws exception {}@ afterpublic void teardown () throws exception {string verificationerrorstring = verificationerrors. tostring (); If (! "". Equals (verificationerrorstring) {fail (verificationerrorstring) ;}@testpublic void testcase10 () {// query system. out. println (demo. case10 (); driver. get (weburl) inputelement = driver. find_element_by_name ("Q") inputelement. send_keys ("Cheese! ") Inputelement. Submit () print driver. titletry: webdriverwait (driver, 10). Until (lambda DRIVER: Driver. Title. Lower (). startswith (" Cheese! ") Print driver. titlefinally: Driver. Quit ()}}

5. Upload the maven project to SVN. The SVN address will be used in the configuration of Jenkins below.

 

6. Running the testcases remotely and continuously:

Create a maven2 project in Jenkins and configure it all the way. In goals and options, enter "Clean-Dtest = com. Google. webtest EMMA: Emma findbugs: findbugs cobertura: cobertura ".

Click build now to run.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.