Selenium web driver

10
Test Automation Using Selenium

Transcript of Selenium web driver

Page 1: Selenium web driver

Test Automation Using Selenium

Page 2: Selenium web driver

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.

Page 3: Selenium web driver

Selenium Components Selenium IDE

Selenium Remote Control

Selenium Webdriver

Page 4: Selenium web driver

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

Page 5: Selenium web driver
Page 6: Selenium web driver

• 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.

Page 7: Selenium web driver

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

Page 8: Selenium web driver

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

Page 9: Selenium web driver

Demo: Verify page titlepublic 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();}

Page 10: Selenium web driver

Thank You