• No results found

Full Featured Test Automation using Selenium Grid and CI (Jenkins)

N/A
N/A
Protected

Academic year: 2021

Share "Full Featured Test Automation using Selenium Grid and CI (Jenkins)"

Copied!
23
0
0

Loading.... (view fulltext now)

Full text

(1)

Hier soll der Titel rein

Tools for Software QA and Testing

www.qs-tag.de

Host: imbus AG

www.qs-tag.de

Full Featured Test

Automation using Selenium

Grid and CI (Jenkins)

Ruslan Strazhnyk

Maven Research Inc.

(2)

About me

Ruslan Strazhnyk

Experience – 10 years in IT (7 in QA Automation)

Areas:

– Test Automation, Data-driven testing, Performance Testing, Continuous Integration

Position:

– QA Automation Engineer

Skills:

– Python, Selenium, Jenkins, MySQL, SQLAlchemy – Jmeter, Cloud Services, Linux, Virtualization

www.maven.co

Maven Research Inc – Knowledge sharing network for specialists and experts.

Headquarters (San Francisco, USA) Development Team (Lviv, Ukraine)

(3)

Selenium is a set of different software tools built originally on Selenium Core (JavaScript library) each with a different approach to supporting web test automation.

Selenium is most known of it’s:

o Selenium IDE

o Selenium Remote Control (1.0) o Selenium Grid

o Selenium Webdriver (2.0)

Selenium is compatible with:

(4)

Why people use Selenium?

 Organizations adopt virtualization and cloud-based technologies  It scales the test automation and can cut costs in physical

hardware and increase efficiency of testing

 Selenium WebDriver has unmatched support for testing

applications in virtual environment, executing tests in parallel, reducing costs, and increasing speed and coverage

How can I start using Selenium?

o You can download bindings for your language and write code using in Selenium/Webdriver API directly

o But it is faster to start by downloading Selenium IDE Firefox plug-in o The tool will help you to record your first testcases

o Get it on http://docs.seleniumhq.org/download/

(5)

Beginning with Selenium?

(6)

So how does Selenium work

IDE: Records and plays back tests in Firefox.

Allows to export tests to many programming

languages

Your Tests – series of Selenium commands,

which are sent to Selenium Remote Control

Server or the Selenium Grid server

Selenium RC starts up browsers (1 at time)

and run commands you pass along from

your tests

Selenium Grid coordinates multiple

Selenium RC’s, where you can tests on

lots of platforms, allows wider and parallel

testing

(7)

Example of the Selenium Grid

architecture

(8)

 Selenium Grid allows us to run multiple instances of WebDriver or Selenium Remote Control in parallel.

 It makes all these nodes appear as a single instance, so tests do not have to worry about the actual infrastructure. Selenium Grid cuts down on the time required to run

 Selenium tests to a fraction of the time that a single instance of Selenium would take to run and it is very easy to set up and use.

 The selenium-server-standalone

package includes the Hub, WebDriver, and Selenium RC needed to run the grid

(9)

Selenium Test Script

Go to

https://github.com/Desperado/QS_tag_2013

class ImbusTest(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.implicitly_wait(30) self.base_url = "http://www.maven.co/" self.verificationErrors = [] self.accept_next_alert = True def test_maven_site(self): driver = self.driver driver.get(self.base_url) driver.find_element_by_link_text("Electronic Surveys").click() self.assertEqual("Survey Experts | Maven", driver.title)

self.assertEqual("Electronic Surveys", driver.find_element_by_css_selector("h1").text) self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "div.surveys-image"))

self.assertEqual("How it Works", driver.find_element_by_css_selector("div.centered-content > h1").text) driver.find_element_by_css_selector("img[alt=\"Maven\"]").click()

driver.find_element_by_link_text("Telephone Consultations").click() self.assertEqual("Consult with an Expert | Maven", driver.title)

(10)

Jenkins is an award-winning application that monitors executions of repeated jobs.

It’s main focus is on:

Building/testing software projects continuously

Jenkins provides an easy-to-use so-called continuous integration system, making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build.

As continuous integration is a widely accepted practice, it is essential that we run Selenium WebDriver tests as part of the CI process for early feedback and increased confidence. Jenkins is widely used as a continuous integration server tool.

Instead of having a plain Selenium Grid, Jenkins provides a Selenium Grid that can be very well integrated with the CI infrastructure. We can use Jenkins' powerful distributed model for CI to run our Selenium tests in parallel on a Jenkins cluster.

(11)

A lot of possibilities to install Jenkins:

o as an app on Ubuntu / Red Hat o as a Unix deamon

o as Solaris 10 service o as a Windows service

o More here https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins

Jenkins Installation

(12)

We need to install Jenkins Selenium Plugin to add Selenium Grid support in Jenkins. Use the

following steps to install and configure Jenkins Selenium Plugin: 1. Click Manage Jenkins on the Jenkins Dashboard.

2. Click on Manager Plugins from the Manage Jenkins option. 3. Click on the Available tab.

4. Locate and select Jenkins Selenium Plugin from the list of available plugins. 5. Click on the Download now and install after restart button.

6. A new screen will be displayed Installing Plugins/Upgrades.

7. After the plugin is downloaded, restart Jenkins. Make sure that no jobs are running

while you restart.

8. After Jenkins restarts, a Selenium Grid link will appear on the left side navigation pane.

9. Click on Selenium Grid, the Registered Remote Controls page will be displayed.

10. Selenium Grid is now available on http://localhost:4444/wd/hub for tests

(13)

Things to install on build machine

• sudo apt-get install xvfb

• sudo apt-get install google-chrome

• sudo apt-get install git

• sudo apt-get install wget

• sudo apt-get install python

• sudo apt-get install python-pip

• sudo pip install selenium

• sudo pip install nose

• sudo pip install nose-testconfig

X Virtual Framebuffer

Google Chrome Browser

Git repository

Unit get tool

Python Interpreter

Python Install Manager

Selenium binding

Python nose testrunner

Nose testconfig

(14)
(15)

Useful plug-ins for Jenkins

1. Github plugin.

2. xUnit plugin.

3. Xvfb plugin.

4. Other plug-ins you like.

(16)

1. Before creating new job, open Jenkins -> Configure System.

2. Make sure you enter proper Xvfb installation configuation (for headless runs)

1. Create new Jenkins job.

2. Choose github SCM https://github.com/Desperado/QS_tag_2013.git

3. Choose “Build when a change is pushed to GitHub”. 4. Start Xvfb before the build, and shut it down after. 5. Write test execution command in “Execute shell”.

6. Add Post-build Action – “Publish JUnit test result report”.

(17)

Building custom Selenium plug-in

1. git clone https://github.com/jenkinsci/selenium-plugin.git

2. Jump into directory and do: mvn install –DskipTests 3. Upload selenium.hpi into ci from "target" directory.

(18)

1. Download latest Selenium server from

http://code.google.com/p/selenium/downloads/list/

2. Rename and place it into C:/Selenium/selenium-server.jar

1. Download Firefox binary and install

2. Find Firefox profile template and copy to another folder. 3. Rename it to C:/selenium/firefox/ilki8ovl.selenium

1. Place it into C:/selenium/chromedriver.exe 2. Download Chromedriver.

(19)

1. Make sure system has all needed security updates.

2. Make sure Windows Internet Options are set the same for all zones(as lowest as possible). 3. Make protected mode Off on all zones.

4. Disable Autocomplete - http://bit.ly/1eUlHc9 5. Disable annoying security warnings –

http://bit.ly/1803zdJ

6. Make sure you are not using any other 3rd party firewalls, antiviruses that block Selenium port 4444 etc.

(20)

java -jar C:/Selenium/selenium-server.jar -role webdriver -hub http://ci-server:4444/grid/register -port 5565

-nodeTimeout 1200 -browser browserName=iexplore,version=8,platform=WINDOWS

java -jar C:/Selenium/selenium-server.jar -role webdriver -hub http://ci-server:4444/grid/register -port 5555

-nodeTimeout 1200 -firefoxProfileTemplate "C:/selenium/firefox/ilki8ovl.selenium” -browser browserName=firefox,version=23,platform=WINDOWS

java jar C:/Selenium/seleniumserver.jar role webdriver

-Dwebdriver.chrome.driver="C:/selenium/chromedriver.exe" -hub http://ci-server:4444/grid/register -port 5560 -nodeTimeout 1200 -browser

browserName=chrome,platform=WINDOWS

Selenium slave nodes configuration

Before using selenium server, up-to-date JRE must be downloaded and installed

(21)

Running tests in parallel will decrease single test running speed:

 Test A execution ~ 10 sec.  Test B execution ~ 12 sec.

 A+B on single session ~ 22 sec.  A || B on parallel session ~ 14 sec.

 More parallel runs – more optimization  Needs a lot of computer power though

(22)

Questions? Ideas? Contacts.

[email protected]

http://ua.linkedin.com/in/ruslanstraznhyk/

http://twitter.com/strazhnyk

IM(skype): ruslanstrazhnyk

http://www.maven.co/join/TUHvWu8K

(23)

Selenium Website

http://www.seleniumhq.org/

Selenium Official Blog

http://seleniumhq.wordpress.com/

Jenkins website

http://jenkins-ci.org/

Parallel Selenium testing

http://www.deepshiftlabs.com/sel_blog/?p=1932&lang=en-us

References

Related documents

Characteristics of included studies (Continued) neg- ative sepsis) vs 53.. 7) Sepsis (gen- eral) Mix/ un- clear Not re- ported Acute pyelonephri- tis, pneu- monia, diges- tive

Hasil penelitian menunjukkan bahwa wilayah perairan Pulau Menjangan ber- potensi keterpaparan dari berbagai unsur, yaitu jumlah pengunjung, tinggi gelombang, tipe

Information about all deaths not attributed to war-related physical trauma occurring in Gaza during the period July to September 2014 was instead collected from Ministry of

immunological agents, e.g. the CTLA-4 inhibitor ipilimumab. We investigated the occurrence of neuromuscular disorders with regards to clinical and laboratory findings. Based on

Moreover, if only minimal paths are constructed, then longer ones may be needed in order to produce the same number of answers, thereby causing more work compared with an algorithm

It turns out that among all the points at infinity in the projective plane, only one is on the elliptic curve; i.e., the line at infinity intersects E only in one point

This study aims to recognize the effect of the working pillars of the internal audit committees in improving the financial performance in the commercial banks in Jordan.The

Almost every country in the world today is connected to an internet but there are challenges in making firm legislations for dealing with e- evidence , e-contract and