Test Automation Using
Selenium
Selenium
 Selenium is a robust set of tools that supports rapid development of test automation for
web-based applications.
 Supports Cross Browser Testing. The Selenium tests can be run on multiple browsers.
 Allows scripting in several languages like Java, C#, PHP and Python.
Selenium Components
 Selenium IDE
 Selenium Remote Control
 Selenium Webdriver
Selenium IDE Limitations
 No multiple browsers support
 It runs only in Mozilla Firefox.
 Selenium IDE can execute scripts created in Selenese only.
 It is difficult to use Selenium IDE for checking complex test cases involving
dynamic contents
 No manual scripts
 E.g. conditions and Loops for Data Driven Testing
• Introduction to Selenium 2.0(WebDriver)
 Webdriver is the most commonly used cross browser testing tool
 Native automation faster and a little less prone to error and browser configuration
 Supports multiple OS platforms ( Windows/Mac/Linux/Android/iOS)
 No other tool supports to the extent selenium does with multiple OS testing.
 Supports multiple browsers (IE/Firefox/Chrome/Opera/Safari)
 Supports all latest versions of all the browsers including Safari and Opera , considering
safari users
 Selenium also supports backend validations.
 Fast and Lightweight
 Better execution speed compare to commercial tools.
Getting Started : Softwares Needed
 JDK
 Eclipse
 Selenium jar files
 Can be downloaded from http://www.seleniumhq.org/download/
 Drivers for IE and Chrome
 All Required jar files for the framework
 junit-4.12.jar
 hamcrest-core-1.3.jar
 apache-poi.jar - To get the data from Excel
 sikuli-java.jar - Integration with Sikuli
How to locate an element
 To identify the objects such as Links, Buttons, Edit boxes, Drop downs, etc on the application Selenium uses a
concept called “Locators”.
 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") );
Note : There are plug-ins for firefox/chrome to automatically display the Xpath
Demo: Verify page title
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(“Sun technologies");
// (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 = new WebDriverWait(driver, 10);
waiting.until( ExpectedConditions.presenceOfElementLocated( By.id("pnnext") ) );
// (4) Check the title of the page
if( driver.getTitle().equals(“sun technologies - Google Search") )
System.out.println("PASS");
else
System.err.println("FAIL");
driver.quit();
}
Selenium web driver

Selenium web driver

  • 1.
  • 2.
    Selenium  Selenium isa robust set of tools that supports rapid development of test automation for web-based applications.  Supports Cross Browser Testing. The Selenium tests can be run on multiple browsers.  Allows scripting in several languages like Java, C#, PHP and Python.
  • 3.
    Selenium Components  SeleniumIDE  Selenium Remote Control  Selenium Webdriver
  • 4.
    Selenium IDE Limitations No multiple browsers support  It runs only in Mozilla Firefox.  Selenium IDE can execute scripts created in Selenese only.  It is difficult to use Selenium IDE for checking complex test cases involving dynamic contents  No manual scripts  E.g. conditions and Loops for Data Driven Testing
  • 6.
    • Introduction toSelenium 2.0(WebDriver)  Webdriver is the most commonly used cross browser testing tool  Native automation faster and a little less prone to error and browser configuration  Supports multiple OS platforms ( Windows/Mac/Linux/Android/iOS)  No other tool supports to the extent selenium does with multiple OS testing.  Supports multiple browsers (IE/Firefox/Chrome/Opera/Safari)  Supports all latest versions of all the browsers including Safari and Opera , considering safari users  Selenium also supports backend validations.  Fast and Lightweight  Better execution speed compare to commercial tools.
  • 7.
    Getting Started :Softwares Needed  JDK  Eclipse  Selenium jar files  Can be downloaded from http://www.seleniumhq.org/download/  Drivers for IE and Chrome  All Required jar files for the framework  junit-4.12.jar  hamcrest-core-1.3.jar  apache-poi.jar - To get the data from Excel  sikuli-java.jar - Integration with Sikuli
  • 8.
    How to locatean element  To identify the objects such as Links, Buttons, Edit boxes, Drop downs, etc on the application Selenium uses a concept called “Locators”.  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") ); Note : There are plug-ins for firefox/chrome to automatically display the Xpath
  • 9.
    Demo: Verify pagetitle 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(“Sun technologies"); // (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 = new WebDriverWait(driver, 10); waiting.until( ExpectedConditions.presenceOfElementLocated( By.id("pnnext") ) ); // (4) Check the title of the page if( driver.getTitle().equals(“sun technologies - Google Search") ) System.out.println("PASS"); else System.err.println("FAIL"); driver.quit(); }