SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
Selenium
An Introduction
Selenium
❖ What is it?
❖ What is it good for?
❖ How do I get started?
❖ What are the gotchas?
Selenium?
❖ AKA Webdriver
❖ Web automation/testing framework
❖ Tests run on real browsers
wd.get("http://www.metafilter.com/")
wd.find_element_by_link_text("FAQ").click()
Yesss Master...
Pros
❖ Realistic test conditions
❖ Cross-browser testing
❖ Popular & mature tech
Cons
❖ Slow
❖ Changing HTML may break tests
Uses
❖ Acceptance Testing
❖ Continuous Integration
❖ Monitoring
❖ TDD? Maybe?
Python example
from selenium.webdriver.firefox.webdriver import WebDriver
wd = WebDriver()
wd.implicitly_wait(60)
wd.get("http://www.metafilter.com/")
wd.find_element_by_link_text("FAQ").click()
assert "How do I sign up for a MetaFilter account?"
in wd.find_element_by_tag_name("html").text
PHP!
require_once 'php-webdriver';
$wd = new WebDriver();
$session = $wd->session();
$session->open("http://www.metafilter.com/");
$session->element("link text", "FAQ")->click();
$session->close();
assert(strpos(
$session->element("tag name", "html")->text(),
"How do I sign up for a MetaFilter account?"));
Java!
import org.openqa.selenium.*;
import static java.util.concurrent.TimeUnit.*;
FirefoxDriver wd = new FirefoxDriver();
wd.manage().timeouts().implicitlyWait(60, SECONDS);
wd.get("http://www.metafilter.com/");
wd.findElement(By.linkText("FAQ")).click();
assert wd.findElement(By.tagName("html")).getText()
.contains("How do I sign up for a MetaFilter account?")
wd.quit();
Getting started, option A
❖ Get Selenium server from seleniumhq.org
❖ Download language binding of your choice
❖ Write some code & play it back
Getting started, option B
➔ Get Selenium Builder from sebuilder.com
➔ Record your actions as tests
➔ Play back locally, or via server
➔ Export to code or JSON
➔ Run JSON via interpreters
Gotcha 1: Visibility
❖ Selenium respects display: none
❖ You can’t interact with something invisible
❖ Even if it’s in the HTML
Gotcha 2: Timing
❖ Page needs to load first
❖ Some Javascript has to execute too?
❖ Page changes dynamically?
Gotcha 2: Timing
❖ Wait for page elements
❖ Implicitly or explicitly
❖ Don’t use pause!
Gotcha 2: Timing
from selenium.webdriver.firefox.webdriver import WebDriver
wd = WebDriver()
wd.implicitly_wait(60)
wd.get("http://www.metafilter.com/")
wd.find_element_by_link_text("FAQ").click()
assert "How do I sign up for a MetaFilter account?"
in wd.find_element_by_tag_name("html").text
Gotcha 3: Locators
from selenium.webdriver.firefox.webdriver import WebDriver
wd = WebDriver()
wd.implicitly_wait(60)
wd.get("http://www.metafilter.com/")
wd.find_element_by_link_text("FAQ").click()
assert "How do I sign up for a MetaFilter account?"
in wd.find_element_by_tag_name("html").text
Gotcha 3: Locators
❖ Locators identify UI elements
❖ HTML changes can break locators
Gotcha 3: Locators
❖ Use simple, clean, robust locators
❖ Depends on your approach
❖ Text vs ID vs CSS
❖ Careful XPATH for the tough cases
Good & bad locators
id: home_link
id: 12094b
css: span.green
css: #rightbar > .menu > li:nth-of-type(3) > h5
css: .logout
xpath: //*[@id='menu']//input[3]
xpath: //header/div/div[1]/div[1]/a/h1/span[2]
Good & bad locators
id: home_link
id: 12094b
css: span.green
css: #rightbar > .menu > li:nth-of-type(3) > h5
css: .logout
xpath: //*[@id='menu']//input[3]
xpath: //header/div/div[1]/div[1]/a/h1/span[2]
Resources
❖ Selenium HQ
❖ A CI solution with Builder, Travis & Sauce
❖ Obligatory self-promotion!
Thank you! Questions?
@zarkonnen_com

Contenu connexe

Tendances

Introduction To ASP.Net MVC
Introduction To ASP.Net MVCIntroduction To ASP.Net MVC
Introduction To ASP.Net MVC
Joe Wilson
 
jQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web PerformancejQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web Performance
dmethvin
 

Tendances (20)

One step in the future: CSS variables
One step in the future: CSS variablesOne step in the future: CSS variables
One step in the future: CSS variables
 
Introduction à AngularJS
Introduction à AngularJSIntroduction à AngularJS
Introduction à AngularJS
 
Introduction To ASP.Net MVC
Introduction To ASP.Net MVCIntroduction To ASP.Net MVC
Introduction To ASP.Net MVC
 
Webdriver cheatsheets summary
Webdriver cheatsheets summaryWebdriver cheatsheets summary
Webdriver cheatsheets summary
 
Real World Selenium Testing
Real World Selenium TestingReal World Selenium Testing
Real World Selenium Testing
 
jQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web PerformancejQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web Performance
 
Our application got popular and now it breaks
Our application got popular and now it breaksOur application got popular and now it breaks
Our application got popular and now it breaks
 
jQuery Conference Toronto
jQuery Conference TorontojQuery Conference Toronto
jQuery Conference Toronto
 
The Future of CSS with Web Components
The Future of CSS with Web ComponentsThe Future of CSS with Web Components
The Future of CSS with Web Components
 
Automate testing with behat, selenium, phantom js and nightwatch.js (5)
Automate testing with behat, selenium, phantom js and nightwatch.js (5)Automate testing with behat, selenium, phantom js and nightwatch.js (5)
Automate testing with behat, selenium, phantom js and nightwatch.js (5)
 
Getting By Without "QA"
Getting By Without "QA"Getting By Without "QA"
Getting By Without "QA"
 
Don't Over-React - just use Vue!
Don't Over-React - just use Vue!Don't Over-React - just use Vue!
Don't Over-React - just use Vue!
 
jQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksjQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & Tricks
 
Test your Javascript! v1.1
Test your Javascript! v1.1Test your Javascript! v1.1
Test your Javascript! v1.1
 
AngularJS at PyVo
AngularJS at PyVoAngularJS at PyVo
AngularJS at PyVo
 
jQuery Conference Chicago - September 2014
jQuery Conference Chicago - September 2014jQuery Conference Chicago - September 2014
jQuery Conference Chicago - September 2014
 
The Art of Angular in 2016 - Devoxx France 2016
The Art of Angular in 2016 - Devoxx France 2016The Art of Angular in 2016 - Devoxx France 2016
The Art of Angular in 2016 - Devoxx France 2016
 
Rapid Testing, Rapid Development
Rapid Testing, Rapid DevelopmentRapid Testing, Rapid Development
Rapid Testing, Rapid Development
 
Getting up and running with selenium for automated Code palousa
Getting up and running with selenium for automated  Code palousaGetting up and running with selenium for automated  Code palousa
Getting up and running with selenium for automated Code palousa
 
DOSUG Wicket 101
DOSUG Wicket 101DOSUG Wicket 101
DOSUG Wicket 101
 

En vedette

Introducing Selenium Builder – the Future of Test Development
Introducing Selenium Builder – the Future of Test DevelopmentIntroducing Selenium Builder – the Future of Test Development
Introducing Selenium Builder – the Future of Test Development
seleniumconf
 
Self-Generating Test Artifacts for Selenium/WebDriver
Self-Generating Test Artifacts for Selenium/WebDriverSelf-Generating Test Artifacts for Selenium/WebDriver
Self-Generating Test Artifacts for Selenium/WebDriver
seleniumconf
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
Prasad Sawant
 
Java Collections Framework
Java  Collections  FrameworkJava  Collections  Framework
Java Collections Framework
guestd8c458
 

En vedette (15)

Selenium Builder
Selenium BuilderSelenium Builder
Selenium Builder
 
Introducing Selenium Builder – the Future of Test Development
Introducing Selenium Builder – the Future of Test DevelopmentIntroducing Selenium Builder – the Future of Test Development
Introducing Selenium Builder – the Future of Test Development
 
Selenium Webdriver - jOpenSpace 2015
Selenium Webdriver - jOpenSpace 2015Selenium Webdriver - jOpenSpace 2015
Selenium Webdriver - jOpenSpace 2015
 
Self-Generating Test Artifacts for Selenium/WebDriver
Self-Generating Test Artifacts for Selenium/WebDriverSelf-Generating Test Artifacts for Selenium/WebDriver
Self-Generating Test Artifacts for Selenium/WebDriver
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Understanding Selenium/RC, Webdriver Architecture and developing the page obj...
Understanding Selenium/RC, Webdriver Architecture and developing the page obj...Understanding Selenium/RC, Webdriver Architecture and developing the page obj...
Understanding Selenium/RC, Webdriver Architecture and developing the page obj...
 
Selenium WebDriver - Test automation for web applications
Selenium WebDriver - Test automation for web applicationsSelenium WebDriver - Test automation for web applications
Selenium WebDriver - Test automation for web applications
 
Java Collections Framework
Java  Collections  FrameworkJava  Collections  Framework
Java Collections Framework
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
 
Exception handling
Exception handlingException handling
Exception handling
 
Introduction to Selenium Web Driver
Introduction to Selenium Web DriverIntroduction to Selenium Web Driver
Introduction to Selenium Web Driver
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Manual testing interview question by INFOTECH
Manual testing interview question by INFOTECHManual testing interview question by INFOTECH
Manual testing interview question by INFOTECH
 

Similaire à Selenium intro

Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
drewz lin
 
Automation with Selenium Presented by Quontra Solutions
Automation with Selenium Presented by Quontra SolutionsAutomation with Selenium Presented by Quontra Solutions
Automation with Selenium Presented by Quontra Solutions
Quontra Solutions
 
Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
Morgan Cheng
 
Top 15 Selenium WebDriver Interview Questions and Answers.pptx
Top 15 Selenium WebDriver Interview Questions and Answers.pptxTop 15 Selenium WebDriver Interview Questions and Answers.pptx
Top 15 Selenium WebDriver Interview Questions and Answers.pptx
AnanthReddy38
 

Similaire à Selenium intro (20)

Workshop: Building Vaadin add-ons
Workshop: Building Vaadin add-onsWorkshop: Building Vaadin add-ons
Workshop: Building Vaadin add-ons
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriver
 
DirectToWeb 2.0
DirectToWeb 2.0DirectToWeb 2.0
DirectToWeb 2.0
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
 
IE8 Dev Overview_pp2003
IE8 Dev Overview_pp2003IE8 Dev Overview_pp2003
IE8 Dev Overview_pp2003
 
Web driver training
Web driver trainingWeb driver training
Web driver training
 
Continuous integration using thucydides(bdd) with selenium
Continuous integration using thucydides(bdd) with  seleniumContinuous integration using thucydides(bdd) with  selenium
Continuous integration using thucydides(bdd) with selenium
 
Automation with Selenium Presented by Quontra Solutions
Automation with Selenium Presented by Quontra SolutionsAutomation with Selenium Presented by Quontra Solutions
Automation with Selenium Presented by Quontra Solutions
 
14. html 5 security considerations
14. html 5 security considerations14. html 5 security considerations
14. html 5 security considerations
 
Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
 
Webdriver.io
Webdriver.io Webdriver.io
Webdriver.io
 
Java. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax ApplicationsJava. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax Applications
 
Continuous integration using thucydides(bdd) with selenium
Continuous integration using thucydides(bdd) with seleniumContinuous integration using thucydides(bdd) with selenium
Continuous integration using thucydides(bdd) with selenium
 
Google Web Toolkit
Google Web ToolkitGoogle Web Toolkit
Google Web Toolkit
 
Escape from the automation hell
Escape from the automation hellEscape from the automation hell
Escape from the automation hell
 
Top 15 Selenium WebDriver Interview Questions and Answers.pptx
Top 15 Selenium WebDriver Interview Questions and Answers.pptxTop 15 Selenium WebDriver Interview Questions and Answers.pptx
Top 15 Selenium WebDriver Interview Questions and Answers.pptx
 
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web ToolkitJava Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
 
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
 

Dernier

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Dernier (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 

Selenium intro

  • 2. Selenium ❖ What is it? ❖ What is it good for? ❖ How do I get started? ❖ What are the gotchas?
  • 3. Selenium? ❖ AKA Webdriver ❖ Web automation/testing framework ❖ Tests run on real browsers
  • 5. Pros ❖ Realistic test conditions ❖ Cross-browser testing ❖ Popular & mature tech
  • 6. Cons ❖ Slow ❖ Changing HTML may break tests
  • 7. Uses ❖ Acceptance Testing ❖ Continuous Integration ❖ Monitoring ❖ TDD? Maybe?
  • 8. Python example from selenium.webdriver.firefox.webdriver import WebDriver wd = WebDriver() wd.implicitly_wait(60) wd.get("http://www.metafilter.com/") wd.find_element_by_link_text("FAQ").click() assert "How do I sign up for a MetaFilter account?" in wd.find_element_by_tag_name("html").text
  • 9. PHP! require_once 'php-webdriver'; $wd = new WebDriver(); $session = $wd->session(); $session->open("http://www.metafilter.com/"); $session->element("link text", "FAQ")->click(); $session->close(); assert(strpos( $session->element("tag name", "html")->text(), "How do I sign up for a MetaFilter account?"));
  • 10. Java! import org.openqa.selenium.*; import static java.util.concurrent.TimeUnit.*; FirefoxDriver wd = new FirefoxDriver(); wd.manage().timeouts().implicitlyWait(60, SECONDS); wd.get("http://www.metafilter.com/"); wd.findElement(By.linkText("FAQ")).click(); assert wd.findElement(By.tagName("html")).getText() .contains("How do I sign up for a MetaFilter account?") wd.quit();
  • 11. Getting started, option A ❖ Get Selenium server from seleniumhq.org ❖ Download language binding of your choice ❖ Write some code & play it back
  • 12. Getting started, option B ➔ Get Selenium Builder from sebuilder.com ➔ Record your actions as tests ➔ Play back locally, or via server ➔ Export to code or JSON ➔ Run JSON via interpreters
  • 13.
  • 14. Gotcha 1: Visibility ❖ Selenium respects display: none ❖ You can’t interact with something invisible ❖ Even if it’s in the HTML
  • 15. Gotcha 2: Timing ❖ Page needs to load first ❖ Some Javascript has to execute too? ❖ Page changes dynamically?
  • 16. Gotcha 2: Timing ❖ Wait for page elements ❖ Implicitly or explicitly ❖ Don’t use pause!
  • 17. Gotcha 2: Timing from selenium.webdriver.firefox.webdriver import WebDriver wd = WebDriver() wd.implicitly_wait(60) wd.get("http://www.metafilter.com/") wd.find_element_by_link_text("FAQ").click() assert "How do I sign up for a MetaFilter account?" in wd.find_element_by_tag_name("html").text
  • 18. Gotcha 3: Locators from selenium.webdriver.firefox.webdriver import WebDriver wd = WebDriver() wd.implicitly_wait(60) wd.get("http://www.metafilter.com/") wd.find_element_by_link_text("FAQ").click() assert "How do I sign up for a MetaFilter account?" in wd.find_element_by_tag_name("html").text
  • 19. Gotcha 3: Locators ❖ Locators identify UI elements ❖ HTML changes can break locators
  • 20. Gotcha 3: Locators ❖ Use simple, clean, robust locators ❖ Depends on your approach ❖ Text vs ID vs CSS ❖ Careful XPATH for the tough cases
  • 21. Good & bad locators id: home_link id: 12094b css: span.green css: #rightbar > .menu > li:nth-of-type(3) > h5 css: .logout xpath: //*[@id='menu']//input[3] xpath: //header/div/div[1]/div[1]/a/h1/span[2]
  • 22. Good & bad locators id: home_link id: 12094b css: span.green css: #rightbar > .menu > li:nth-of-type(3) > h5 css: .logout xpath: //*[@id='menu']//input[3] xpath: //header/div/div[1]/div[1]/a/h1/span[2]
  • 23. Resources ❖ Selenium HQ ❖ A CI solution with Builder, Travis & Sauce ❖ Obligatory self-promotion!