Getting started with Selenium 2
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
9,341
On Slideshare
9,274
From Embeds
67
Number of Embeds
8

Actions

Shares
Downloads
600
Comments
0
Likes
12

Embeds 67

http://osdc.com.au 32
http://2011.osdc.com.au 22
http://www.linkedin.com 5
http://a0.twimg.com 3
https://twitter.com 2
http://www.scoop.it 1
https://www.linkedin.com 1
http://pmomale-ld1 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Transcript

  • 1. Getting started with Selenium 2 Sebastiano Armeli-Battana @sebarmeli https://github.com/sebarmeliNovember 17 , 2011 Open Source Developers Conference, Canberra
  • 2. What is Selenium?Open Source Web Application Testing SystemAutomated UI TestingFunctional type of testsMultiple browsers, multiple languages
  • 3. History 2004 2007 2009 2011Selenium WebDriver Selenium 2
  • 4. Selenium
  • 5. SeleniumSelenium Core : JavaScript Framework
  • 6. SeleniumSelenium Core : JavaScript Framework- IDE Firefox Plugin
  • 7. SeleniumSelenium Core : JavaScript Framework - IDE Firefox Plugin - Remote Control (RC) Server : Proxy to launch browsers Client libraries
  • 8. SeleniumSelenium Core : JavaScript Framework - IDE Firefox Plugin - Remote Control (RC) Server : Proxy to launch browsers Client libraries - Grid Distributed remote tests
  • 9. WebDriver“Best fit” language Clean & Object Oriented APIHtmlUnitDriverJava bindings
  • 10. Selenium 2 - IDE - Web Driver Bindings : Java, C#, Python, Ruby WebDriver API Simplified Architecture Selenium Server NOT needed * - Grid 2
  • 11. Selenium ServerReplicate Selenium RC functionalitiesSelenium Grid 2
  • 12. First stepsJava / C# bindingsSelenium ServerAndroid APKhttp://code.google.com/p/selenium/downloads/listChrome Driverhttp://code.google.com/p/chromium/downloads/listRubygem install selenium-webdriverPythonpip install selenium / easy_install selenium
  • 13. Let’s code!
  • 14. Locator Strategies• 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"));
  • 15. Page interactionswebElement.click()webElement.sendKeys(...)webElement.submit()Actions class Mouse Events / Drag and Drop
  • 16. AJAX applicationsDOM Elements loaded asynchronouslya) Polling the DOM for n secondswebDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); (Java)webDriver.manage.timeouts.implicit_wait = 30 (Ruby)webDriver.implicit_wait(30) (Python)b) Wait until condition occursExpectedCondition / WebDriverWait
  • 17. Testing style and executing JSTesting CSS propertieswebElement.getCssValue(“height”);webElement.getCssValue(“background-image”);Javascript executionJavascriptExecutor js = (JavascriptExecutor) webDriver;Long value = (Long) js.executeScript("return window.scrollY");
  • 18. TargetLocator and Navigation InterfacesTargetLocator Frames and Popup DialogsTargetLocator target = webDriver.switchTo();WebElement element = target.frame(“name”)Alert alert = target.alert();Navigation Browser buttons emulationNavigation nav = webDriver.navigate();nav.back(); / nav.forward(); nav.to(“url”);
  • 19. Migrating from Selenium 1Selenium selenium = new WebDriverBackedSelenium(webDriver, “http://osdc.com.au”);selenium.open("http://osdc.com.au");selenium.click("id=follow_twitter");selenium.waitForPageToLoad("10000");WebDriver webDriver = ((WebDriverBackedSelenium) selenium).getUnderlyingWebDriver();
  • 20. Page Object Pattern / PageFactoryPages as ObjectsSeparation between DOM and services in a PageWebDriver API not exposedPageFactory class to easily instantiate a Page Object
  • 21. Selenium Grid 2Starting Hub java -jar selenium-server-standalone-2.9.0.jar -role hubStarting WebDriver Node java -jar selenium-server-standalone-2.9.0.jar -role webdriver -hub http://localhost:4444/grid/register -browserbrowserName=chrome,version=15,platform=MAC -port 5556Grid consolehttp://localhost:4444/grid/consoleLaunching Test Remotely (Java)
  • 22. Mobile Testing
  • 23. Selenium 2 - Java QuickStart Archetypehttps://github.com/sebarmeli/Selenium2-Java-QuickStart-Archetype
  • 24. Resourceshttp://www.slideshare.net/sebarmeli/getting-started-with-selenium-2https://github.com/sebarmeli/Selenium2-Java-Demohttp://seleniumhq.org/http://code.google.com/p/selenium/Google Groups
  • 25. Questions ?