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

June 1, 2016 | Author: Ruslan Strazhnyk | Category: Types, Instruction manuals
Share Embed Donate


Short Description

With this presentation people can learn how to start Web Automation using Jenkins tools and how to integrate Automation ...

Description

Tools for Software QATitel andrein Testing Hier soll der

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

www.qs-tag.de

Ruslan Strazhnyk Maven Research Inc.

Host: imbus AG

www.qs-tag.de

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

Maven Research Inc – Knowledge sharing network for specialists and experts. Headquarters (San Francisco, USA) Development Team (Lviv, Ukraine)

www.maven.co

Introduction to Selenium 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 o o o

Selenium IDE Selenium Remote Control (1.0) Selenium Grid Selenium Webdriver (2.0)

Selenium is compatible with:

Where can I get Selenium? 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/

Beginning with Selenium?

May be hard on the beginning but very good in the end

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

Example of the Selenium Grid architecture

Selenium Grid 







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

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)

What is Jenkins? 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.

Jenkins Installation A lot of possibilities to install Jenkins:

Short link bit.ly/1bd2r4A

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 Selenium Plugin 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

Things to install on build machine

X Virtual Framebuffer Google Chrome Browser Git repository Unit get tool Python Interpreter Python Install Manager Selenium binding Python nose testrunner Nose testconfig

• 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

Jenkins Dashboard

Useful plug-ins for Jenkins Go to Jenkins > Manage Jenkins > Manage Plugins

1. 2. 3. 4.

Github plugin. xUnit plugin. Xvfb plugin. Other plug-ins you like.

Configure Test Execution Job 1. Before creating new job, open Jenkins -> Configure System. 2. Make sure you enter proper Xvfb installation configuation (for headless runs)

1. 2. 3. 4. 5. 6.

Create new Jenkins job. Choose github SCM https://github.com/Desperado/QS_tag_2013.git Choose “Build when a change is pushed to GitHub”. Start Xvfb before the build, and shut it down after. Write test execution command in “Execute shell”. Add Post-build Action – “Publish JUnit test result report”.

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.

Windows machine setup 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.

Windows machine setup 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.

Selenium slave nodes configuration Before using selenium server, up-to-date JRE must be downloaded and installed Get it on http://java.com 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/selenium-server.jar -role webdriver Dwebdriver.chrome.driver="C:/selenium/chromedriver.exe" -hub http://ciserver:4444/grid/register -port 5560 -nodeTimeout 1200 -browser browserName=chrome,platform=WINDOWS

Run tests in parallel 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

Questions? Ideas? Contacts.

[email protected]

http://ua.linkedin.com/in/ruslanstraznhyk/ http://twitter.com/strazhnyk IM(skype): ruslanstrazhnyk http://www.maven.co/join/TUHvWu8K

References and useful info

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

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF