Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Getting started with Selenium WebDriver

Getting started with Selenium WebDriver

Talk given at OSDC 2011, Canberra - November 2011

A32ee5b05bff6b42a3dd62b5732065f8?s=128

Sebastiano Armeli-Battana

November 16, 2011
Tweet

Transcript

  1. Getting started with Selenium 2 Sebastiano Armeli-Battana @sebarmeli https://github.com/sebarmeli November

    16, 2011 Monday, 3 June 13
  2. Open Source Web Application Testing System Automated UI Testing Functional

    type of tests Multiple browsers, multiple languages What is Selenium? Monday, 3 June 13
  3. History 2004 2007 2009 2011 Selenium WebDriver Selenium 2 Monday,

    3 June 13
  4. Selenium Monday, 3 June 13

  5. Selenium Selenium Core : JavaScript Framework Monday, 3 June 13

  6. - IDE Firefox Plugin Selenium Selenium Core : JavaScript Framework

    Monday, 3 June 13
  7. - IDE Firefox Plugin Selenium - Remote Control (RC) Server

    : Proxy to launch browsers Client libraries Selenium Core : JavaScript Framework Monday, 3 June 13
  8. - IDE Firefox Plugin Selenium - Grid Distributed remote tests

    - Remote Control (RC) Server : Proxy to launch browsers Client libraries Selenium Core : JavaScript Framework Monday, 3 June 13
  9. “Best fit” language Clean & Object Oriented API HtmlUnitDriver Java

    bindings WebDriver Monday, 3 June 13
  10. - IDE Selenium 2 - Grid 2 - Web Driver

    Bindings : Java, C#, Python, Ruby WebDriver API Simplified Architecture Selenium Server NOT needed * Monday, 3 June 13
  11. Replicate Selenium RC functionalities Selenium Grid 2 Selenium Server Monday,

    3 June 13
  12. Java / C# bindings Selenium Server Android APK http://code.google.com/p/selenium/downloads/list Chrome

    Driver http://code.google.com/p/chromium/downloads/list Ruby gem install selenium-webdriver Python pip install selenium / easy_install selenium First steps Monday, 3 June 13
  13. Let’s code! Monday, 3 June 13

  14. • Id webDriver.findElement(By.id("logo")); • Name webDriver.findElement(By.name("q")); • Tag Name webDriver.findElement(By.tagName("H1"));

    • Class name webDriver.findElements(By.className("sponsor_logos")); • CSS Selector webDriver.findElement(By.cssSelector("section#sponsor>p")); • XPath webDriver.findElement(By.xpath("//section[@id=‘miniconfs’]/a[2]")); • Link Text webDriver.findElements(By.linkText("About")); • Partial Link Text webDriver.findElement(By.partialLinkText("visitcanberra")); Locator Strategies Monday, 3 June 13
  15. webElement.click() webElement.sendKeys(CharSequence... arg0) webElement.submit() Actions class Interactions Monday, 3 June

    13
  16. DOM Elements loaded asynchronously Wait for n seconds -> Implicit

    Wait webDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); (Java) webDriver.manage.timeouts.implicit_wait = 30 (Ruby) webDriver.implicit_wait(30) (Python) ExpectedCondition and WebDriverWait classes -> Explicit Wait AJAX applications Monday, 3 June 13
  17. Testing CSS properties webElement.getCssValue(“height”); webElement.getCssValue(“background-image”); JavascriptExecutor class JavascriptExecutor js =

    (JavascriptExecutor) webDriver; Long value = (Long) js.executeScript("return window.scrollY"); Testing style and executing JS Monday, 3 June 13
  18. TargetLocator Class To switch between Frames and Popup Dialogs TargetLocator

    target = webDriver.switchTo(); WebElement element = target.frame(“name”) Alert alert = target.alert(); Navigation Class To navigate like in a browser Navigation nav = webDriver.navigate(); nav.back(); / nav.forward(); nav.to(“url”); TargetLocator Class and Navigation Class Monday, 3 June 13
  19. Selenium selenium = new WebDriverBackedSelenium(webDriver, “http://osdc.com.au”); selenium.open("http://osdc.com.au"); selenium.click("id=follow_twitter"); selenium.waitForPageToLoad("10000"); Migrating

    from Selenium 1 Monday, 3 June 13
  20. Pages as Objects Separation between DOM and services in a

    Page WebDriver API not exposed PageFactory class to easily instantiate a Page Object Page Object Pattern / PageFactory Monday, 3 June 13
  21. Starting Hub java -jar selenium-server-standalone-2.9.0.jar -role hub Starting WebDriver Node

    java -jar selenium-server-standalone-2.9.0.jar -role webdriver - hub http://localhost:4444/grid/register -browser browserName=chrome,version=15,platform=MAC -port 5556 Grid console http://localhost:4444/grid/console Launching Test Remotely (Java) Selenium Grid 2 Monday, 3 June 13
  22. Mobile Testing Monday, 3 June 13

  23. Selenium 2 - Java QuickStart Archetype Monday, 3 June 13

  24. http://seleniumhq.org/ http://code.google.com/p/selenium/ http://code.google.com/p/selenium/wiki http://code.google.com/p/selenium/downloads/list Google Groups Resources Monday, 3 June

    13
  25. Questions ? Monday, 3 June 13