Upload
springpeople
View
245
Download
0
Embed Size (px)
Citation preview
by Gururaj
Learn How To Use Selenium Successfully In Conjunction With Other Tools
• We have INSTRUCTOR -LED - both Online LIVE & Classroom Session
Present for classroom sessions in Bangalore & Delhi (NCR)
We are the ONLY Education delivery partners for Mulesoft, Elastic, Pivotal &
Lightbend in India
We have delivered more than 5000 trainings and have over 400 courses and
a vast pool of over 200 experts to make YOU the EXPERT!
FOLLOW US ON SOCIAL MEDIA TO STAY UPDATED ON THE UPCOMING
WEBINARS
Non-Certified Courses
…and many more
Certified Partners
• Selenium tool
• Write maintainable and reusable Selenium scripts
• Reporting Structure by using external plugin's
• Cross browser testing (Running selenium grid with Docker)
• UI layout test using Galen framework
• Maven– automation build tool
• Code repository (Git)
• Jenkins CI tool
Agenda
Selenium
Selenium is the best open source tool for doing automation for web based
application and it does not have any cost attached to it. The only cost is the effort which
will go for designing and developing the script for the application.
Selenium scripting can be done in a number of programming languages like C#, Perl,
PHP, Ruby, Java etc, unlike other commercial tools which support single scripting
language. Since Selenium scripting can be done in any language of choice, one can easily
find right resources for the programming language chosen for Selenium Automation.
Last but not the least, since this tool comes at ZERO PRICE, an organization’s
management will find that the only investment they have made is on the infrastructure and
human effort and not on the heavy licensing cost.
IDE WebDriver Grid
Selenium uses what is called locators to find and match the
elements of your page that it needs to interact with: Link XPath ID Name CSS
Locators
Add on's
Css selector helper
WebDriver Element Locator
Page object generator - Plugin
Selenium Page Object Generator is an essential tool
to improve your workflow. It will generate Page
Object Model on active Chrome tab with a single
click, provided that all the options and template are
configured. The generated Page Object Model will
be saved to pre-configured Chrome download folder.
It strives to reduce manual involvement, but manual
tweak still recommended
Sample file
Preferred selector order to locators ;
Preferred Order
ID Locator
NAME Locator
CSS Locator
XPATH Locator
Thread.sleep Implicit Waits Explicit Waits FluentWait
Implicit waits :Once set, the implicit wait is set for the life of the WebDriver object instance.
Explicit waits: An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code
Exception Handling
Expected Conditions
Because it's quite a common occurrence to have to synchronize the DOM and your instructions, most clients also come with a set of predefined expected conditions. As might be obvious by the name, they are conditions that are predefined for frequent wait operations.
The conditions available in the different language bindings vary, but this is a non-exhaustive list of a few:
alert is presentelement existselement is visibletitle containstitle isvisible text
Expected Conditions
Expected Conditions
Because it's quite a common occurrence to have to synchronize the DOM and your instructions, most clients also come with a set of predefined expected conditions. As might be obvious by the name, they are conditions that are predefined for frequent wait operations.
The conditions available in the different language bindings vary, but this is a non-exhaustive list of a few:
alert is presentelement existselement is visibletitle containstitle isvisible text
Expected Conditions
Sample code...
Problem : open Jquery component and try to get tooltip for the textbox
Other Options
FluentWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition.
User may configure the wait to ignore specific types of exceptions whilst waiting, such as NoSuchElementExceptions when searching for an element on the page.
// Waiting 30 seconds for an element to be present on the page, checking// for its presence once every 5 seconds.Wait<WebDriver> wait = new FluentWait<WebDriver>(driver) .withTimeout(30, SECONDS) .pollingEvery(5, SECONDS) .ignoring(NoSuchElementException.class);
WebElement foo = wait.until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("foo")); }});
Fluent Waits
Common functions or Keywords Click, Verify, Wait for Element, EnterText, SelectBox etc..
Page Object Model / Factory
Reusability
Example
Page Object Model is a design pattern to create Object Repository for web UI elements. Under this model, for each web page in the application there should be
corresponding page class. This Page class will find the WebElements of that web page and also contain page
methods which perform operations on those WebElements. Name of these methods should be given as per the task they are performing
Page Object Model
POM - Example
TestCases
Pages
Page Factory
Page Factory is an inbuilt page object model concept for Selenium WebDriver
@FindBy elements - use of @FindBy annotations. With this annotation, we can define a
strategy for looking up the element, along with the necessary information for identifying
it:
@FindBy can accept tagName, partialLinkText, name, linkText, id, css, className, xpath as attributes.
Example
LoginPage = PageFactory.initElements(driver, LoginPagePOF.class); }
@Test public void test() { LoginPage.LogIn_Action("guest", "guest"); System.out.println(" Login Successfully, now it is the time to Log Off buddy."); }
Page Factory
Page Factory Class To initialize WebElements
Page Factory - Project
Page Factory
TestNG classes
Test Data
Config
Utility Factory
Reports
Screen Shots
Logs
`
`
`
`
Generating reports is always challenge with Selenium, since it doesn't comes with
any reporting features. There are lot of plugin's available will see in action;
REPORTING
XSLT
Report NG
ATU Reports
Extent
<target name="xsltreports"> <mkdir dir="${basedir}/XSLT_Reports/output"/>
<xslt in="${ng.result}/testng-results.xml" style="src/com/xslt/testng-results.xsl"
out="${basedir}/XSLT_Reports/output/index.html" classpathref="classpath_jars" processor="SaxonLiaison">
<param name="testNgXslt.outputDir" expression="${basedir}/XSLT_Reports/output/"/>
<param name="testNgXslt.showRuntimeTotals" expression="true"/>
</xslt> </target>
XSLT - Reporting
Create ANT task in build.xml file with target
Sample Report
ReportNG is a simple HTML reporting plug-in for the TestNGunit-testing framework. It is intended as a replacement for the default TestNG HTML report. The default report is comprehensive but is not so easy to understand at-a-glance. ReportNG provides a simple, colour-coded view of the test results.ReportNG generates 100% valid XHTML 1.0 files. The output can be customised by over-riding the default stylesheet with your own CSS file.
ReportNG - Plugin
Sample Report
Very simple to use API
Beautiful and responsive UI
Provides dashboard for the entire run
Parallel execution of classes and methods supported
Creates a single report file, so less management of artifacts required (Online only*, Offline report stores all artifacts locally)
Separate section for categories, provides analysis of tests by category
Easily integrate test-runner logs
Can be customized heavily using an external config file
and this is developed by http://extentreports.relevantcodes.com
Extent Reports - Plugin
Very simple to use API
Beautiful and responsive UI
Provides dashboard for the entire run
Parallel execution of classes and methods supported
Creates a single report file, so less management of artifacts required (Online only*, Offline report stores all artifacts locally)
Separate section for categories, provides analysis of tests by category
Easily integrate test-runner logs
Can be customized heavily using an external config file
and this is developed by http://extentreports.relevantcodes.com
Extent Reports - Plugin
Sample Report
ATU Reporter is free open source plugin/utility for Selenium. This will be a TestNG listener for generating customized graphical reports. Following reports can be generated by this listener.
Line Charts Bar Charts Pie Charts
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"><suite name="Suite" parallel="false"> <test name="Test"> <classes> <class name="com.test.AUTReporting.ReporterGoogleTest"/> </classes> </test> <listeners> <listener class-name="atu.testng.reports.listeners.ATUReportsListener"></listener> <listener class-name="atu.testng.reports.listeners.ConfigurationListener"></listener> <listener class-name="atu.testng.reports.listeners.MethodListener"></listener> </listeners></suite>
ATU Reports - Plugin
Sample Report
Cross Browser Testing is a type of functional test to check that your web application
works as expected in different browsers.
Cross Browser Testing
CBT – With cloud services
Running test on local machine with different OS with different combination of browsers its always a challenge, either we need to get more machine and really on selenium grid to solve the problem. Now without installing any OS or browser can we run the selenium scripts on cloud, yes its possible with some of the cloud services like
Testing botSauce labBrowserSTack.
public static final String KEY = "your key paste here"; public static final String SECRET = "your secret paste here"; public static final String URL = "http://" + KEY + ":" + SECRET + "@hub.testingbot.com/wd/hub";
public static void main(String[] args) throws IOException, InterruptedException { // TODO Auto-generated method stub
DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("platform", "WIN8"); caps.setCapability("version", "35"); caps.setCapability("browserName", "chrome");// Remote web driver to register with testing bot key and secret, so that it will launch browser on these machines
driver = new RemoteWebDriver(new URL(URL), caps); driver.get("https://timetracker.anuko.com/login.php");
Grid with Cloud Services
In simple words, Docker – with use of linux-containers – allows you to
pack all your application dependencies, like database, system libraries
and so on, into standardized and portable units, called containers. You don’t need to ship entire OS to your CI or production server. We can manage this with containers with independent units.
Selenium Grid with Docker
Docker is a lightweight container (read: a scaled-down VM) that provides a fast and programmatic
way to run distributed applications. Selenium Grid is distributed system of nodes for running tests.
Instead of running your grid across multiple machines or VMs, you can run them all on a single
large machine using Docker.
`docker-selenium` project is about packaging selenium grid as docker containers (
https://github.com/seleniumhq/docker-selenium)
We don't have to build any selenium infrastructure machines. I just run the provided images by
docker-selenium project (https://hub.docker.com/r/selenium/).
We don't have to install selenium jar, java, browsers and other runtime dependencies. They are
already built in a docker image and I can just run them as either selenium grid with hub and nodes
or as standalone selenium on any docker engine enabled vm.
Docker
Setup
Create Docker images for your Selenium Grid hub and node(s)
Add Java to the hub to run the Selenium server jar
Add Java, plus Firefox and Xvfb to the node (Xvfb is an X server that can run on
machines with no display hardware and no physical input devices. It emulates a dumb
framebuffer using virtual memory.)
Create a docker-compose.yml file to define how the images will interact with each
other
Start docker-compose and scale out to as many nodes as you need – or that your
machine can handle
http://www.conductor.com/nightlight/running-selenium-grid-using-docker-compose/
Steps for setup
Responsive Web design Testing
About Galen
Layout testing with GALEN
Responsive web design Testing
http://www.hangar17.in/en/responsive-webdesign
Pages should be readable on all resolutions
Text, Image alignment, controls
Color, shading, gradient consistency
What to Test
Selecting different set of devices for test
Frequent changes in requirements
Do emulators / simulators all the devices in the market
ToolsApplitools
Viewport Resize for Chrome
Galen
Challenges
Its open source
Build with Responsive Web design in Mind
Uses Selenium for web page interactions
Developed by : Ivan Subin
Galen Framework
How Galen Works
Sample Spec File
Test Report
Detailed Report
Maven – build automation tool
Maven – a build automation tool which is distributed under Apache Software Foundation. It is mainly used for java projects. It makes build consistent with other project.
Maven is used to manage the dependencies.
Maven provides pom.xml which is the core to any project.
Maven stores all project jars. Library jar are in place called repository which could be central, local or remote repository.
<repositories> <repository> <id>libraryId</id> <url>http://comanyrepositryId</url> </repository></repositories>
Project example
Command to run → mvn clean test
Git – Code Repository
Git Hub is a Collaboration platform. It is built on top of git. It allows you to keep
both local and remote copies of your project. A project which you can publish it
among your team members as they can use it and update it from there itself.
Advantages :
Multiple people when they work on the same project they can update project
details and inform other team members simultaneously.
Jenkins can help us to regularly build the project from the remote repository
this helps us to keep track of failed builds.
Setup
Jenkins is the leading open-source continuous integration tool
developed by Hudson lab. It is cross-platform and can be used on
Windows, Linux, Mac OS and Solaris environments. It fires pre-
configured actions when a particular step occurs in jobs.
Jenkins
Running Selenium tests in Jenkins allows you to run your tests every time
your software changes and deploy the software to a new environment Jenkins can schedule your tests to run at specific time. You can save the execution history and Test Reports. Jenkins supports Maven for building and testing a project in continuous
integration. Jenkins supports Docker plugin
Why – Jenkins and Selenium
Docker - > http://blog.unicsolution.com/2015/07/scale-selenium-grid-in-5-seconds-with.html
Docker Conference : https://confengine.com/selenium-conf-2015/proposal/1365/docker-selenium-getting-started
Galen : http://galenframework.com/
Extent Reporting : http://extentreports.relevantcodes.com
My Blog : http://gururajhm.blogspot.in/p/welcome.html
Selenium Git Hub : https://github.com/SeleniumHQ/selenium
Page object Model : http://martinfowler.com/bliki/PageObject.htmlhttps://code.google.com/p/selenium/wiki/PageFactory
http://seleniumhq.github.io/selenium/docs/api/java/index.html
References