The document discusses Selenium, an open-source tool for automating web application testing. It provides an overview of Selenium components and how they work. It also discusses challenges with the traditional Selenium approach and how Tellurium addresses these challenges by defining the UI structure separately from tests using a Groovy DSL. This allows for easier refactoring and separation of UI and test code compared to the traditional "record and play" Selenium approach. The document concludes with best practices for test automation and references for further information.
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
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)
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)
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
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
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.
#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.