KEMBAR78
Automated Web Testing Using Selenium | PPT
 
Automated Web Testing using Selenium Perficient China Waylon Zhang Yahoo!m:  waylon_zhang2008 [email_address]
Agenda Warm-up  Introduction of Selenium Framework Troubleshooting of Selenium Practice Q&A
Warm-up Google Advance Search Function
Prerequisite Development experience in Java language Knowledge of Xpath language Basic knowledge of HTML/Junit/TestNg Knowledge of The Same Origin Policy
What is Selenium? Selenium is a suite of tools to automate web app testing across many platforms.   Selenium Core: DHTML test execution framework Selenium IDE: Firefox extension – record and playback Selenium Remote Control Server: launches/kills browser, HTTP Proxy Client libraries Selenium Grid Run Selenium tests in parallel
Selenium components *Selenese is the set of Selenium Commands that run you tests. Don’t support If or For (While) statements C#, Java, Perl, PHP, Python, Ruby Selenese *Selenese  Programming Languages Yes No No Support I&O Yes No No Need Jre Yes Yes No Different Domain Yes Yes Yes Support Https/SSL No No Yes AUT Server side installed Firefox, IE,Safari Firefox Firefox, IE,Safari Browsers Selenium Remote Control Selenium IDE Selenium Core
How to use Selenium RC to develop
How Selenium RC Works?
How Selenium RC Works? (cont.)
Selenium Solutions of HTTPS Support HTTPS IE (supported by default, configure IE browser) FireFox (Selenium server doesn’t support add-ons configurations) Safari   (doesn’t support HTTPS configurations, so Selenium can’t run on it)
Selenium to Test Click Flash (1/2)
Selenium to test Click Flash (2/2) Get help from Developer javascript:WTKSendFlashClick( "{\"Page\":\"Exterior\", \"ClickType\":\"angleClick\",\"ClickParams\":{\"Direction\":\"left\"}}" ) Use Selenium’s API selenium.runScript(target)
Selenium to test Ajax Wait For It…
Add API to Selenium (1/2)  Example: add Function of  getTableRows(locator) to Selenium Server Side Add js to user-extensions.js Save the user-extensions.js under the folder where selenium server resides start selenium server with user-extensions.js
Add API to Selenium (2/2)  Example: add Function of  getTableRows(locator) to Selenium Client Side Add API to Selenium.java under package of com.thoughtworks.selenium  Add function to DefaultSelenium.java under package of com.thoughtworks.selenium
Selenium Open Issues How to test GWT web applications?
Problems in Selenium Verbose  Locators everywhere Coupling UI locators, actions, and assertions are coupled Not expressive What does the UI look like? Speed Since IE is lack of native XPath support, so tests run in IE are very slow Record and Play Re-labeling a button or moving it to another part of the window may require the test to be re-recorded Refactor Seems to be difficult Reusable Less likely
Tellurium’s solution package com.perficient.tellurium.webapp.ui import org.tellurium.dsl.DslContext public class TelluriumModule extends DslContext { public void defineUi(){ ui.Container(uid: "root", clocator: [tag: "table", name: "Tellurium"]){ InputBox(uid: "firstName", clocator: [tag: "input", type: "text", name: "FirstName"]) InputBox(uid: "lastName", clocator: [tag: "input", type: "text", name: "LastName"]) InputBox(uid: "fullName", clocator: [tag: "input", type: "text", name: "FullName"]) InputBox(uid: "save", clocator: [tag: "input", type: "button", value: "Save"], respond:  ["click"]) } } public void getFullName(String firstName,String lastName){ type "root.firstName",firstName type "root.lastName",lastName pause 500 click "root.save" } }
What is Tellurium? UI module based web testing framework built on top of Selenium UI is defined in Groovy class and tests can be written in  Java (JUnit 4 or TestNG) Groovy Pure DSL script Handles the mapping from Java object to UI  Reference:  http:// code.google.com/p/aost /
What challenges are addressed in Tellurium No longer “record and play” style, but UI module oriented Separated Robust Easy to refactor
What challenges are addressed in Tellurium Support jQuery Selector useJQuerySelector() disableJQuerySelector()
Summarization: Advantage/Disadvantage Involved new language  Very new, some potential risks we don’t know No longer “record and play” style, but UI module oriented Easy to refactor Easy to use UI and tests are separated Faster performance in IE  Ideally only defining the HTML elements is required as the entry criteria of scripting Tellurium Hard to refactor Very slow in IE UI locators, actions, and assertions are coupled Record and Play requires little or no software development  It’s required to have both the HTML and the back-end code ready before we start scripting Selenium Disadvantage Advantage Pre-condition
Best Practices To Automate or Not to Automate? That is the Question! The test framework should be approved, documented, reviewed. Structure scripts with minimal dependencies. Test automation is a fulltime effort, not a sideline. A dedicated team is required.
Q&A
References Tellurium Framework http:// code.google.com/p/aost /   Guidelines for Automation framework design http://knowledgeinbox.com/articles/automation/frameworks/guidelines-for-automation-framework-design/ 10 Step Test Automation Approach - Guide for automation testers http://testing.thoughtworks.com/article10step

Automated Web Testing Using Selenium

  • 1.
  • 2.
    Automated Web Testingusing Selenium Perficient China Waylon Zhang Yahoo!m: waylon_zhang2008 [email_address]
  • 3.
    Agenda Warm-up Introduction of Selenium Framework Troubleshooting of Selenium Practice Q&A
  • 4.
    Warm-up Google AdvanceSearch Function
  • 5.
    Prerequisite Development experiencein Java language Knowledge of Xpath language Basic knowledge of HTML/Junit/TestNg Knowledge of The Same Origin Policy
  • 6.
    What is Selenium?Selenium is a suite of tools to automate web app testing across many platforms. Selenium Core: DHTML test execution framework Selenium IDE: Firefox extension – record and playback Selenium Remote Control Server: launches/kills browser, HTTP Proxy Client libraries Selenium Grid Run Selenium tests in parallel
  • 7.
    Selenium components *Seleneseis the set of Selenium Commands that run you tests. Don’t support If or For (While) statements C#, Java, Perl, PHP, Python, Ruby Selenese *Selenese Programming Languages Yes No No Support I&O Yes No No Need Jre Yes Yes No Different Domain Yes Yes Yes Support Https/SSL No No Yes AUT Server side installed Firefox, IE,Safari Firefox Firefox, IE,Safari Browsers Selenium Remote Control Selenium IDE Selenium Core
  • 8.
    How to useSelenium RC to develop
  • 9.
  • 10.
    How Selenium RCWorks? (cont.)
  • 11.
    Selenium Solutions ofHTTPS Support HTTPS IE (supported by default, configure IE browser) FireFox (Selenium server doesn’t support add-ons configurations) Safari (doesn’t support HTTPS configurations, so Selenium can’t run on it)
  • 12.
    Selenium to TestClick Flash (1/2)
  • 13.
    Selenium to testClick Flash (2/2) Get help from Developer javascript:WTKSendFlashClick( "{\"Page\":\"Exterior\", \"ClickType\":\"angleClick\",\"ClickParams\":{\"Direction\":\"left\"}}" ) Use Selenium’s API selenium.runScript(target)
  • 14.
    Selenium to testAjax Wait For It…
  • 15.
    Add API toSelenium (1/2) Example: add Function of getTableRows(locator) to Selenium Server Side Add js to user-extensions.js Save the user-extensions.js under the folder where selenium server resides start selenium server with user-extensions.js
  • 16.
    Add API toSelenium (2/2) Example: add Function of getTableRows(locator) to Selenium Client Side Add API to Selenium.java under package of com.thoughtworks.selenium Add function to DefaultSelenium.java under package of com.thoughtworks.selenium
  • 17.
    Selenium Open IssuesHow to test GWT web applications?
  • 18.
    Problems in SeleniumVerbose Locators everywhere Coupling UI locators, actions, and assertions are coupled Not expressive What does the UI look like? Speed Since IE is lack of native XPath support, so tests run in IE are very slow Record and Play Re-labeling a button or moving it to another part of the window may require the test to be re-recorded Refactor Seems to be difficult Reusable Less likely
  • 19.
    Tellurium’s solution packagecom.perficient.tellurium.webapp.ui import org.tellurium.dsl.DslContext public class TelluriumModule extends DslContext { public void defineUi(){ ui.Container(uid: "root", clocator: [tag: "table", name: "Tellurium"]){ InputBox(uid: "firstName", clocator: [tag: "input", type: "text", name: "FirstName"]) InputBox(uid: "lastName", clocator: [tag: "input", type: "text", name: "LastName"]) InputBox(uid: "fullName", clocator: [tag: "input", type: "text", name: "FullName"]) InputBox(uid: "save", clocator: [tag: "input", type: "button", value: "Save"], respond: ["click"]) } } public void getFullName(String firstName,String lastName){ type "root.firstName",firstName type "root.lastName",lastName pause 500 click "root.save" } }
  • 20.
    What is Tellurium?UI module based web testing framework built on top of Selenium UI is defined in Groovy class and tests can be written in Java (JUnit 4 or TestNG) Groovy Pure DSL script Handles the mapping from Java object to UI Reference: http:// code.google.com/p/aost /
  • 21.
    What challenges areaddressed in Tellurium No longer “record and play” style, but UI module oriented Separated Robust Easy to refactor
  • 22.
    What challenges areaddressed in Tellurium Support jQuery Selector useJQuerySelector() disableJQuerySelector()
  • 23.
    Summarization: Advantage/Disadvantage Involvednew language Very new, some potential risks we don’t know No longer “record and play” style, but UI module oriented Easy to refactor Easy to use UI and tests are separated Faster performance in IE Ideally only defining the HTML elements is required as the entry criteria of scripting Tellurium Hard to refactor Very slow in IE UI locators, actions, and assertions are coupled Record and Play requires little or no software development It’s required to have both the HTML and the back-end code ready before we start scripting Selenium Disadvantage Advantage Pre-condition
  • 24.
    Best Practices ToAutomate or Not to Automate? That is the Question! The test framework should be approved, documented, reviewed. Structure scripts with minimal dependencies. Test automation is a fulltime effort, not a sideline. A dedicated team is required.
  • 25.
  • 26.
    References Tellurium Frameworkhttp:// code.google.com/p/aost / Guidelines for Automation framework design http://knowledgeinbox.com/articles/automation/frameworks/guidelines-for-automation-framework-design/ 10 Step Test Automation Approach - Guide for automation testers http://testing.thoughtworks.com/article10step

Editor's Notes

  • #8 Notes
  • #12 -firefoxProfileTemplate ${selenium.home}/profiles/firefoxProfile
  • #16 Add js to user-extensions.js: Selenium.prototype.getTableRows = function(locator) { /** * Gets the number of rows in a table. * * @param locator element locator for table * @return number of rows in the table, 0 if none */ var table = this.browserbot.findElement(locator); return table.rows.length.toString(); }; Selenium.java: String getTableRows(String locator); DefaultSelenium.java: public String getTableRows(String locator){ return commandProcessor.getString("getTableRows", new String[] {locator,}); } Test Method: public void testTables() throws InterruptedException{ selenium.open("http://www.w3schools.com/tags/tag_table.asp"); Thread. sleep (10000); String rows= selenium.getTableRows("//table[@id='table3']"); System. out .println("rows count= "+rows); }
  • #17 Add js to user-extensions.js: Selenium.prototype.getTableRows = function(locator) { /** * Gets the number of rows in a table. * * @param locator element locator for table * @return number of rows in the table, 0 if none */ var table = this.browserbot.findElement(locator); return table.rows.length.toString(); }; Selenium.java: String getTableRows(String locator); DefaultSelenium.java: public String getTableRows(String locator){ return commandProcessor.getString("getTableRows", new String[] {locator,}); } Test Method: public void testTables() throws InterruptedException{ selenium.open("http://www.w3schools.com/tags/tag_table.asp"); Thread. sleep (10000); String rows= selenium.getTableRows("//table[@id='table3']"); System. out .println("rows count= "+rows); }
  • #22 XPath builder can build the XPath from the composite locator, i.e., a set of attributes. Starting with version 0.6.0, Tellurium supports jQuery selectors to address the problem of poor performance of XPath in Internet Explorer. jQuery selector builders are used to automatically generate jQuery selectors instead of XPath with the following advantages: Faster performance in IE. Leverage the power of jQuery to retrieve bulk data from the web by testing with one method call. New features provided by jQuery attribute selectors.
  • #25 Notes
  • #27 Notes