2. Selenium developed in 2004 by Jason Huggins as a JavaScript library used to
automate his manual testing routines
In 2005 Dan Fabulich and Nelson Sproul (with help from Pat Lightbody)
made an offer to accept a series of patches that would transform Selenium-RC into
what it became best known for. In the same meeting, the steering of Selenium as a
project would continue as a committee, with Huggins and Hammant being the
ThoughtWorks representatives.
In 2007, Huggins joined Google.Together with others like Jennifer Bevan, he
continued with the development and stabilization of Selenium RC. At the same time,
Simon Stewart atThoughtWorks developed a superior browser automation tool called
WebDriver.
In 2009, after a meeting between the developers at the GoogleTest
Automation Conference, it was decided to merge the two projects, and call the new
project SeleniumWebDriver, or Selenium 2.0.
2
3. Selenium is a suite of testing automation tools used forWeb-Base
applications: Selenium IDE, Selenium RC, Selenium WebDriver and Selenium Grid
These tools provide a rich set of testing functions specifically geared to
varied testing scenarios of all types of Web applications
The operations provided by these tools are highly flexible and afford many
options for comparing UI elements to expected application behavior
Selenium tests can be executed on multiple browser platforms
3
4. 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
Developed tests can be run against other browsers, using a simple command-line
interface that invokes the Selenium RC server
Can exportWebDriver 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
4
5. Firefox extension
Easy record and playback
Not just a recorder
Intelligent field selection will
use IDs, names, or XPath as needed
Auto-complete for all common Selenium commands
Debug and set breakpoints
Save tests as HTML, Ruby scripts,
or any other format
5
6. 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
6
7. AndWait
▪ Tells Selenium to wait for the page to load after an action has been
performed
▪ Used when triggering navigation/page refresh (test will fail otherwise)
▪ Command: clickAndWait
WaitFor
▪ No set time period
▪ Dynamically waits for the desired condition, checking every second
▪ Commands: waitForElementPresent, waitForVisible, etc…
Echo
▪ Used to display information progress notes that is displayed to the console
during test execution
▪ Informational notes can be used to provide context within your test results
report
▪ Used to print the contents of Selenium variables
7
9. 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”
9
10. 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”
10
11. SeleniumWebDriver is the successor to Selenium RC. SeleniumWebDriver
accepts commands (sent in Selenese, or via a Client API) and sends them to a browser.
This is implemented through a browser-specific browser driver, which sends
commands to a browser, and retrieves results. Most browser drivers actually launch
and access a browser application (such as Firefox or Internet Explorer); there is also an
HtmlUnit browser driver, which simulates a browser using HtmlUnit.
Selenium-WebDriver supports multiple browsers in multiple platforms
Google Chrome 12.0.712.0+
Internet Explorer 6+
Firefox 3.0+
Opera 11.5+
Android – 2.3+ for phones and tablets
iOS 3+ for phones
iOS 3.2+ for tablets
11
12. WebDriver is designed to providing a simpler and uniformed programming
interface
▪ SameWebDriver script runs for different platforms
Support multiple programming language:
▪ Java, C#, Python, Ruby, PHP, Perl…
It’s efficient
▪ WebDriver leverages each browser’s native support for automation.
A solution for the automated testing
▪ Simulate user actions
▪ Functional testing
Create regression tests to verify functionality and user acceptance.
▪ Browser compatibility testing
The same script can run on any Selenium platform
▪ Load testing
▪ Stress testing
12
13. public static void main( String[] args ) {
// Create a new instance of the Firefox driver
WebDriver driver = new FirefoxDriver();
// (1) Go to a page
driver.get("http://www.google.com");
// (2) Locate an element
WebElement element = driver.findElement(By.name("q"));
// (3-1) Enter something to search for
element.sendKeys("Purdue Univeristy");
// (3-2) Now submit the form. WebDriver will find the form for us from the element
element.submit();
// (3-3) Wait up to 10 seconds for a condition
WebDriverWait waiting = newWebDriverWait(driver, 10);
waiting.until( ExpectedConditions.presenceOfElementLocated( By.id("pnnext") ) );
// (4) Check the title of the page
if( driver.getTitle().equals("purdue univeristy - Google Search") )
System.out.println("PASS");
else
System.err.println("FAIL");
//Close the browser
driver.quit();
}
13
14. By id
HTML: <div id="coolestWidgetEvah">...</div>
WebDriver:
driver.findElement( By.id("coolestWidgetEvah") );
By name
HTML: <input name="cheese" type="text"/>
WebDriver:
driver.findElement( By.name("cheese") );
By Xpath
HTML
<html>
<input type="text" name="example" />
<input type="text" name="other" />
</html>
WebDriver:
driver.findElements( By.xpath("//input") );
14
15. Creating New Instance Of Firefox Driver
WebDriver driver = new FirefoxDriver();
CommandTo Open URL In Browser
driver.get(“http://google.com");
Clicking on any element or button of webpage
driver.findElement(By.id("submitButton")).click();
Retrieve text from targeted element of software web application page and will
store it in variable = dropdown
String dropdown=driver.findElement(By.tagName("select")).getText;
Typing text in text box or text area.
driver.findElement(By.name("fname")).sendKeys("My First Name");
Applying Implicit wait in webdriver
driver.manage().timeouts().implicitlyWait(15,TimeUnit.SECONDS);
15
16. Get page title in selenium webdriver
driver.getTitle();
Get Current Page URL In SeleniumWebDriver
driver.getCurrentUrl();
Selecting or Deselecting value from drop down in selenium webdriver.
Select ByVisibleText
Select mydrpdwn = new Select(driver.findElement(By.id("Carlist")));
mydrpdwn.selectByVisibleText("Audi");
Select ByValue
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.selectByValue("Italy")
Select By Index
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.selectByIndex(0);
16
17. Get page title in selenium webdriver
driver.getTitle();
Get Current Page URL In SeleniumWebDriver
driver.getCurrentUrl();
Selecting or Deselecting value from drop down in selenium webdriver.
Select ByVisibleText
Select mydrpdwn = new Select(driver.findElement(By.id("Carlist")));
mydrpdwn.selectByVisibleText("Audi");
Select ByValue
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.selectByValue("Italy")
Select By Index
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.selectByIndex(0);
17
18. Navigate to URL or Back or Forward in SeleniumWebdriver
driver.navigate().to("http://google.com");
driver.navigate().back();
driver.navigate().forward();
Verify Element Present in SeleniumWebDriver
Boolean iselementpresent =
driver.findElements(By.xpath("//input[@id='text2']")).size()!= 0;
Capturing entire page screenshot in SeleniumWebDriver
File screenshot =
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File("D:screenshot.jpg"));
18
19. assertEquals
Assert.assertEquals(actual, expected);
AssertEquals assertion helps you to assert actual and expected equal values.
assertNotEquals
Assert.assertNotEquals(actual, expected);
assertNotEquals assertion is useful to assert not equal values.
assertTrue
Assert.assertTrue(condition);
assertTrue assertion works for boolean value true assertion.
assertFalse
Assert.assertFalse(condition);
assertFalse assertion works for boolean value false assertion.
19
20. Selenium IDE
Advantages
Selenium IDE is very easy to use.
It has the capability to convert the test to different programming languages such as html,
java etc
Programming language experience is not required for Selenium IDE
Selenium IDE provides Logging capabilities using file login plug-in.
In Selenium IDE, user can debug and set breakpoints
Selenium IDE is flexible for the users.
Disadvantage
Selenium IDE is Firefox plugin, thus its support is limited to Firefox only
It will not support iteration and conditional statement
Selenium IDE doesn't support error handling
Doesn't support test script grouping
Selenium IDE do not support Database testing
20
21. Selenium WebDriver
Advantages
Support for iPhone and Android testing
Better features for Ajax testing.
You can easily simulate clicking on front and back button of browser.
Unlike RC you dont have to start a server in webdriver.
You can simulate movement of a mouse using selenium.
You can find coordinates of any object usingWebdriver.
You have classes inWebdriver which help you to simulate key press events of keyboard.
Keywod driven framework is very easy to build in webdriver.
Disadvantages
WebDriver needs very much expertise resources.The resource should also be very well
versed in framework architecture.
It is difficult to test Image based application.
WebDriver need outside support for report generation activity like dependence on TestNG
or Jenkins
WebDriver does not support file upload facility.
21