Gems Of Selenium
Upcoming SlideShare
Loading in...5

Gems Of Selenium



Gems of Selenium

Gems of Selenium



Total Views
Views on SlideShare
Embed Views



4 Embeds 628 580
http://smash 37 10 1



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Gems Of Selenium Gems Of Selenium Presentation Transcript

  • Gems of Selenium Anand Ramdeo Komal Joshi @testinggeek
  • Selenium Is.. |
  • A bit of History.. | SELENIUM
  • It All Started Here
    • Time and Expense application built using Python+Plone @ Thoughtworks
    • Goal was “Fast, Fast, Fast” | ADD ROW
  • It All Started Here
    • Time and Expense application built using Python+Plone @ Thoughtworks
    • Goal was “Fast, Fast, Fast” | ADD ROW
  • It All Started Here
    • Time and Expense application built using Python+Plone @ Thoughtworks
    • Goal was “Fast, Fast, Fast” | ADD ROW
  • Problems.. |
  • And Solutions..
    • Mozilla Extension – “Driftwood” by Andrew McCormick from Thoughtworks. Worked, but it was firefox only solution.
    • Paul Gross and Jasson Huggin set out to implement Fit for JS.
    • Which eventually became Selenium Core or Java Script Test Runner |
  • Popularity of Selenium |
  • Reason of Success |
  • In search of treasure @testinggeek
    • The journey begins..
    • Want to automate ?
    • What are the common problems faced by people when using selenium IDE?
  • In search of treasure @testinggeek
    • Treasure is ….
    • Reliable automation.
    • Stable automation.
    • Maintainable automation.
    • Effective Automation .
  • @testinggeek Found my first Gem…. UI Element  How can this precious gem help me?
  • UI Element is... @testinggeek
    • ...a mapping between semantically meaningful names of elements on webpages, and the elements.
    • ...defined using JSON
  • Abstraction With UI-Element
    • selenium.type("q", “TestingGeek");
    @testinggeek LOGIN_BUTTON = "css=input[value='Log in']" DELETE_CONFIRMATION = "css=input[value='"Yes, I'm sure"']" myMap.addPageset({     name: 'allPages',     description: 'All WLL Pages',     pathRegexp: '.*' }); myMap.addElement ('allPages', {     name: 'register'     , description: 'Register link on all the pages'     , locator: "xpath=//*[@id='user']/dd/a[1]"    })"ui=allPages::register()") Abstracting with UI Element
  • @testinggeek I want to extend Selenium with some new assertions,actions No problem User-extension.js is here for that.
  • Extending Slenium...
    • Selenium Object Prototype
    • Pagebot Object Prototype.
    • On startup, Selenium will automatically look through methods on these prototypes, using name patterns to recognize which ones are actions, assertions and locators.
  • Automation is incomplete without cross browser testing
    • Selenium RC gem for different browser…
    • * iehta
    • * firefox
    • * iexplore
    • * chrome
    • * custom (for custom browsers)
  • https...
    • Different options of selenium…
    • https
    • Multiwindow=<true/false>
    • Firefoxtemplate=<default template location>
  • Collecting all the gems and putting in the treasure chest @testinggeek
  • Is this the only treasure
    • The real gems are in your minds in your brains.
    • Come up with a solution
    • Implement a simple but effective solution.
  • Automate using wrappers. @testinggeek SA
    • Use a combination of tools....
    • Selenium + Auto it.
    • Selenium + Batch files.
  • @testinggeek SA /** * This method would just kill the PDF */ public void closesPDF(){ { String[] dialog = new String[] { &quot;srcestesourcesillAcroRd32.bat&quot;}; try { Process p = Runtime.getRuntime().exec(dialog); System.out.println(p.getErrorStream().toString()); System.out.println(p.getInputStream().toString()); System.out.println(p.getOutputStream().toString()); System.out.println(&quot;After execution&quot;); } catch (IOException e) { // TODO Auto-generated catch block System.out.println(&quot;In the exception&quot;); e.printStackTrace(); throw new AssertionError(&quot;No Dialogue box displayed&quot;); } } }
  • Easy to read Natural language automation
    • Simple easy to read language
    • POM.
  • Componentise your automation @testinggeek
  • Add dynamism...
    • Connecting to the databses…
  • @testinggeek All this is less effective if automation does not run automatically......
  • Integrate with CI tools @testinggeek Mavenise your automation... And integrate them with Hudson...
  • Distribute the Tests @testinggeek With Selenium Grids or Hudson Slaves...
  • Integrate with CI tools @testinggeek What about Selenium 2.0 ?..... Will my old selenium tests run in 2.0?
  • Selenium 2.0 @testinggeek -Web Driver - Presentation redering etc.
  • @testinggeek import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.RenderedWebElement; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class TestingGeek { public static void main(String[] args) throws Exception { // The Firefox driver supports javascript WebDriver driver = new FirefoxDriver(); // Go to the TestingGeek home page driver.get(&quot;;); // Enter the query string &quot;Cheese&quot; //WebElement query = driver.findElement(;q&quot;)); WebElement menu= driver.findElement(By. id(&quot;menu27&quot;));; // query.sendKeys(&quot;Cheese&quot;); // Sleep until the div we want is visible or 5 seconds is over long end = System. currentTimeMillis() + 5000; while (System. currentTimeMillis() < end) { // Browsers which render content (such as Firefox and IE) // return &quot;RenderedWebElements&quot; // RenderedWebElement resultsDiv = (RenderedWebElement) driver.findElement(By.className(&quot;gac_m&quot;)); RenderedWebElement resultsDiv = (RenderedWebElement) driver.findElement(By. id(&quot;menu27&quot;)); // If results have been returned, // the results are displayed in a drop down. if (resultsDiv.isDisplayed()) { break; } } // And now list the suggestions //List<WebElement> allSuggestions = driver.findElements(By. xpath(&quot;//td[@class='gac_c']&quot;)); List<WebElement> menus = driver.findElements(By. xpath(&quot;//div/div/div/ul/li[2]/ul&quot;)); for (WebElement menu1 : menus) { System. out.println(menu1.getText()); } } }
  • Thank You.
    • Anand Ramdeo
    • @testinggeek
    • [email_address]