Gems Of Selenium


Published on

Gems of Selenium

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Gems Of Selenium

  1. 1. Gems of Selenium Anand Ramdeo Komal Joshi @testinggeek
  2. 2. Selenium Is.. |
  3. 3. A bit of History.. | SELENIUM
  4. 4. It All Started Here <ul><li>Time and Expense application built using Python+Plone @ Thoughtworks </li></ul><ul><li>Goal was “Fast, Fast, Fast” </li></ul> | ADD ROW
  5. 5. It All Started Here <ul><li>Time and Expense application built using Python+Plone @ Thoughtworks </li></ul><ul><li>Goal was “Fast, Fast, Fast” </li></ul> | ADD ROW
  6. 6. It All Started Here <ul><li>Time and Expense application built using Python+Plone @ Thoughtworks </li></ul><ul><li>Goal was “Fast, Fast, Fast” </li></ul> | ADD ROW
  7. 7. Problems.. |
  8. 8. And Solutions.. <ul><li>Mozilla Extension – “Driftwood” by Andrew McCormick from Thoughtworks. Worked, but it was firefox only solution. </li></ul><ul><li>Paul Gross and Jasson Huggin set out to implement Fit for JS. </li></ul><ul><li>Which eventually became Selenium Core or Java Script Test Runner </li></ul> |
  9. 9. Popularity of Selenium |
  10. 10. Reason of Success |
  11. 11. In search of treasure @testinggeek <ul><li>The journey begins.. </li></ul><ul><li>Want to automate ? </li></ul><ul><li>What are the common problems faced by people when using selenium IDE? </li></ul>
  12. 12. In search of treasure @testinggeek <ul><li>Treasure is …. </li></ul><ul><li>Reliable automation. </li></ul><ul><li>Stable automation. </li></ul><ul><li>Maintainable automation. </li></ul><ul><li>Effective Automation . </li></ul>
  13. 13. @testinggeek Found my first Gem…. UI Element  How can this precious gem help me?
  14. 14. UI Element is... @testinggeek <ul><li>...a mapping between semantically meaningful names of elements on webpages, and the elements. </li></ul><ul><li>...defined using JSON </li></ul>
  15. 15. Abstraction With UI-Element <ul><li>selenium.type(&quot;q&quot;, “TestingGeek&quot;); </li></ul><ul><li>;btnG&quot;); </li></ul>@testinggeek LOGIN_BUTTON = &quot;css=input[value='Log in']&quot; DELETE_CONFIRMATION = &quot;css=input[value='&quot;Yes, I'm sure&quot;']&quot; myMap.addPageset({     name: 'allPages',     description: 'All WLL Pages',     pathRegexp: '.*' }); myMap.addElement ('allPages', {     name: 'register'     , description: 'Register link on all the pages'     , locator: &quot;xpath=//*[@id='user']/dd/a[1]&quot;    });ui=allPages::register()&quot;) Abstracting with UI Element
  16. 16. @testinggeek I want to extend Selenium with some new assertions,actions No problem User-extension.js is here for that.
  17. 17. Extending Slenium... <ul><li>Selenium Object Prototype </li></ul><ul><li>Pagebot Object Prototype. </li></ul><ul><li>On startup, Selenium will automatically look through methods on these prototypes, using name patterns to recognize which ones are actions, assertions and locators. </li></ul>@testinggeek
  18. 18. Automation is incomplete without cross browser testing <ul><li>Selenium RC gem for different browser… </li></ul><ul><li>* iehta </li></ul><ul><li>* firefox </li></ul><ul><li>* iexplore </li></ul><ul><li>* chrome </li></ul><ul><li>* custom (for custom browsers) </li></ul>@testinggeek
  19. 19. https... <ul><li>Different options of selenium… </li></ul><ul><li>https </li></ul><ul><li>Multiwindow=<true/false> </li></ul><ul><li>Firefoxtemplate=<default template location> </li></ul>@testinggeek
  20. 20. Collecting all the gems and putting in the treasure chest @testinggeek
  21. 21. Is this the only treasure <ul><li>The real gems are in your minds in your brains. </li></ul><ul><li>Come up with a solution </li></ul><ul><li>Implement a simple but effective solution. </li></ul>@testinggeek
  22. 22. Automate using wrappers. @testinggeek SA <ul><li>Use a combination of tools.... </li></ul><ul><li>Selenium + Auto it. </li></ul><ul><li>Selenium + Batch files. </li></ul>
  23. 23. @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;); } } }
  24. 24. Easy to read Natural language automation <ul><li>Simple easy to read language </li></ul><ul><li>POM. </li></ul>@testinggeek
  25. 25. Componentise your automation @testinggeek
  26. 26. Add dynamism... <ul><li>Connecting to the databses… </li></ul>@testinggeek
  27. 27. @testinggeek All this is less effective if automation does not run automatically......
  28. 28. Integrate with CI tools @testinggeek Mavenise your automation... And integrate them with Hudson...
  29. 29. Distribute the Tests @testinggeek With Selenium Grids or Hudson Slaves...
  30. 30. Integrate with CI tools @testinggeek What about Selenium 2.0 ?..... Will my old selenium tests run in 2.0?
  31. 31. Selenium 2.0 @testinggeek -Web Driver - Presentation redering etc.
  32. 32. @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()); } } }
  33. 33. Thank You. <ul><li>Anand Ramdeo </li></ul><ul><li> </li></ul><ul><li>@testinggeek </li></ul><ul><li> </li></ul><ul><li>[email_address] </li></ul>@testinggeek