Selenium rc presentation_20110104

1,296 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,296
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Selenium rc presentation_20110104

  1. 1. Michael SalvucciJanuary 4, 2011
  2. 2. Selenium RC: Introduction
  3. 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. 4. How does it work?• First, launch Selenium server: java –jar selenium-server.jar• Second, run a Selenese script: phpunit mytest.php
  5. 5. Where to get it?• Selenium RC: http://seleniumhq.org/download/• PHP Unit: http://www.phpunit.de/manual/current/en/installation.html
  6. 6. What does the script look like? (1 of 2)<?phprequire_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. 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 }}?>
  8. 8. Selenium RC:Common Tests
  9. 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. 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
  11. 11. XPather
  12. 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. 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. 14. Selenium RC: Caveats
  15. 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. 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. 17. Caveats - False Positives• Selenium RC test alerts can result in false positives
  18. 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");
  19. 19. Selenium RC:Hudson Integration
  20. 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
  21. 21. Selenium RC: References
  22. 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

×