Slide 1

Slide 1 text

Getting started with Selenium 2 Sebastiano Armeli-Battana @sebarmeli https://github.com/sebarmeli November 16, 2011 Monday, 3 June 13

Slide 2

Slide 2 text

Open Source Web Application Testing System Automated UI Testing Functional type of tests Multiple browsers, multiple languages What is Selenium? Monday, 3 June 13

Slide 3

Slide 3 text

History 2004 2007 2009 2011 Selenium WebDriver Selenium 2 Monday, 3 June 13

Slide 4

Slide 4 text

Selenium Monday, 3 June 13

Slide 5

Slide 5 text

Selenium Selenium Core : JavaScript Framework Monday, 3 June 13

Slide 6

Slide 6 text

- IDE Firefox Plugin Selenium Selenium Core : JavaScript Framework Monday, 3 June 13

Slide 7

Slide 7 text

- IDE Firefox Plugin Selenium - Remote Control (RC) Server : Proxy to launch browsers Client libraries Selenium Core : JavaScript Framework Monday, 3 June 13

Slide 8

Slide 8 text

- 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

Slide 9

Slide 9 text

“Best fit” language Clean & Object Oriented API HtmlUnitDriver Java bindings WebDriver Monday, 3 June 13

Slide 10

Slide 10 text

- IDE Selenium 2 - Grid 2 - Web Driver Bindings : Java, C#, Python, Ruby WebDriver API Simplified Architecture Selenium Server NOT needed * Monday, 3 June 13

Slide 11

Slide 11 text

Replicate Selenium RC functionalities Selenium Grid 2 Selenium Server Monday, 3 June 13

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Let’s code! Monday, 3 June 13

Slide 14

Slide 14 text

• 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

Slide 15

Slide 15 text

webElement.click() webElement.sendKeys(CharSequence... arg0) webElement.submit() Actions class Interactions Monday, 3 June 13

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

Mobile Testing Monday, 3 June 13

Slide 23

Slide 23 text

Selenium 2 - Java QuickStart Archetype Monday, 3 June 13

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

Questions ? Monday, 3 June 13