SlideShare a Scribd company logo
Selenium 101
SELENIUM 101
automates browsers
I’M
• BertVan Hauwaert
• CEO, CFO, CTO, … of
be.coded
• Freelancer
NOTICE
This is a 101 talk!
(ANTI-)PATTERNS
ICE-CREAM CONE
Manual tests
Automated
GUI tests
Integration
tests
Unit
tests
CUPCAKE
ManualTest
Automated GUITests
Automated IntegrationTests
(API, Component)
Automated
UnitTests
Manual testers
Automated GUI
testers
Developers
TESTING PYRAMID
Automated
GUI tests
Automated API tests
Automated Integration tests
Automated Component tests
Automated Unit tests
Manual
Session
BasedTesting
Functional tests
Examples
Story tests
Prototypes
Simulations
Exploratory testing
Scenarios
Usability testing
UAT
Alpha / Beta
Unit tests
Component test
Performance & Load testing
Security testing
“ility” testing
Business facing
Technology facing
Supportingtheteam
Critiqueproduct
Automated & manual
Automated
Manual
Tools
AGILETESTING QUADRANTS
Q2
Q1 Q4
Q3
BROWSERTESTING
• Headless browser emulators
• Browser controllers
WHAT IS SELENIUM?
• Suite of tools
• Automates browsers
• Testing purposes
• Boring web-based administration tasks
TOOLS - SELENIUM IDE
• Selenium IDE
• Firefox extension
• Record and playback interactions
• Use it to
• Create quick bug reproduction scripts
• Create scripts to aid in automation-aided exploratory
testing
TOOLS - SELENIUM RC
• Selenium Remote Control
• Server
• Automatically launches and kills browsers
• Acts as a HTTP proxy for web requests from them
• Client libraries
• for your favourite computer language
• Deprecated
TOOLS - SELENIUM WEBDRIVER
• Successor to Selenium RC
• Driving a browser natively
• Accepts commands > browser
• Sent in Selenese or Client API
• Using a browser driver
TOOLS - SELENIUM GRID
• Web browsers on remote machines
• One server acts as a hub
• Tests contact hub to access browsers
• Running tests in parallel
THE IDE
THE IDE
COMMANDS
• Selenese
• 3 types
• Actions
• Accessors
• Assertions
SCRIPT SYNTAX
• Command + 2 parameters
• Not always required
• Parameters
• Locator
• Text pattern to verify
• Text pattern or variable to insert
LOCATOR
• Identifies an element
• identifier
• id
• name
• XPath
• link text
• DOM
• CSS
LOCATOR - IDENTIFIER
• identifier=loginForm
• identifier=password
• identifier=continue
• username

<html>
<body>
<form id="loginForm">
<input name="username" type="text"/>
<input name="password" type="password"/>
<input name="continue" type="submit" value="Login"/>
<input name="continue" type="button" value="Clear"/>
</form>
<a href="/pleaseSendMeSpam">Register</a>
</body>
<html>
LOCATOR - ID
• id=loginForm

<html>
<body>
<form id="loginForm">
<input name="username" type="text"/>
<input name="password" type="password"/>
<input name="continue" type="submit" value="Login"/>
<input name="continue" type="button" value="Clear"/>
</form>
<a href="/pleaseSendMeSpam">Register</a>
</body>
<html>
LOCATOR - NAME
• name=username
• name=continue
• name=continue value=Clear
• name=continue Clear
• name=continue type=button

<html>
<body>
<form id="loginForm">
<input name="username" type="text"/>
<input name="password" type="password"/>
<input name="continue" type="submit" value="Login"/>
<input name="continue" type="button" value="Clear"/>
</form>
<a href="/pleaseSendMeSpam">Register</a>
</body>
<html>
LOCATOR - XPATH
• xpath=/html/body/form[1]
• //form[1]
• xpath=//form[@id='loginForm']
• xpath=//form[input/@name='username']

<html>
<body>
<form id="loginForm">
<input name="username" type="text"/>
<input name="password" type="password"/>
<input name="continue" type="submit" value="Login"/>
<input name="continue" type="button" value="Clear"/>
</form>
<a href="/pleaseSendMeSpam">Register</a>
</body>
<html>
LOCATOR - XPATH
• //input[@name='username']
• //form[@id='loginForm']/input[1]

<html>
<body>
<form id="loginForm">
<input name="username" type="text"/>
<input name="password" type="password"/>
<input name="continue" type="submit" value="Login"/>
<input name="continue" type="button" value="Clear"/>
</form>
<a href="/pleaseSendMeSpam">Register</a>
</body>
<html>
LOCATOR - XPATH
• //input[@name='continue'][@type='button']
• //form[@id='loginForm']/input[4]

<html>
<body>
<form id="loginForm">
<input name="username" type="text"/>
<input name="password" type="password"/>
<input name="continue" type="submit" value="Login"/>
<input name="continue" type="button" value="Clear"/>
</form>
<a href="/pleaseSendMeSpam">Register</a>
</body>
<html>
LOCATOR - LINK
• link=Register

<html>
<body>
<form id="loginForm">
<input name="username" type="text"/>
<input name="password" type="password"/>
<input name="continue" type="submit" value="Login"/>
<input name="continue" type="button" value="Clear"/>
</form>
<a href="/pleaseSendMeSpam">Register</a>
</body>
<html>
LOCATOR - DOM
• dom=document.getElementById('loginForm')
• dom=document.forms['loginForm']
• dom=document.forms[0]

<html>
<body>
<form id="loginForm">
<input name="username" type="text"/>
<input name="password" type="password"/>
<input name="continue" type="submit" value="Login"/>
<input name="continue" type="button" value="Clear"/>
</form>
<a href="/pleaseSendMeSpam">Register</a>
</body>
<html>
LOCATOR - DOM
• document.forms[0].username
• document.forms[0].elements['username']
• document.forms[0].elements[0]

<html>
<body>
<form id="loginForm">
<input name="username" type="text"/>
<input name="password" type="password"/>
<input name="continue" type="submit" value="Login"/>
<input name="continue" type="button" value="Clear"/>
</form>
<a href="/pleaseSendMeSpam">Register</a>
</body>
<html>
LOCATOR - DOM
• document.forms[0].elements[3]

<html>
<body>
<form id="loginForm">
<input name="username" type="text"/>
<input name="password" type="password"/>
<input name="continue" type="submit" value="Login"/>
<input name="continue" type="button" value="Clear"/>
</form>
<a href="/pleaseSendMeSpam">Register</a>
</body>
<html>
LOCATOR - CSS
• css=form#loginForm

<html>
<body>
<form id="loginForm">
<input name="username" type="text"/>
<input name="password" type="password"/>
<input name="continue" type="submit" value="Login"/>
<input name="continue" type="button" value="Clear"/>
</form>
<a href="/pleaseSendMeSpam">Register</a>
</body>
<html>
LOCATOR - CSS
• css=input[name="username"]
• css=input.req[type="text"] 

<html>
<body>
<form id="loginForm">
<input class=“req” name="username" type="text"/>
<input class="req pwd" name="password" type="password"/>
<input name="continue" type="submit" value="Login"/>
<input name="continue" type="button" value="Clear"/>
</form>
<a href="/pleaseSendMeSpam">Register</a>
</body>
<html>
LOCATOR - CSS
• css=input.pwd
• css=#loginForm input:nth-child(2)

<html>
<body>
<form id="loginForm">
<input class="req" name="username" type="text"/>
<input class="req pwd" name="password" type="password"/>
<input name="continue" type="submit" value="Login"/>
<input name="continue" type="button" value="Clear"/>
</form>
<a href="/pleaseSendMeSpam">Register</a>
</body>
<html>
LOCATOR - CSS
• css=#loginForm input[type="button"]

<html>
<body>
<form id="loginForm">
<input name="username" type="text"/>
<input name="password" type="password"/>
<input name="continue" type="submit" value="Login"/>
<input name="continue" type="button" value="Clear"/>
</form>
<a href="/pleaseSendMeSpam">Register</a>
</body>
<html>
TEXT PATTERNS
• Globbing
• Regular expressions
• Exact
TEXT PATTERNS - GLOBBING
• glob:
• *
• Match anything inside character class
• [ ]
• Character class
• [aeiou]
• [0-9]
• [a-zA-Z0-9]
TEXT PATTERNS – REGULAR
EXPRESSIONS
• regexp: or regexpi:
PATTERN MATCH
. any single character
[ ] character class: any single character that appears inside the brackets
* quantifier: 0 or more of the preceding character (or group)
+ quantifier: 1 or more of the preceding character (or group)
? quantifier: 0 or 1 of the preceding character (or group)
{1,5} quantifier: 1 through 5 of the preceding character (or group)
|
alternation: the character/group on the left or the character/group on the
right
( ) grouping: often used with alternation and/or quantifier
TEXT PATTERNS - EXACT
• Exact:
• “Real *”
• glob:Real * will also match “Real number”
• exact:Real *
• regexp:Real *
TEST CASE
• Set of Selenium commands
• Executed one by one
TEST SUITES
• A test suite is a collection of tests
• <html>

<head> 

<title>Test Suite Function Tests - Priority 1</title> 

</head> 

<body> 

<table>

<tr><td><b>Suite Of Tests</b></td></tr>

<tr><td><a href="./ultimateQuestionOfLive.html">Ultimate question of live</a></td></tr>

<tr><td><a href="./recursion.html">Recursion</a></td></tr>

</table>

</body>

</html>
COMMONLY USED
COMMANDS
• open
• opens a page using a URL.
• click/clickAndWait
• performs a click operation, and optionally waits for a new page to load.
• waitForPageToLoad
• pauses execution until an expected new page loads. Called automatically when
clickAndWait is used.
• waitForElementPresent
• pauses execution until an expected UI element, as defined by its HTML tag, is present
on the page.
COMMONLY USED
COMMANDS
• verifyTitle/assertTitle
• verifies an expected page title.
• verifyTextPresent
• verifies expected text is somewhere on the page.
• verifyElementPresent
• verifies an expected UI element, as defined by its HTML tag, is present on the
page.
• verifyText
• verifies expected text and its corresponding HTML tag are present on the page.
ASSERTION ORVERIFICATION
• Assert
• Fail test, abort current test case
• Verify
• Fail test, continue to run the test case
TIP - BASEURL
<tr>

<td>store</td>

<td>http://domain</td>

<td>baseUrl</td>

</tr>



<! – … -->



<tr>

<td>open</td>

<td>${baseUrl}/page</td>

<td></td>

</tr>
TIP – OVERWRITE METHOD
<tr>
<td>getEval</td>
<td>window._oldFooBar = window.fooBar;
window.fooBar = function(arg1, arg2) {
window._oldFooBar(arg1, arg2);
window.fooBarData = {
arg1: arg1,
arg2: arg2
};
if (window.console){
window.console.log(window.fooBarData);
}
};</td>
<td></td>
</tr>
TIP – OVERWRITE METHOD
<tr>
<td>assertEval</td>
<td>window.fooBarData.arg1</td>
<td>baz</td>
</tr>
TIP – NO ORPHANEDTEXT
<a href=“/property/123”>
Koekoekstraat 70 - Melle
<em>235.000 EUR</em>
</a>
<a href=“/property/123”>
<span>Koekoekstraat 70 - Melle</span>
<em>235.000 EUR</em>
</a>
TIP – IDENTIFY FUNCTION
<button id="login-button">
<span>Login</span>
</button>
WAI-ARIA role landmarks
//li[@role="menuitem" and .=“About us ,”]
TIP – MAGNIUM
• Magium = Selenium + Magento
DEMO
• Answer to the Ultimate Question of Life, the
Universe, and Everything
• Recursion
Selenium 101
DOCKERTOTHE RESCUE
• https://hub.docker.com/r/selenium/
• selenium/hub
• selenium/node-chrome
• selenium/node-firefox
DOCKER-COMPOSE
hub:
image: selenium/hub
ports:
- "4444:4444"
firefox:
image: selenium/node-firefox
links:
- hub
chrome:
image: selenium/node-chrome
links:
- hub
EXAMPLE
abstract class AbstractSeleniumTestCase extends TestCase

{



protected $webDriverUrl = ‘http://127.0.0.1:4444/wd/hub';

protected $webDriver;



public function setUp()

{

$this->webDriver = RemoteWebDriver::create(
$this->webDriverUrl, DesiredCapabilities::firefox()
);

}



public function tearDown()

{

if ($this->webDriver) {

$this->webDriver->quit();


}

}
}
EXAMPLE
public function testRecursion()

{

$this->webDriver->get('http://www.google.be');

$this->webDriver->findElement(WebDriverBy::id('lst-ib'))

->sendKeys('Recursion')->submit();



$this->webDriver->wait(10, 300)

->until(

function ($webDriver) {

try {

$webDriver->findElement(WebDriverBy::cssSelector('a.spell'));

return true;

} catch (NoSuchElementException $ex) {

return false;

}

}

);



$aSpellElement = $this->webDriver->findElement(WebDriverBy::cssSelector('a.spell'));

$this->assertEquals("Recursion", $aSpellElement->getText());

$aSpellElement->click();

$this->takeScreenshot(__FUNCTION__);

}
Selenium 101
RESOURCES
• http://www.seleniumhq.org/
• https://github.com/becoded/talk-selenium-101
• https://github.com/facebook/php-webdriver
• http://magiumlib.com/
QUESTIONS ?

More Related Content

ODP
Selenium testing IDE 101
PDF
Selenium IDE and Beyond
PPT
Selenium ide material (1)
PPT
Selenium Ide Tutorials
PPTX
Selenium Open Source Tool
PPTX
Selenium IDE
PDF
Introduction to Selenium IDE
PDF
How to Use Selenium, Successfully
Selenium testing IDE 101
Selenium IDE and Beyond
Selenium ide material (1)
Selenium Ide Tutorials
Selenium Open Source Tool
Selenium IDE
Introduction to Selenium IDE
How to Use Selenium, Successfully

What's hot (19)

PPT
Selenium classes in mumbai
PPTX
Selenium tutorial
PDF
Practical Tips & Tricks for Selenium Test Automation - Dave Haeffner
PPTX
Learn Test Automation using Selenium - Lesson 1
PDF
Efficient Automated Test Creation With Selenium IDE Plugins
PDF
Selenium Best Practices with Jason Huggins
PDF
How To Use Selenium Successfully
PDF
Practical Tips & Tricks for Selenium Test Automation
PPT
Selenium By Pravin Mishra
PPTX
Selenium
PDF
Selenium IDE features
PPTX
Apex Testing Deep Dive
PPTX
Selenium ide made easy
PPT
Selenium
PPTX
Selenium WebDriver - Test automation for web applications
PDF
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
PDF
Selenium IDE
PDF
Automated Web Testing With Selenium
PDF
Getting Started with Selenium
Selenium classes in mumbai
Selenium tutorial
Practical Tips & Tricks for Selenium Test Automation - Dave Haeffner
Learn Test Automation using Selenium - Lesson 1
Efficient Automated Test Creation With Selenium IDE Plugins
Selenium Best Practices with Jason Huggins
How To Use Selenium Successfully
Practical Tips & Tricks for Selenium Test Automation
Selenium By Pravin Mishra
Selenium
Selenium IDE features
Apex Testing Deep Dive
Selenium ide made easy
Selenium
Selenium WebDriver - Test automation for web applications
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium IDE
Automated Web Testing With Selenium
Getting Started with Selenium
Ad

Similar to Selenium 101 (20)

PPTX
Selenium ppt
PPTX
6. Automation Testing tools.pptxSoftwareQulaity
PPTX
Automation Testing
PPTX
Selenium
PPTX
Selenium-corporate-training-in-mumbai
PDF
Selenium
PPTX
PPTX
Selenium
PPTX
Selenium
PPTX
Selenium
PPTX
Selenium
PPT
Selenium (1) (1)
PPTX
Automated testing with selenium prasad bapatla
PPTX
Selenium
PPT
Selenium Concepts
PPTX
Selenium using Java
 
PPT
Test automation using selenium presented by Quontra Solutions
ODP
Introduction to Selenium
DOC
Selenium course syllabus
PPTX
Selenium corporate-training-in-mumbai
Selenium ppt
6. Automation Testing tools.pptxSoftwareQulaity
Automation Testing
Selenium
Selenium-corporate-training-in-mumbai
Selenium
Selenium
Selenium
Selenium
Selenium
Selenium (1) (1)
Automated testing with selenium prasad bapatla
Selenium
Selenium Concepts
Selenium using Java
 
Test automation using selenium presented by Quontra Solutions
Introduction to Selenium
Selenium course syllabus
Selenium corporate-training-in-mumbai
Ad

Recently uploaded (20)

PDF
Empathic Computing: Creating Shared Understanding
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation theory and applications.pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
cuic standard and advanced reporting.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Spectroscopy.pptx food analysis technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Cloud computing and distributed systems.
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Empathic Computing: Creating Shared Understanding
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Encapsulation_ Review paper, used for researhc scholars
Per capita expenditure prediction using model stacking based on satellite ima...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation theory and applications.pdf
Electronic commerce courselecture one. Pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Machine learning based COVID-19 study performance prediction
cuic standard and advanced reporting.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Network Security Unit 5.pdf for BCA BBA.
sap open course for s4hana steps from ECC to s4
Diabetes mellitus diagnosis method based random forest with bat algorithm
Spectroscopy.pptx food analysis technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Cloud computing and distributed systems.
Spectral efficient network and resource selection model in 5G networks
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton

Selenium 101

  • 3. I’M • BertVan Hauwaert • CEO, CFO, CTO, … of be.coded • Freelancer
  • 4. NOTICE This is a 101 talk!
  • 6. ICE-CREAM CONE Manual tests Automated GUI tests Integration tests Unit tests
  • 7. CUPCAKE ManualTest Automated GUITests Automated IntegrationTests (API, Component) Automated UnitTests Manual testers Automated GUI testers Developers
  • 8. TESTING PYRAMID Automated GUI tests Automated API tests Automated Integration tests Automated Component tests Automated Unit tests Manual Session BasedTesting
  • 9. Functional tests Examples Story tests Prototypes Simulations Exploratory testing Scenarios Usability testing UAT Alpha / Beta Unit tests Component test Performance & Load testing Security testing “ility” testing Business facing Technology facing Supportingtheteam Critiqueproduct Automated & manual Automated Manual Tools AGILETESTING QUADRANTS Q2 Q1 Q4 Q3
  • 10. BROWSERTESTING • Headless browser emulators • Browser controllers
  • 11. WHAT IS SELENIUM? • Suite of tools • Automates browsers • Testing purposes • Boring web-based administration tasks
  • 12. TOOLS - SELENIUM IDE • Selenium IDE • Firefox extension • Record and playback interactions • Use it to • Create quick bug reproduction scripts • Create scripts to aid in automation-aided exploratory testing
  • 13. TOOLS - SELENIUM RC • Selenium Remote Control • Server • Automatically launches and kills browsers • Acts as a HTTP proxy for web requests from them • Client libraries • for your favourite computer language • Deprecated
  • 14. TOOLS - SELENIUM WEBDRIVER • Successor to Selenium RC • Driving a browser natively • Accepts commands > browser • Sent in Selenese or Client API • Using a browser driver
  • 15. TOOLS - SELENIUM GRID • Web browsers on remote machines • One server acts as a hub • Tests contact hub to access browsers • Running tests in parallel
  • 18. COMMANDS • Selenese • 3 types • Actions • Accessors • Assertions
  • 19. SCRIPT SYNTAX • Command + 2 parameters • Not always required • Parameters • Locator • Text pattern to verify • Text pattern or variable to insert
  • 20. LOCATOR • Identifies an element • identifier • id • name • XPath • link text • DOM • CSS
  • 21. LOCATOR - IDENTIFIER • identifier=loginForm • identifier=password • identifier=continue • username
 <html> <body> <form id="loginForm"> <input name="username" type="text"/> <input name="password" type="password"/> <input name="continue" type="submit" value="Login"/> <input name="continue" type="button" value="Clear"/> </form> <a href="/pleaseSendMeSpam">Register</a> </body> <html>
  • 22. LOCATOR - ID • id=loginForm
 <html> <body> <form id="loginForm"> <input name="username" type="text"/> <input name="password" type="password"/> <input name="continue" type="submit" value="Login"/> <input name="continue" type="button" value="Clear"/> </form> <a href="/pleaseSendMeSpam">Register</a> </body> <html>
  • 23. LOCATOR - NAME • name=username • name=continue • name=continue value=Clear • name=continue Clear • name=continue type=button
 <html> <body> <form id="loginForm"> <input name="username" type="text"/> <input name="password" type="password"/> <input name="continue" type="submit" value="Login"/> <input name="continue" type="button" value="Clear"/> </form> <a href="/pleaseSendMeSpam">Register</a> </body> <html>
  • 24. LOCATOR - XPATH • xpath=/html/body/form[1] • //form[1] • xpath=//form[@id='loginForm'] • xpath=//form[input/@name='username']
 <html> <body> <form id="loginForm"> <input name="username" type="text"/> <input name="password" type="password"/> <input name="continue" type="submit" value="Login"/> <input name="continue" type="button" value="Clear"/> </form> <a href="/pleaseSendMeSpam">Register</a> </body> <html>
  • 25. LOCATOR - XPATH • //input[@name='username'] • //form[@id='loginForm']/input[1]
 <html> <body> <form id="loginForm"> <input name="username" type="text"/> <input name="password" type="password"/> <input name="continue" type="submit" value="Login"/> <input name="continue" type="button" value="Clear"/> </form> <a href="/pleaseSendMeSpam">Register</a> </body> <html>
  • 26. LOCATOR - XPATH • //input[@name='continue'][@type='button'] • //form[@id='loginForm']/input[4]
 <html> <body> <form id="loginForm"> <input name="username" type="text"/> <input name="password" type="password"/> <input name="continue" type="submit" value="Login"/> <input name="continue" type="button" value="Clear"/> </form> <a href="/pleaseSendMeSpam">Register</a> </body> <html>
  • 27. LOCATOR - LINK • link=Register
 <html> <body> <form id="loginForm"> <input name="username" type="text"/> <input name="password" type="password"/> <input name="continue" type="submit" value="Login"/> <input name="continue" type="button" value="Clear"/> </form> <a href="/pleaseSendMeSpam">Register</a> </body> <html>
  • 28. LOCATOR - DOM • dom=document.getElementById('loginForm') • dom=document.forms['loginForm'] • dom=document.forms[0]
 <html> <body> <form id="loginForm"> <input name="username" type="text"/> <input name="password" type="password"/> <input name="continue" type="submit" value="Login"/> <input name="continue" type="button" value="Clear"/> </form> <a href="/pleaseSendMeSpam">Register</a> </body> <html>
  • 29. LOCATOR - DOM • document.forms[0].username • document.forms[0].elements['username'] • document.forms[0].elements[0]
 <html> <body> <form id="loginForm"> <input name="username" type="text"/> <input name="password" type="password"/> <input name="continue" type="submit" value="Login"/> <input name="continue" type="button" value="Clear"/> </form> <a href="/pleaseSendMeSpam">Register</a> </body> <html>
  • 30. LOCATOR - DOM • document.forms[0].elements[3]
 <html> <body> <form id="loginForm"> <input name="username" type="text"/> <input name="password" type="password"/> <input name="continue" type="submit" value="Login"/> <input name="continue" type="button" value="Clear"/> </form> <a href="/pleaseSendMeSpam">Register</a> </body> <html>
  • 31. LOCATOR - CSS • css=form#loginForm
 <html> <body> <form id="loginForm"> <input name="username" type="text"/> <input name="password" type="password"/> <input name="continue" type="submit" value="Login"/> <input name="continue" type="button" value="Clear"/> </form> <a href="/pleaseSendMeSpam">Register</a> </body> <html>
  • 32. LOCATOR - CSS • css=input[name="username"] • css=input.req[type="text"] 
 <html> <body> <form id="loginForm"> <input class=“req” name="username" type="text"/> <input class="req pwd" name="password" type="password"/> <input name="continue" type="submit" value="Login"/> <input name="continue" type="button" value="Clear"/> </form> <a href="/pleaseSendMeSpam">Register</a> </body> <html>
  • 33. LOCATOR - CSS • css=input.pwd • css=#loginForm input:nth-child(2)
 <html> <body> <form id="loginForm"> <input class="req" name="username" type="text"/> <input class="req pwd" name="password" type="password"/> <input name="continue" type="submit" value="Login"/> <input name="continue" type="button" value="Clear"/> </form> <a href="/pleaseSendMeSpam">Register</a> </body> <html>
  • 34. LOCATOR - CSS • css=#loginForm input[type="button"]
 <html> <body> <form id="loginForm"> <input name="username" type="text"/> <input name="password" type="password"/> <input name="continue" type="submit" value="Login"/> <input name="continue" type="button" value="Clear"/> </form> <a href="/pleaseSendMeSpam">Register</a> </body> <html>
  • 35. TEXT PATTERNS • Globbing • Regular expressions • Exact
  • 36. TEXT PATTERNS - GLOBBING • glob: • * • Match anything inside character class • [ ] • Character class • [aeiou] • [0-9] • [a-zA-Z0-9]
  • 37. TEXT PATTERNS – REGULAR EXPRESSIONS • regexp: or regexpi: PATTERN MATCH . any single character [ ] character class: any single character that appears inside the brackets * quantifier: 0 or more of the preceding character (or group) + quantifier: 1 or more of the preceding character (or group) ? quantifier: 0 or 1 of the preceding character (or group) {1,5} quantifier: 1 through 5 of the preceding character (or group) | alternation: the character/group on the left or the character/group on the right ( ) grouping: often used with alternation and/or quantifier
  • 38. TEXT PATTERNS - EXACT • Exact: • “Real *” • glob:Real * will also match “Real number” • exact:Real * • regexp:Real *
  • 39. TEST CASE • Set of Selenium commands • Executed one by one
  • 40. TEST SUITES • A test suite is a collection of tests • <html>
 <head> 
 <title>Test Suite Function Tests - Priority 1</title> 
 </head> 
 <body> 
 <table>
 <tr><td><b>Suite Of Tests</b></td></tr>
 <tr><td><a href="./ultimateQuestionOfLive.html">Ultimate question of live</a></td></tr>
 <tr><td><a href="./recursion.html">Recursion</a></td></tr>
 </table>
 </body>
 </html>
  • 41. COMMONLY USED COMMANDS • open • opens a page using a URL. • click/clickAndWait • performs a click operation, and optionally waits for a new page to load. • waitForPageToLoad • pauses execution until an expected new page loads. Called automatically when clickAndWait is used. • waitForElementPresent • pauses execution until an expected UI element, as defined by its HTML tag, is present on the page.
  • 42. COMMONLY USED COMMANDS • verifyTitle/assertTitle • verifies an expected page title. • verifyTextPresent • verifies expected text is somewhere on the page. • verifyElementPresent • verifies an expected UI element, as defined by its HTML tag, is present on the page. • verifyText • verifies expected text and its corresponding HTML tag are present on the page.
  • 43. ASSERTION ORVERIFICATION • Assert • Fail test, abort current test case • Verify • Fail test, continue to run the test case
  • 44. TIP - BASEURL <tr>
 <td>store</td>
 <td>http://domain</td>
 <td>baseUrl</td>
 </tr>
 
 <! – … -->
 
 <tr>
 <td>open</td>
 <td>${baseUrl}/page</td>
 <td></td>
 </tr>
  • 45. TIP – OVERWRITE METHOD <tr> <td>getEval</td> <td>window._oldFooBar = window.fooBar; window.fooBar = function(arg1, arg2) { window._oldFooBar(arg1, arg2); window.fooBarData = { arg1: arg1, arg2: arg2 }; if (window.console){ window.console.log(window.fooBarData); } };</td> <td></td> </tr>
  • 46. TIP – OVERWRITE METHOD <tr> <td>assertEval</td> <td>window.fooBarData.arg1</td> <td>baz</td> </tr>
  • 47. TIP – NO ORPHANEDTEXT <a href=“/property/123”> Koekoekstraat 70 - Melle <em>235.000 EUR</em> </a> <a href=“/property/123”> <span>Koekoekstraat 70 - Melle</span> <em>235.000 EUR</em> </a>
  • 48. TIP – IDENTIFY FUNCTION <button id="login-button"> <span>Login</span> </button> WAI-ARIA role landmarks //li[@role="menuitem" and .=“About us ,”]
  • 49. TIP – MAGNIUM • Magium = Selenium + Magento
  • 50. DEMO • Answer to the Ultimate Question of Life, the Universe, and Everything • Recursion
  • 52. DOCKERTOTHE RESCUE • https://hub.docker.com/r/selenium/ • selenium/hub • selenium/node-chrome • selenium/node-firefox
  • 53. DOCKER-COMPOSE hub: image: selenium/hub ports: - "4444:4444" firefox: image: selenium/node-firefox links: - hub chrome: image: selenium/node-chrome links: - hub
  • 54. EXAMPLE abstract class AbstractSeleniumTestCase extends TestCase
 {
 
 protected $webDriverUrl = ‘http://127.0.0.1:4444/wd/hub';
 protected $webDriver;
 
 public function setUp()
 {
 $this->webDriver = RemoteWebDriver::create( $this->webDriverUrl, DesiredCapabilities::firefox() );
 }
 
 public function tearDown()
 {
 if ($this->webDriver) {
 $this->webDriver->quit(); 
 }
 } }
  • 55. EXAMPLE public function testRecursion()
 {
 $this->webDriver->get('http://www.google.be');
 $this->webDriver->findElement(WebDriverBy::id('lst-ib'))
 ->sendKeys('Recursion')->submit();
 
 $this->webDriver->wait(10, 300)
 ->until(
 function ($webDriver) {
 try {
 $webDriver->findElement(WebDriverBy::cssSelector('a.spell'));
 return true;
 } catch (NoSuchElementException $ex) {
 return false;
 }
 }
 );
 
 $aSpellElement = $this->webDriver->findElement(WebDriverBy::cssSelector('a.spell'));
 $this->assertEquals("Recursion", $aSpellElement->getText());
 $aSpellElement->click();
 $this->takeScreenshot(__FUNCTION__);
 }
  • 57. RESOURCES • http://www.seleniumhq.org/ • https://github.com/becoded/talk-selenium-101 • https://github.com/facebook/php-webdriver • http://magiumlib.com/