SlideShare a Scribd company logo
1 of 23
Download to read offline
Michael Salvucci
January 4, 2011
Selenium RC:
 Introduction
What is Selenium RC?
• It is a program that allows test automation
• It simulates a user navigating through pages
  and then verifies that content against
  expectations
• It alerts the user to discrepancies via console or
  email
• Its Selenese language allows phpunit to connect
  to a selenium server
• The RC stands for Remote Control
How does it work?
• First, launch Selenium server:
   java –jar selenium-server.jar

• Second, run a Selenese script:
   phpunit mytest.php
Where to get it?
• Selenium RC:
  http://seleniumhq.org/download/

• PHP Unit:
  http://www.phpunit.de/manual/current/en/installation.html
What does the script look like? (1 of 2)
<?php

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class Example extends PHPUnit_Extensions_SeleniumTestCase
{

 protected function setUp()
 {
   $this->setBrowser("*chrome");
   $this->setBrowserUrl("http://www.nationalguard.com");
 }
                                                           continued…
What does the script look like? (2 of 2)

 public function testMyTestCase()
 {
   $this->open("/");
   sleep(5);
   $this->verifyTitle(“The National Guard");

     // put the rest of your tests here

 }
}
?>
Selenium RC:
Common Tests
Now that I’ve got it… What can I do with it?
• Open up a page:
   $this->open("/products");

• Click on a link:
   $this->click(“link=Log In”);

• Verify a title:
   $this->verifyTitle(“The National Guard”);

• Fill-out a form:
   $this->type(“signin_username”, “joe@example.com”);

   $this->type(“signin_password”, “123456”);

   $this->select(“gender”, “male”);

   $this->click(“//a[@onclick=”$(this).parents(‘form’).eq(0).submit(); return false;”]”);
Wait a minute… What the heck is $this-
 >click(“//a[@onclick=”$(this).parents(‘form’).e
 q(0).submit(); return false;”]”); ?

• It’s an XPath
   XPath is a language that describes how to locate specific elements in a document

• How do I find the XPath for something?
   The easiest way is via a Firefox plug-in called XPather. Xpather extracts XPaths
     while browsing or inspecting HTML/XML/*ML documents.

   Then, when viewing a webpage, highlight the element you want, right-click for the
     submenu, then left-click on “Show in XPather”.

• XPather is available at:
   http://xpath.alephzarro.com
XPather
What else can I do?
• Verify text appears on a page:
   $this->verifyText(“//html/body/div[@id=‘wrapper’]/div[@id=‘content’]/h2”, “Thank
     you Iostudio Tester”);

• Verify an element is present:
   $this->verifyElementPresent(“//html/body[@id=‘profile’]/div[@id=‘wrap’]/div”);

• Verify a URL:
   $this->verifyLocation(“http://www.nationalguard.com/chat”);

• Switch over to a pop-up window so you can examine it:
   $windowName = $this->getAllWindowNames();

   $this->waitForPopUp($windowName[1], “45000”);

   $this->selectWindow($windowName[1]);
Locating Elements
• “For many Selenium commands, a target is required. This target identifies
  an element in the content of the web application, and consists of the location
  strategy followed by the location in the format locatorType=location.” I’ve
  shown you the XPath way. Here’s some other examples:

• Locating by identifier:
    verifyElementPresent(“identifier=loginForm”);

• Locating by DOM:
    verifyElementPresent(“dom=document.getElementById(‘loginForm”);

• Locating by CSS selector:
    verifyElementPresent(“css=form#loginForm”);

• Refer to: http://seleniumhq.org/docs/04_selenese_commands-html for more
  information.
Selenium RC:
  Caveats
Caveats - verifyText() vs. verifyTextPresent()
• Use verifyText() instead of verifyTextPresent() because the latter does not
  work properly
• verifyTextPresent() is also weak because it doesn’t pinpoint what you want
  to look at exactly (eg. $this->verifyTextPresent(“Frequently Asked Questions”); )
• Proper usage (N.B. This should all be on one line):
    $this-
      >verifyText(“//html/body/div[@id='wrapper']/div[@id='
      content_wrp']/div[@id='sidebar']/div[@id='side_tab_s
      tack']/div[@id='tab_content_container']/div[@id='flag
      _content']/div/div[@id='newWidget_flag_1']”,
      “Frequently Asked Questions”);
Caveats - XPather
     • XPather reports elements with a single leading slash. However, Selenium
       RC expects to see two leading slashes for XPaths.




$this->verifyElement(“//html/body/div[@id=‘wrapper’]/div[@id=‘content_wrp’]/div[@id=‘sidebar’]/div”);
Caveats - False Positives
• Selenium RC test alerts can result in false positives
Caveats - Pop-up Windows
• A problem with grabbing a pop-up window is that the window’s name is
  dynamic, and you have to know the window’s name in order to select it.

• The pop-up could be named “selenium_blank45375”. The next time, it
  could be named “selenium_blank41821”, so we have to use the
  getAllWindowNames() function to get the name of the pop-up we need.

  $this->click("link=Take the tour.");
  $windowName = $this->getAllWindowNames();
  $this->waitForPopUp($windowName[1], "45000");
  $this->selectWindow($windowName[1]);
  sleep(7);
  $this->verifyTitle("Army National Guard Virtual Career Fair");
Selenium RC:
Hudson Integration
Hudson Integration
• With Hudson, you can automate Selenium (eg. run hourly tests) and
  receive email alerts when problem arise.
• You can get Hudson here:
    http://hudson-ci.org
Selenium RC:
 References
References
• http://seleniumhq.org/download/
• http://seleniumhq.org/docs/index.html
• http://seleniumhq.org/docs/04_selenese_commands.html
• http://release.seleniumhq.org/selenium-remote-
  control/0.9.2/doc/php/Selenium/Testing_Selenium.html
• PHP Unit: http://www.phpunit.de/manual/current/en/installation.html
• XPather (A Firefox Plugin for generating XPaths):
  http://xpath.alephzarro.com/
• Hudson: http://hudson-ci.org
Selenium rc presentation_20110104

More Related Content

What's hot

Creating fast, dynamic ACLs in Zend Framework
Creating fast, dynamic ACLs in Zend FrameworkCreating fast, dynamic ACLs in Zend Framework
Creating fast, dynamic ACLs in Zend FrameworkWim Godden
 
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)Wim Godden
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09Michelangelo van Dam
 
Love and Loss: A Symfony Security Play
Love and Loss: A Symfony Security PlayLove and Loss: A Symfony Security Play
Love and Loss: A Symfony Security PlayKris Wallsmith
 
WordPress Third Party Authentication
WordPress Third Party AuthenticationWordPress Third Party Authentication
WordPress Third Party AuthenticationAaron Brazell
 
jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)Addy Osmani
 
Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and RubyYnon Perek
 
Guard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityGuard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityRyan Weaver
 
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django applicationDjangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django applicationMasashi Shibata
 
Let's talk testing with Selenium
Let's talk testing with SeleniumLet's talk testing with Selenium
Let's talk testing with Seleniumanishanarang
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreRyan Weaver
 
Intro to SQL Injection
Intro to SQL InjectionIntro to SQL Injection
Intro to SQL Injectionhon1nbo
 
Overlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh MyOverlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh MySteve McMahon
 

What's hot (20)

Kyiv.py #17 Flask talk
Kyiv.py #17 Flask talkKyiv.py #17 Flask talk
Kyiv.py #17 Flask talk
 
Creating fast, dynamic ACLs in Zend Framework
Creating fast, dynamic ACLs in Zend FrameworkCreating fast, dynamic ACLs in Zend Framework
Creating fast, dynamic ACLs in Zend Framework
 
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
 
Love and Loss: A Symfony Security Play
Love and Loss: A Symfony Security PlayLove and Loss: A Symfony Security Play
Love and Loss: A Symfony Security Play
 
WordPress Third Party Authentication
WordPress Third Party AuthenticationWordPress Third Party Authentication
WordPress Third Party Authentication
 
jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)
 
Codegnitorppt
CodegnitorpptCodegnitorppt
Codegnitorppt
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and Ruby
 
Guard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityGuard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful Security
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
Php e Cassandra
Php e Cassandra Php e Cassandra
Php e Cassandra
 
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django applicationDjangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django application
 
Let's talk testing with Selenium
Let's talk testing with SeleniumLet's talk testing with Selenium
Let's talk testing with Selenium
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
 
Complex Sites with Silex
Complex Sites with SilexComplex Sites with Silex
Complex Sites with Silex
 
Intro to SQL Injection
Intro to SQL InjectionIntro to SQL Injection
Intro to SQL Injection
 
Overlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh MyOverlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh My
 

Viewers also liked

Community outreach presentation
Community outreach presentationCommunity outreach presentation
Community outreach presentationlenawee
 
Diretrizes seminario da_pratic
Diretrizes seminario da_praticDiretrizes seminario da_pratic
Diretrizes seminario da_praticCarol Fontoura
 
Comets, meteors, and asteroids
Comets, meteors, and asteroidsComets, meteors, and asteroids
Comets, meteors, and asteroidsjennakaz
 
Ekc prog angl 2011 ekc
Ekc prog angl 2011 ekcEkc prog angl 2011 ekc
Ekc prog angl 2011 ekcjbhsante
 
Stakeholder Engagement: Avoid It At Your Own Risk
Stakeholder Engagement: Avoid It At Your Own Risk Stakeholder Engagement: Avoid It At Your Own Risk
Stakeholder Engagement: Avoid It At Your Own Risk American Electric Power
 
2011 AEP Corporate Accountability Report
2011 AEP Corporate Accountability Report 2011 AEP Corporate Accountability Report
2011 AEP Corporate Accountability Report American Electric Power
 
Integrated Reporting: The (R)evolution of Corporate Reporting
Integrated Reporting: The (R)evolution of Corporate Reporting Integrated Reporting: The (R)evolution of Corporate Reporting
Integrated Reporting: The (R)evolution of Corporate Reporting American Electric Power
 
Selenium RC Presentation 20110104
Selenium RC Presentation 20110104Selenium RC Presentation 20110104
Selenium RC Presentation 20110104Michael Salvucci
 
Comets, meteors, and asteroids
Comets, meteors, and asteroidsComets, meteors, and asteroids
Comets, meteors, and asteroidsjennakaz
 
Comets, meteors, and asteroids
Comets, meteors, and asteroidsComets, meteors, and asteroids
Comets, meteors, and asteroidsjennakaz
 
Perancangan Implementasi Unified Communications dan Analisa Quality of Servic...
Perancangan Implementasi Unified Communications dan Analisa Quality of Servic...Perancangan Implementasi Unified Communications dan Analisa Quality of Servic...
Perancangan Implementasi Unified Communications dan Analisa Quality of Servic...rizazizah
 
Desenho artistico e_de_apresen (1)
Desenho artistico e_de_apresen (1)Desenho artistico e_de_apresen (1)
Desenho artistico e_de_apresen (1)Carol Fontoura
 
Comets, meteors, and asteroids
Comets, meteors, and asteroidsComets, meteors, and asteroids
Comets, meteors, and asteroidsjennakaz
 
25 techniques Marketing digitales pour atteindre vos clients
25 techniques Marketing digitales pour atteindre vos clients25 techniques Marketing digitales pour atteindre vos clients
25 techniques Marketing digitales pour atteindre vos clientsAirYourVoice
 

Viewers also liked (19)

Community outreach presentation
Community outreach presentationCommunity outreach presentation
Community outreach presentation
 
Diretrizes seminario da_pratic
Diretrizes seminario da_praticDiretrizes seminario da_pratic
Diretrizes seminario da_pratic
 
Comets, meteors, and asteroids
Comets, meteors, and asteroidsComets, meteors, and asteroids
Comets, meteors, and asteroids
 
AEP | Credit Suisse 2011 Energy Summit
AEP | Credit Suisse 2011 Energy SummitAEP | Credit Suisse 2011 Energy Summit
AEP | Credit Suisse 2011 Energy Summit
 
2010 AEP Fact Book
2010 AEP Fact Book 2010 AEP Fact Book
2010 AEP Fact Book
 
Ekc prog angl 2011 ekc
Ekc prog angl 2011 ekcEkc prog angl 2011 ekc
Ekc prog angl 2011 ekc
 
Stakeholder Engagement: Avoid It At Your Own Risk
Stakeholder Engagement: Avoid It At Your Own Risk Stakeholder Engagement: Avoid It At Your Own Risk
Stakeholder Engagement: Avoid It At Your Own Risk
 
AEP 1Q 2011 Earnings Presentation
AEP 1Q 2011 Earnings PresentationAEP 1Q 2011 Earnings Presentation
AEP 1Q 2011 Earnings Presentation
 
2011 AEP Corporate Accountability Report
2011 AEP Corporate Accountability Report 2011 AEP Corporate Accountability Report
2011 AEP Corporate Accountability Report
 
Integrated Reporting: The (R)evolution of Corporate Reporting
Integrated Reporting: The (R)evolution of Corporate Reporting Integrated Reporting: The (R)evolution of Corporate Reporting
Integrated Reporting: The (R)evolution of Corporate Reporting
 
Selenium RC Presentation 20110104
Selenium RC Presentation 20110104Selenium RC Presentation 20110104
Selenium RC Presentation 20110104
 
Comets, meteors, and asteroids
Comets, meteors, and asteroidsComets, meteors, and asteroids
Comets, meteors, and asteroids
 
AEP Q4 2010 Earnings Presentation
AEP Q4 2010 Earnings Presentation AEP Q4 2010 Earnings Presentation
AEP Q4 2010 Earnings Presentation
 
Q3 2011 AEP Earnings Presentation
Q3 2011 AEP Earnings PresentationQ3 2011 AEP Earnings Presentation
Q3 2011 AEP Earnings Presentation
 
Comets, meteors, and asteroids
Comets, meteors, and asteroidsComets, meteors, and asteroids
Comets, meteors, and asteroids
 
Perancangan Implementasi Unified Communications dan Analisa Quality of Servic...
Perancangan Implementasi Unified Communications dan Analisa Quality of Servic...Perancangan Implementasi Unified Communications dan Analisa Quality of Servic...
Perancangan Implementasi Unified Communications dan Analisa Quality of Servic...
 
Desenho artistico e_de_apresen (1)
Desenho artistico e_de_apresen (1)Desenho artistico e_de_apresen (1)
Desenho artistico e_de_apresen (1)
 
Comets, meteors, and asteroids
Comets, meteors, and asteroidsComets, meteors, and asteroids
Comets, meteors, and asteroids
 
25 techniques Marketing digitales pour atteindre vos clients
25 techniques Marketing digitales pour atteindre vos clients25 techniques Marketing digitales pour atteindre vos clients
25 techniques Marketing digitales pour atteindre vos clients
 

Similar to Selenium rc presentation_20110104

UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013Michelangelo van Dam
 
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...Edureka!
 
UA Testing with Selenium and PHPUnit - ZendCon 2013
UA Testing with Selenium and PHPUnit - ZendCon 2013UA Testing with Selenium and PHPUnit - ZendCon 2013
UA Testing with Selenium and PHPUnit - ZendCon 2013Michelangelo van Dam
 
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...Edureka!
 
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQUA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQMichelangelo van Dam
 
Bcblackpool jquery tips
Bcblackpool jquery tipsBcblackpool jquery tips
Bcblackpool jquery tipsJack Franklin
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013Michelangelo van Dam
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207patter
 
Escape from the automation hell
Escape from the automation hellEscape from the automation hell
Escape from the automation hellNikita Simonovets
 
Automated testing with Drupal
Automated testing with DrupalAutomated testing with Drupal
Automated testing with DrupalPromet Source
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Michelangelo van Dam
 
Javatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJavatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJini Lee
 
Automation Testing
Automation TestingAutomation Testing
Automation TestingRomSoft SRL
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsMichael Peacock
 

Similar to Selenium rc presentation_20110104 (20)

UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
 
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
 
UA Testing with Selenium and PHPUnit - ZendCon 2013
UA Testing with Selenium and PHPUnit - ZendCon 2013UA Testing with Selenium and PHPUnit - ZendCon 2013
UA Testing with Selenium and PHPUnit - ZendCon 2013
 
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...
 
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQUA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
 
Bcblackpool jquery tips
Bcblackpool jquery tipsBcblackpool jquery tips
Bcblackpool jquery tips
 
Selenium testing - Handle Elements in WebDriver
Selenium testing - Handle Elements in WebDriver Selenium testing - Handle Elements in WebDriver
Selenium testing - Handle Elements in WebDriver
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Selenium Webdriver
Selenium WebdriverSelenium Webdriver
Selenium Webdriver
 
UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 
WCLA12 JavaScript
WCLA12 JavaScriptWCLA12 JavaScript
WCLA12 JavaScript
 
Escape from the automation hell
Escape from the automation hellEscape from the automation hell
Escape from the automation hell
 
Automated testing with Drupal
Automated testing with DrupalAutomated testing with Drupal
Automated testing with Drupal
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
Javatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJavatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparison
 
Selenium with java
Selenium with javaSelenium with java
Selenium with java
 
Automation Testing
Automation TestingAutomation Testing
Automation Testing
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
Webdriver
WebdriverWebdriver
Webdriver
 

Selenium rc presentation_20110104

  • 3. What is Selenium RC? • It is a program that allows test automation • It simulates a user navigating through pages and then verifies that content against expectations • It alerts the user to discrepancies via console or email • Its Selenese language allows phpunit to connect to a selenium server • The RC stands for Remote Control
  • 4. How does it work? • First, launch Selenium server: java –jar selenium-server.jar • Second, run a Selenese script: phpunit mytest.php
  • 5. Where to get it? • Selenium RC: http://seleniumhq.org/download/ • PHP Unit: http://www.phpunit.de/manual/current/en/installation.html
  • 6. What does the script look like? (1 of 2) <?php require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; class Example extends PHPUnit_Extensions_SeleniumTestCase { protected function setUp() { $this->setBrowser("*chrome"); $this->setBrowserUrl("http://www.nationalguard.com"); } continued…
  • 7. What does the script look like? (2 of 2) public function testMyTestCase() { $this->open("/"); sleep(5); $this->verifyTitle(“The National Guard"); // put the rest of your tests here } } ?>
  • 9. Now that I’ve got it… What can I do with it? • Open up a page: $this->open("/products"); • Click on a link: $this->click(“link=Log In”); • Verify a title: $this->verifyTitle(“The National Guard”); • Fill-out a form: $this->type(“signin_username”, “joe@example.com”); $this->type(“signin_password”, “123456”); $this->select(“gender”, “male”); $this->click(“//a[@onclick=”$(this).parents(‘form’).eq(0).submit(); return false;”]”);
  • 10. Wait a minute… What the heck is $this- >click(“//a[@onclick=”$(this).parents(‘form’).e q(0).submit(); return false;”]”); ? • It’s an XPath XPath is a language that describes how to locate specific elements in a document • How do I find the XPath for something? The easiest way is via a Firefox plug-in called XPather. Xpather extracts XPaths while browsing or inspecting HTML/XML/*ML documents. Then, when viewing a webpage, highlight the element you want, right-click for the submenu, then left-click on “Show in XPather”. • XPather is available at: http://xpath.alephzarro.com
  • 12. What else can I do? • Verify text appears on a page: $this->verifyText(“//html/body/div[@id=‘wrapper’]/div[@id=‘content’]/h2”, “Thank you Iostudio Tester”); • Verify an element is present: $this->verifyElementPresent(“//html/body[@id=‘profile’]/div[@id=‘wrap’]/div”); • Verify a URL: $this->verifyLocation(“http://www.nationalguard.com/chat”); • Switch over to a pop-up window so you can examine it: $windowName = $this->getAllWindowNames(); $this->waitForPopUp($windowName[1], “45000”); $this->selectWindow($windowName[1]);
  • 13. Locating Elements • “For many Selenium commands, a target is required. This target identifies an element in the content of the web application, and consists of the location strategy followed by the location in the format locatorType=location.” I’ve shown you the XPath way. Here’s some other examples: • Locating by identifier: verifyElementPresent(“identifier=loginForm”); • Locating by DOM: verifyElementPresent(“dom=document.getElementById(‘loginForm”); • Locating by CSS selector: verifyElementPresent(“css=form#loginForm”); • Refer to: http://seleniumhq.org/docs/04_selenese_commands-html for more information.
  • 14. Selenium RC: Caveats
  • 15. Caveats - verifyText() vs. verifyTextPresent() • Use verifyText() instead of verifyTextPresent() because the latter does not work properly • verifyTextPresent() is also weak because it doesn’t pinpoint what you want to look at exactly (eg. $this->verifyTextPresent(“Frequently Asked Questions”); ) • Proper usage (N.B. This should all be on one line): $this- >verifyText(“//html/body/div[@id='wrapper']/div[@id=' content_wrp']/div[@id='sidebar']/div[@id='side_tab_s tack']/div[@id='tab_content_container']/div[@id='flag _content']/div/div[@id='newWidget_flag_1']”, “Frequently Asked Questions”);
  • 16. Caveats - XPather • XPather reports elements with a single leading slash. However, Selenium RC expects to see two leading slashes for XPaths. $this->verifyElement(“//html/body/div[@id=‘wrapper’]/div[@id=‘content_wrp’]/div[@id=‘sidebar’]/div”);
  • 17. Caveats - False Positives • Selenium RC test alerts can result in false positives
  • 18. Caveats - Pop-up Windows • A problem with grabbing a pop-up window is that the window’s name is dynamic, and you have to know the window’s name in order to select it. • The pop-up could be named “selenium_blank45375”. The next time, it could be named “selenium_blank41821”, so we have to use the getAllWindowNames() function to get the name of the pop-up we need. $this->click("link=Take the tour."); $windowName = $this->getAllWindowNames(); $this->waitForPopUp($windowName[1], "45000"); $this->selectWindow($windowName[1]); sleep(7); $this->verifyTitle("Army National Guard Virtual Career Fair");
  • 20. Hudson Integration • With Hudson, you can automate Selenium (eg. run hourly tests) and receive email alerts when problem arise. • You can get Hudson here: http://hudson-ci.org
  • 22. References • http://seleniumhq.org/download/ • http://seleniumhq.org/docs/index.html • http://seleniumhq.org/docs/04_selenese_commands.html • http://release.seleniumhq.org/selenium-remote- control/0.9.2/doc/php/Selenium/Testing_Selenium.html • PHP Unit: http://www.phpunit.de/manual/current/en/installation.html • XPather (A Firefox Plugin for generating XPaths): http://xpath.alephzarro.com/ • Hudson: http://hudson-ci.org