SlideShare a Scribd company logo
Lets Automate!
Lets Automate your web tests using Selenium
A guide to automation using selenium
Ahmed Mubbashir Khan, http://about.me/mubbashir
@mubbashir
Agenda
Demo of sikuli-on-selenium
Automation
Automation objective
What is selenium
-Components of selenium
-Walkthrough
- S-IDE
- Driver/RC
-Grid
-Walking through the code of the demo(Maven, Java, TestNG)
Command Reference
- Locators Reference
Test automation is any use of tools to aid
testing- James Bach (http://www.satisfice.com/blog/archives/118)
OK- But its a very broad term, what are we
going to automate?
Answer: Regression Tests (Checks to be
precise)
http://www.developsense.com/blog/2009/08/testing-vs-checking/
What is Test/Check Automation?
Expecting automation to find lots of bugs when
you are automating regression testing is the
wrong objective - Dorothy Graham (STAReast 19 April, 2012)
Automation is not a magic tool. It will not find
bugs - good tests finds the bugs - Dorothy
Graham (STAReast 19 April, 2012)
What is the objective of (Regression)
Automation?
Think of your automation as a baseline test
suite to be used in conjunction with manual
testing, rather than as a replacement for it-
James Bach (http://www.satisfice.com/articles/test_automation_snake_oil.pdf (1999))
Just as there can be quality
software, there can be quality test automation-
James Bach (http://www.satisfice.com/articles/test_automation_snake_oil.pdf (1999))
What is the objective of (Regression)
Automation??
Test Automation is a software Project, Treat it
as a software project.
Test Automation is coding, why would you ask
it to be done by someone who can't code-
Adam Goucher
Automation is Software.
• Rapid feedback to developers
• Virtually unlimited iterations of test case
execution
• Support for Agile and extreme development
methodologies
• Disciplined documentation of test cases
• Customized defect reporting
• Finding defects missed by manual testing
Why Not Automate? Which are Myths? and
what about ROI?
To Automate or Not to Automate?
Hmm..
Always Remember: Agile test quadrant
Selenium (set of libraries) automates browsers.
That's it. What you do with that power is entirely
up to you. (http://seleniumhq.org/)
Selenium's History...
What is selenium?
Its Opensource (code.google.com/p/selenium/)
It runs in many browsers and operating
systems
Can be controlled by many programming
languages and testing frameworks.
Companies using selenium includes Google,
BBC, Ubuntu, Pivotal Labs, Mozlilla and Yelp
among many others.
And "Die QTP Die" http://paulhammant.
Why selenium?
QTP vs Selenium- Job Market
Why selenium??
Selenium does not own the browser, OS does.
Selenium can interact with the rendered HTML content of a
given web page, but it cannot interact with native browser
operations
● Anything which is outside web app (e.g.
upload/download dialog box)
● Anything which runs in a different runtime (e.g flash,
java applets)
● Some HTML5 features (e.g. video, audio, canvas,
webGL)
What selenium can't do?
Selenium is not a testing framework.
Selenium allows you to interact with web pages but
creating tests on top of it is the reponsibility of Test
Framework (xUnit) (https://twitter.com/#!
/AutomatedTester/status/176830982316494849)
What selenium can't do?
Download: http://code.google.
com/p/selenium/downloads/list
IDE, IDE Walkthrough
Lets do it
What else?
Driver(s)
Grid
Installation
Driver(s)
Grid:
java -jar selenium-server-standalone-*.jar -role hub
java -jar selenium-server-standalone-*.jar -port 5456 -role
node -hub http://192.168.0.92:4444/grid/register -browser
browserName=firefox,maxInstances=3 -hubHost
"192.168.0.92" -host "192.168.0.92"
gem install selenium-webdriver
[1] pry(main)> require 'selenium-webdriver'
[2] pry(main)> driver = Selenium::WebDriver.for :firefox
driver=Selenium::WebDriver.for(:remote,:url => "http://192.
168.0.94:4444/wd/hub/",:desired_capabilities => caps)
Installation
Driver(s)
from selenium import webdriver
driver = webdriver.Chrome
('/Users/mubbashir/Documents/Frameworks/selenium/chor
me_driver/chromedriver')
driver.get("http://google.com")
driver.quit()
Installation
Recording
Adding waits and assertions
Replay and Verify
Don't record and save instead record and
export
Page Objetcs
IDE- Writing Test Case
Actions/Commands (http://release.seleniumhq.org/selenium-core/1.0.1/reference.
html#actions)
Commonly used commands:
open
click/clickAndWait
verifyTitle/assertTitle
verifyTextPresent
verifyElementPresent
verifyText
verifyTable
xxAndWait
waitForXX
IDE- Command Reference
Actions/Commands (http://release.seleniumhq.org/selenium-core/1.0.1/reference.
html#actions)
To Execute these commands you need to know:
Element Locators
Element Filters
String-match Patterns
IDE- Command Reference
Actions/Commands (http://release.seleniumhq.org/selenium-core/1.0.1/reference.
html#actions)
Element Locators
● identifier=id: Select the element with the specified @id attribute. If no match is found, select the
first element whose @name attribute is id. (This is normally the default; see below.)
● id=id: Select the element with the specified @id attribute.
● name=name: Select the first element with the specified @name attribute.
○ username
○ name=username
● The name may optionally be followed by one or more element-filters, separated from the name
by whitespace. If the filterType is not specified, value is assumed.
○ name=flavour value=chocolate
● dom=javascriptExpression: Find an element by evaluating the specified string. This allows you
to traverse the HTML Document Object Model using JavaScript. Note that you must not return a
value in this string; simply make it the last expression in the block.
○ dom=document.forms['myForm'].myDropdown
○ dom=document.images[56]
○ dom=function foo() { return document.links[1]; }; foo();
IDE- Command Reference-Locators
Actions/Commands (http://release.seleniumhq.org/selenium-core/1.0.1/reference.
html#actions)
Element Locators
● xpath=xpathExpression: Locate an element using an XPath expression.
○ xpath=//img[@alt='The image alt text']
○ xpath=//table[@id='table1']//tr[4]/td[2]
○ xpath=//a[contains(@href,'#id1')]/@class
○ xpath=(//table[@class='stylee'])//th[text()='theHeaderText']/../td
○ xpath=//input[@name='name2' and @value='yes']
○ xpath=//*[text()="right"]
● link=textPattern: Select the link (anchor) element which contains text matching the specified
pattern.
○ link=The link text
● css=cssSelectorSyntax: Select the element using css selectors. Please refer to CSS2 selectors,
CSS3 selectors for more information..
○ css=a[href="#id3"]
○ css=span#firstChild + span
IDE- Command Reference-Locators
Actions/Commands (http://release.seleniumhq.org/selenium-core/1.0.1/reference.
html#actions)
String-match Patterns
● glob:pattern: Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a kind of limited
regular-expression syntax typically used in command-line shells. In a glob pattern, "*" represents
any sequence of characters, and "?" represents any single character. Glob patterns match
against the entire string.
● regexp:regexp: Match a string using a regular-expression. The full power of JavaScript regular-
expressions is available.
● regexpi:regexpi: Match a string using a case-insensitive regular-expression.
● exact:string: Match a string exactly, verbatim, without any of that fancy wildcard stuff.
If no pattern prefix is specified, Selenium assumes that it's a "glob" pattern
IDE- Command Reference- String
match patterns
Actions/Commands (http://release.seleniumhq.org/selenium-core/1.0.1/reference.
html#actions)
Commonly used commands:
assertFoo(pattern)
assertFooPresent
assertFooNotPresent
Alerts, Popups, and Multiple
Windows

More Related Content

PPT
Java Basics for selenium
PPTX
Test automation expert days
PDF
Easy automation.py
PDF
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
PDF
Codeception
PDF
Selenium Clinic Eurostar 2012 WebDriver Tutorial
PDF
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
PDF
軟體測試是在測試什麼?
Java Basics for selenium
Test automation expert days
Easy automation.py
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
Codeception
Selenium Clinic Eurostar 2012 WebDriver Tutorial
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
軟體測試是在測試什麼?

What's hot (20)

PDF
Enhance react app with patterns - part 1: higher order component
PDF
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
PPTX
Selenium Training | TestNG Framework For Selenium | Selenium Tutorial For Beg...
PDF
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
PDF
Test automation & Seleniun by oren rubin
PDF
Use React Patterns to Build Large Scalable App
PPT
Gems Of Selenium
PDF
From Good to Great: Functional and Acceptance Testing in WordPress.
PDF
Codeception introduction and use in Yii
PDF
Foundation selenium java
PDF
Lets make a better react form
PDF
Test automation - Building effective solutions
PPTX
Selenium withnet
PDF
My Test Automation Journey
PDF
Unit-testing and E2E testing in JS
PDF
Selenium interview questions and answers
PPT
Rich GUI Testing: Swing and JavaFX
PPTX
Selenium Interview Questions & Answers
PDF
How To Use Selenium Successfully
PDF
Practical Test Automation Deep Dive
Enhance react app with patterns - part 1: higher order component
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenium Training | TestNG Framework For Selenium | Selenium Tutorial For Beg...
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Test automation & Seleniun by oren rubin
Use React Patterns to Build Large Scalable App
Gems Of Selenium
From Good to Great: Functional and Acceptance Testing in WordPress.
Codeception introduction and use in Yii
Foundation selenium java
Lets make a better react form
Test automation - Building effective solutions
Selenium withnet
My Test Automation Journey
Unit-testing and E2E testing in JS
Selenium interview questions and answers
Rich GUI Testing: Swing and JavaFX
Selenium Interview Questions & Answers
How To Use Selenium Successfully
Practical Test Automation Deep Dive
Ad

Similar to Introduction to Selenium and Test Automation (20)

PDF
Automation Testing using Selenium Webdriver
PPT
Selenium
PDF
Selenium Introduction by Sandeep Sharda
PPTX
Selenium web driver
PPTX
Selenium Introduction and IDE
DOC
Selenium Automation Using Ruby
PPTX
Selenium.pptx
PPTX
Automation Testing
PDF
Selenium
PPTX
Automated Web Testing With Selenium
PPTX
Selenium
PDF
How To Use Selenium Successfully (Java Edition)
PPTX
SKILLWISE_SELENIUM
PPTX
Selenium Automation
PDF
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
PDF
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
DOCX
What is selenium
PPTX
Selenium training
PPTX
Learn SELENIUM at ASIT
PDF
How To Use Selenium Successfully (Java Edition)
Automation Testing using Selenium Webdriver
Selenium
Selenium Introduction by Sandeep Sharda
Selenium web driver
Selenium Introduction and IDE
Selenium Automation Using Ruby
Selenium.pptx
Automation Testing
Selenium
Automated Web Testing With Selenium
Selenium
How To Use Selenium Successfully (Java Edition)
SKILLWISE_SELENIUM
Selenium Automation
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
What is selenium
Selenium training
Learn SELENIUM at ASIT
How To Use Selenium Successfully (Java Edition)
Ad

Recently uploaded (20)

PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
cuic standard and advanced reporting.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Machine learning based COVID-19 study performance prediction
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Approach and Philosophy of On baking technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Programs and apps: productivity, graphics, security and other tools
Chapter 3 Spatial Domain Image Processing.pdf
Big Data Technologies - Introduction.pptx
sap open course for s4hana steps from ECC to s4
Mobile App Security Testing_ A Comprehensive Guide.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
cuic standard and advanced reporting.pdf
Electronic commerce courselecture one. Pdf
Empathic Computing: Creating Shared Understanding
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Machine learning based COVID-19 study performance prediction
The Rise and Fall of 3GPP – Time for a Sabbatical?
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
MYSQL Presentation for SQL database connectivity
Approach and Philosophy of On baking technology
Building Integrated photovoltaic BIPV_UPV.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
MIND Revenue Release Quarter 2 2025 Press Release

Introduction to Selenium and Test Automation

  • 1. Lets Automate! Lets Automate your web tests using Selenium A guide to automation using selenium Ahmed Mubbashir Khan, http://about.me/mubbashir @mubbashir
  • 2. Agenda Demo of sikuli-on-selenium Automation Automation objective What is selenium -Components of selenium -Walkthrough - S-IDE - Driver/RC -Grid -Walking through the code of the demo(Maven, Java, TestNG) Command Reference - Locators Reference
  • 3. Test automation is any use of tools to aid testing- James Bach (http://www.satisfice.com/blog/archives/118) OK- But its a very broad term, what are we going to automate? Answer: Regression Tests (Checks to be precise) http://www.developsense.com/blog/2009/08/testing-vs-checking/ What is Test/Check Automation?
  • 4. Expecting automation to find lots of bugs when you are automating regression testing is the wrong objective - Dorothy Graham (STAReast 19 April, 2012) Automation is not a magic tool. It will not find bugs - good tests finds the bugs - Dorothy Graham (STAReast 19 April, 2012) What is the objective of (Regression) Automation?
  • 5. Think of your automation as a baseline test suite to be used in conjunction with manual testing, rather than as a replacement for it- James Bach (http://www.satisfice.com/articles/test_automation_snake_oil.pdf (1999)) Just as there can be quality software, there can be quality test automation- James Bach (http://www.satisfice.com/articles/test_automation_snake_oil.pdf (1999)) What is the objective of (Regression) Automation??
  • 6. Test Automation is a software Project, Treat it as a software project. Test Automation is coding, why would you ask it to be done by someone who can't code- Adam Goucher Automation is Software.
  • 7. • Rapid feedback to developers • Virtually unlimited iterations of test case execution • Support for Agile and extreme development methodologies • Disciplined documentation of test cases • Customized defect reporting • Finding defects missed by manual testing Why Not Automate? Which are Myths? and what about ROI? To Automate or Not to Automate?
  • 9. Selenium (set of libraries) automates browsers. That's it. What you do with that power is entirely up to you. (http://seleniumhq.org/) Selenium's History... What is selenium?
  • 10. Its Opensource (code.google.com/p/selenium/) It runs in many browsers and operating systems Can be controlled by many programming languages and testing frameworks. Companies using selenium includes Google, BBC, Ubuntu, Pivotal Labs, Mozlilla and Yelp among many others. And "Die QTP Die" http://paulhammant. Why selenium?
  • 11. QTP vs Selenium- Job Market Why selenium??
  • 12. Selenium does not own the browser, OS does. Selenium can interact with the rendered HTML content of a given web page, but it cannot interact with native browser operations ● Anything which is outside web app (e.g. upload/download dialog box) ● Anything which runs in a different runtime (e.g flash, java applets) ● Some HTML5 features (e.g. video, audio, canvas, webGL) What selenium can't do?
  • 13. Selenium is not a testing framework. Selenium allows you to interact with web pages but creating tests on top of it is the reponsibility of Test Framework (xUnit) (https://twitter.com/#! /AutomatedTester/status/176830982316494849) What selenium can't do?
  • 14. Download: http://code.google. com/p/selenium/downloads/list IDE, IDE Walkthrough Lets do it What else? Driver(s) Grid Installation
  • 15. Driver(s) Grid: java -jar selenium-server-standalone-*.jar -role hub java -jar selenium-server-standalone-*.jar -port 5456 -role node -hub http://192.168.0.92:4444/grid/register -browser browserName=firefox,maxInstances=3 -hubHost "192.168.0.92" -host "192.168.0.92" gem install selenium-webdriver [1] pry(main)> require 'selenium-webdriver' [2] pry(main)> driver = Selenium::WebDriver.for :firefox driver=Selenium::WebDriver.for(:remote,:url => "http://192. 168.0.94:4444/wd/hub/",:desired_capabilities => caps) Installation
  • 16. Driver(s) from selenium import webdriver driver = webdriver.Chrome ('/Users/mubbashir/Documents/Frameworks/selenium/chor me_driver/chromedriver') driver.get("http://google.com") driver.quit() Installation
  • 17. Recording Adding waits and assertions Replay and Verify Don't record and save instead record and export Page Objetcs IDE- Writing Test Case
  • 18. Actions/Commands (http://release.seleniumhq.org/selenium-core/1.0.1/reference. html#actions) Commonly used commands: open click/clickAndWait verifyTitle/assertTitle verifyTextPresent verifyElementPresent verifyText verifyTable xxAndWait waitForXX IDE- Command Reference
  • 19. Actions/Commands (http://release.seleniumhq.org/selenium-core/1.0.1/reference. html#actions) To Execute these commands you need to know: Element Locators Element Filters String-match Patterns IDE- Command Reference
  • 20. Actions/Commands (http://release.seleniumhq.org/selenium-core/1.0.1/reference. html#actions) Element Locators ● identifier=id: Select the element with the specified @id attribute. If no match is found, select the first element whose @name attribute is id. (This is normally the default; see below.) ● id=id: Select the element with the specified @id attribute. ● name=name: Select the first element with the specified @name attribute. ○ username ○ name=username ● The name may optionally be followed by one or more element-filters, separated from the name by whitespace. If the filterType is not specified, value is assumed. ○ name=flavour value=chocolate ● dom=javascriptExpression: Find an element by evaluating the specified string. This allows you to traverse the HTML Document Object Model using JavaScript. Note that you must not return a value in this string; simply make it the last expression in the block. ○ dom=document.forms['myForm'].myDropdown ○ dom=document.images[56] ○ dom=function foo() { return document.links[1]; }; foo(); IDE- Command Reference-Locators
  • 21. Actions/Commands (http://release.seleniumhq.org/selenium-core/1.0.1/reference. html#actions) Element Locators ● xpath=xpathExpression: Locate an element using an XPath expression. ○ xpath=//img[@alt='The image alt text'] ○ xpath=//table[@id='table1']//tr[4]/td[2] ○ xpath=//a[contains(@href,'#id1')]/@class ○ xpath=(//table[@class='stylee'])//th[text()='theHeaderText']/../td ○ xpath=//input[@name='name2' and @value='yes'] ○ xpath=//*[text()="right"] ● link=textPattern: Select the link (anchor) element which contains text matching the specified pattern. ○ link=The link text ● css=cssSelectorSyntax: Select the element using css selectors. Please refer to CSS2 selectors, CSS3 selectors for more information.. ○ css=a[href="#id3"] ○ css=span#firstChild + span IDE- Command Reference-Locators
  • 22. Actions/Commands (http://release.seleniumhq.org/selenium-core/1.0.1/reference. html#actions) String-match Patterns ● glob:pattern: Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a kind of limited regular-expression syntax typically used in command-line shells. In a glob pattern, "*" represents any sequence of characters, and "?" represents any single character. Glob patterns match against the entire string. ● regexp:regexp: Match a string using a regular-expression. The full power of JavaScript regular- expressions is available. ● regexpi:regexpi: Match a string using a case-insensitive regular-expression. ● exact:string: Match a string exactly, verbatim, without any of that fancy wildcard stuff. If no pattern prefix is specified, Selenium assumes that it's a "glob" pattern IDE- Command Reference- String match patterns
  • 23. Actions/Commands (http://release.seleniumhq.org/selenium-core/1.0.1/reference. html#actions) Commonly used commands: assertFoo(pattern) assertFooPresent assertFooNotPresent Alerts, Popups, and Multiple Windows