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

Sebastiano Armeli

November 16, 2011
Tweet

More Decks by Sebastiano Armeli

Other Decks in Programming

Transcript

  1. Open Source Web Application Testing System Automated UI Testing Functional

    type of tests Multiple browsers, multiple languages What is Selenium? Monday, 3 June 13
  2. - IDE Firefox Plugin Selenium - Remote Control (RC) Server

    : Proxy to launch browsers Client libraries Selenium Core : JavaScript Framework Monday, 3 June 13
  3. - 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
  4. - IDE Selenium 2 - Grid 2 - Web Driver

    Bindings : Java, C#, Python, Ruby WebDriver API Simplified Architecture Selenium Server NOT needed * Monday, 3 June 13
  5. 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
  6. • 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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