Selenium: Automated Testing Tool Presenter: Lanette Nichole Braxton October 21, 2014
Selenium: Automated Testing Tool Presenter: Lanette Nichole Braxton October 21, 2014
Selenium: Automated Testing Tool Presenter: Lanette Nichole Braxton October 21, 2014
• Selenium IDE
• Rapid prototyping tool for building test scripts
• Firefox plugin
• Can be used by developers with little to no programming experience to write simple tests quickly
and gain familiarity with the Selenese commands
• Has a recording feature that records a user’s live actions that can be exported in one of many
programming languages
• Does not provide iteration or conditional statements for test scripts
• Can only run tests against FireFox
• Developed tests can be run against other browsers, using a simple command-line interface that
invokes the Selenium RC server
• Can export WebDriver or Remote Control scripts (these scripts should be in PageObject
structure)
• Allows you the option to select a language for saving and displaying test cases
SELENIUM TOOLS
• Selenium Grid
• Scales the Selenium RC solution for large test suites and test that must be run in
multiple environments
• Tests can be run in parallel with simultaneous execution (different tests on
different remote machines)
• It allows for running your tests in a distributed test execution environment
• Used to run your tests against multiple browsers, multiple versions of browser,
and browsers running on different operating systems
• It reduces the time it takes for the test suite to complete a test pass
SELENIUM IDE
SELENIUM IDE
Selenese Commands
Action
Manipulate the state of the application
Used with “AndWait” (clickAndWait)
Accessors
Examines the application state and stores the results in variables
Used to auto generate Assertions
Assertions
Similar to Accessors but verifies the state of the application to what is expected
Modes: assert, verify and waitFor
SELENIUM IDE
Syntax
Has two parameters (both are not required)
Can view command requirements from the command reference tab
Parameters
Locators identify a UI Element on a page
Test Patterns are used for asserting or verifying
Selenium variable or Text Patterns that can be entered in input fields or drop down selections
SELENIUM IDE
Non-Script Parameters
Uses JavaScript to generate values for elements with non-script parameters
JavaScript must be enclosed in curly braces and proceeded by the label “javascript”
SELENIUM IDE
Locators
By Identifier
Used by default
Locator type is “identifier”
First element with id attribute value matching the location will be used
First element with a name attribute matching the location will be used if there are no id matches
By ID
More limited than the “identifier” type
Locator type is “id”
Use this type when you know the element’s id
By Name
Locates an element with a matching name attribute
Filters can be applied for elements with the same name attribute
Locator type is “name”
SELENIUM IDE
X-Path
Used for locating nodes in an XML document
Elements can be located in regards to absolute terms or a relative position to an element that has a
specified id or name attribute
Can locate elements via attributes other than id or name
Starts with “//”
By DOM
Can be accessed using Javascript
Locator type is “document”
By CSS
Uses the style binding of selectors to elements in a document as a locating strategy
Faster than X-Path and can find the most complicated objects in an intrinsic HTML document
Locator type is “css”
SELENIUM IDE
Matching Patterns
Text Patterns
A parameter required by following Selenese commands: verifyText, verifyText, verifyTitle, verifyAlert,
assertConfirmation, verifyPrompt, ect…
Globbing Patterns
Pattern matching based on wild card characters (*, [], -)
Uses the “glob:” label
Default pattern matching scheme
Regular Expressions
The most powerful pattern matching scheme
Prefixed with “regexp:” label
Exact Patterns
Uses no special characters, no need to escape characters
Prefixed with “exact:” label
SELENIUM IDE
• User Extensions
• JavaScript files created for customizations and features to add additional functionality
to Selenium IDE
• For Flow Control, install the goto_sel_ide.js extension
SELENIUM IDE
assertEquals("Google", selenium.getTitle());
selenium.click("btnG");
selenium.waitForPageToLoad("5000");
selenium.getTitle());
}
SELENIUM WEBDRIVER
Project Setup
Java
The easiest way is use Maven. Maven will download the java bindings (the Selenium 2.0 java client
library) and all its dependencies, and will create the project for you, using a maven pom.xml (project
configuration) file
You can then import the maven project into your preferred IDE, IntelliJ IDEA or Eclipse.
From a command-line, CD into the project directory and run maven as follows: mvn clean install
SELENIUM WEBDRIVER
• Locating UI Elements
• Language bindings expose a “findElement” and “Find Elements” method
• The “Find” methods take a locator or query object called “By”
• WebElement element= driver.findElement(By.id("coolestWidgetEvah"));
• List<WebElement>cheeses = driver.findElements(By.className("cheese"));
• WebElement frame = driver.findElement(By.tagName("iframe"));
• WebElement cheese = driver.findElement(By.name("cheese"));
• WebElement cheese = driver.findElement(By.linkText("cheese"));
• WebElement cheese = driver.findElement(By.partialLinkText("cheese"));
• Web Element cheese = driver.findElement(By.cssSelector(“#food.span.dairy.aged”)) List<WebElement> inputs =
driver.findElements(By.xpath("//input"));
• WebElement element = (WebElement) ((JavascriptExecutor)driver).executeScript("return $('.cheese')[0]");
• Input and Navigation
• Select select = new Select(driver.findElement(By.tagName("select")));
select.deselectAll(); select.selectByVisibleText("Edam");
• driver.findElement(By.id("submit")).click();
• driver.switchTo().window("windowName");
• for (String handle : driver.getWindowHandles()) { driver.switchTo().window(handle); }
• driver.switchTo().frame("frameName");
• Alert alert = driver.switchTo().alert();
• driver.navigate().to("http://www.example.com");
• driver.navigate().forward(); driver.navigate().back();
SELENIUM WEBDRIVER
Page Objects
OO Library that separates test code into a MVC pattern bringing OOP to test scripts
Language neutral pattern for representing a complete page or position of a page in an OO manner
Element Implementation
Actions
SELENIUM WEBDRIVER
Do not create the Page Object all at once, build test incrementally
Scripts Should
Not contain any synchronization code
Not contain any Driver API calls (promotes changes to Selenium or other technology without
changing the scripts)
Has asserts (determination of results)
SELENIUM WEBDRIVER
Driver Implementations
HtmlUnitDriver
The fastest and most lightweight implementation of WebDriver
HtmlUnit is a java based implementation of a WebBrowser without a GUI
For any language binding (other than java) the Selenium Server is required to use this driver
A pure Java solution and so it is platform independent
Supports JavaScript but emulates other browsers’ JavaScript behaviour
FireFox Driver
Controls the Firefox browser using a Firefox plugin
Runs in a real browser and supports JavaScript
Faster than the Internet Explorer Driver but slower than HtmlUnitDriver
SELENIUM WEBDRIVER
Driver Implementation
Chrome Driver
Chrome Driver is maintained / supported by the Chromium Project
WebDriver works with Chrome through the chromedriver binary (found on the chromium project’s
download page)
Runs in a real browser and supports JavaScript
Because Chrome is a Webkit-based browser, the Chrome Driver may allow you to verify that your site
works in Safari. Note that since Chrome uses its own V8 JavaScript engine rather than Safari’s Nitro
engine, JavaScript execution may differ
Slower than the HtmlUnit Driver
SELENIUM WEBDRIVER
Opera Driver
See the Opera Driver wiki article in the Selenium Wiki for information on using the Opera Driver
iOS Driver
See either the ios-driver or appium projects
Android Driver
See the Selendroid project
SELENIUM WEBDRIVER
open /
type q selenium rc
clickAndWait btnG
assertTextPresent Results * for selenium rc
SELENIUM RC
import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
• A Grid consists of a single Hub, and one or more Nodes. Both are started
using a selenium-server.jar executable.
• The Hub receives a test to be executed along with information on which
browser and ‘platform’ (i.e. WINDOWS, LINUX, etc) where the test
should be run.
• Since the Hub knows the configuration for each registered Node, it selects
an available Node that has the requested browser-platform combination
• Selenium commands initiated by the test are sent to the Hub, which passes
them to the Node assigned to that test
• The Node runs the browser, and executes the Selenium commands within
that browser against the application under test
SELENIUM REFERENCES
PushToTest.com
SelenuiumHQ