KEMBAR78
Introduction to selenium web driver | PPTX
Introduction to Selenium Web Driver 
Kokhanjuk Maria Test Lead 
2012 www.ExigenServices.com
2 www.ExigenServices.com 
Agenda 
•What is Selenium 2.0 
•Architecture of Selenium 2.0 
•Selenium 2.0 API: 
• Finding elements 
• Basic operations on elements 
• Moving between windows and frames 
• Explicit and Implicit Waits 
•Creating tests using Selenium 2.0
3 www.ExigenServices.com 
What is Selenium? 
Selenium is a set of tools for cross-platform automated testing 
of web applications. 
Selenium supports: 
• IE, Firefox, Safari, Opera and other browsers 
• Windows, OS X, Linux, Solaris and other OS’s 
• C#, Java, Perl, PHP, Python, Ruby and other languages 
• Bromine, JUnit, NUnit, RSpec, TestNG, unittest
Components of Selenium 
4 www.ExigenServices.com 
• Selenium IDE 
• Selenium Remote Control (RC) 
• Selenium Grid 
• Selenium 2.0 and WebDriver
What is Selenium 2.0 ? 
Selenium 1.0 Webdriver 
5 www.ExigenServices.com 
merge 
Selenium 
Webdriver 2.0 
IDE 
Selenium RC 
Selenium Grid
Selenium 1.0 Architecture 
6 www.ExigenServices.com 
Autotests 
(Java, PHP, Phyton, 
Ruby, C#, …) 
Selenium RC 
Browsers 
Web-application 
HTTP
Selenium 2.0 Architecture 
7 www.ExigenServices.com 
Autotests Driver Browsers 
Web-application 
API 
to control the 
browser
Advantages of Selenium 2.0 
• The development and connection of new drivers, 
adapted to the specific test environment 
• A more "advanced" API for writing tests 
• Events generated are the same as for manual testing 
• Work with invisible elements is not available 
8 www.ExigenServices.com
Disadvantages of Selenium 2.0 
• Need to create own webdriver for each test 
9 www.ExigenServices.com 
environment 
• Only 4 programming languages are supported
10 www.ExigenServices.com 
WebDriver 
WebDriver’s Drivers 
•HtmlUnit Driver 
•Firefox Driver 
•Internet Explorer Driver 
•Chrome Driver 
•Opera Driver 
•iPhone Driver 
•Android Driver
WebDriver driver = new FirefoxDriver(); 
11 www.ExigenServices.com 
Selenium API 
WebDriver – to control the browser 
WebElement – to work with the elements on the page 
WebElement element = 
driver.findElement(By.id(“id”));
12 www.ExigenServices.com 
WebDriver API 
 void get(java.lang.String url) – open page 
 void quit() – close browser 
 WebDriver.TargetLocator switchTo() – switching 
between the popup-E, alert, windows 
 WebElement findElement(By by) -– find element by 
locator 
 List<WebElement> findElements(By by) – find 
elements by locator
Selenium API: Find elements 
13 www.ExigenServices.com 
 By.id("idOfObject") 
 By.linkText("TextUsedInTheLink") 
 By.partialLinkText("partOfThelink") 
 By.tagName("theHTMLNodeType") 
 By.className("cssClassOnTheElement") 
 By.cssSelector("cssSelectorToTheElement") 
 By.xpath("//Xpath/to/the/element") 
 By.name("nameOfElement")
Selenium API: Find elements 
14 www.ExigenServices.com 
Tools for finding elements: 
1. Firebug. Download firebug at http://getfirebug.com/ 
2. Firefinder for Firebug
Selenium API: Find elements 
http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#selectors 
15 www.ExigenServices.com
Selenium API: Basic operations on 
elements 
16 www.ExigenServices.com 
 void click() 
 void submit() 
 String getValue() 
 void sendKeys(keysToSend) 
 void clear() 
 String getElementName() 
 String getAttribute(java.lang.String name) 
 boolean toggle()
17 www.ExigenServices.com 
Selenium API: Waits 
Implicit Waits 
Explicit Waits
Working with windows 
18 www.ExigenServices.com 
 Working with browser windows 
driver.getWindowHandles() 
driver.switchTo().window(windowName) 
 Working with frames 
driver.switchTo().frame( "frameName" ); 
 Working with alerts 
driver.switchTo().alert();
19 www.ExigenServices.com 
Create tests 
1. Java 
http://java.com/ru/download 
2. IDE 
3. Library Selenium WebDriver 
http://seleniumhq.org/download/ 
4. Firebug
20 www.ExigenServices.com 
Create test 
Test Case: 
Selenium is in the first line of request for rambler search 
Condition: 
Browser is open 
Steps: 
1. Enter “selenium webdriver” into search request 
2. Press search button 
Expected result: 
The first line of request must be a link to the official 
Selenium website
21 www.ExigenServices.com 
Create test 
public class Rambler { 
protected WebDriver driver; 
@Before 
public void setUp() throws Exception { 
System.out.println("tmp"); 
// driver = new FirefoxDriver(); 
driver = new InternetExplorerDriver(); 
driver.get("http://www.rambler.ru/"); 
}
22 www.ExigenServices.com 
Create test 
@Test 
public void RamblerSearch() throws Exception { 
System.out.println(" TC: Selenium is in the first line of request for rambler search"); 
waitUntilDisplayed(By.cssSelector(Constants.txtRambler)); 
driver.findElement(By.cssSelector(Constants.txtRambler)).sendKeys("selenium webdriver"); 
driver.findElement(By.className("pointer")).click(); 
//wait first result 
waitUntilDisplayed(By.cssSelector("div[class='b-left-column__wrapper']")); 
assertTrue(driver.findElement(By.cssSelector("div[class='b-podmes_books b-podmes_ 
top_1']")).getText().contains("Selenium - Web Browser Automation")); 
}
23 www.ExigenServices.com 
Create test 
public class Constants { 
public static final String txtRambler = "input[class='r--hat-form-text-input']"; 
}
24 www.ExigenServices.com 
Create test 
@Test 
public void RamblerSearch() throws Exception { 
System.out.println(" TC: Selenium is in the first line of request for rambler search"); 
waitUntilDisplayed(By.cssSelector(Constants.txtRambler)); 
driver.findElement(By.cssSelector(Constants.txtRambler)).sendKeys("selenium webdriver"); 
driver.findElement(By.className("pointer")).click(); 
//wait first result 
waitUntilDisplayed(By.cssSelector("div[class='b-left-column__wrapper']")); 
assertTrue(driver.findElement(By.cssSelector("div[class='b-podmes_books b-podmes_ 
top_1']")).getText().contains("Selenium - Web Browser Automation")); 
}
25 www.ExigenServices.com 
Create test 
public void waitUntilDisplayed(final By locator) { 
( new WebDriverWait(driver, 120)).until(new ExpectedCondition<Boolean>() { 
public Boolean apply(WebDriver d) { 
return d.findElement(locator).isDisplayed(); 
} 
}); 
} 
@After 
public void tearDown() throws Exception { 
//close browser 
driver.quit(); 
}
26 www.ExigenServices.com 
Create test: result
27 www.ExigenServices.com 
Create test: result
28 www.ExigenServices.com 
Structure of the test 
1. Use Set UP () and tearDown() 
2. All tests should finish with assertion 
3. Elements’ locators should be defined in separate 
class
30 www.ExigenServices.com 
Useful links 
• http://seleniumhq.org/docs/ 
• http://software-testing.ru/library/testing/functional-testing/ 
1398-selenium-20 
• http://automated-testing. 
info/knowledgebase/avtomatizaciya-funkcionalnogo- 
testirovaniya/selenium 
• http://autotestgroup.com/ru/ 
• http://www.w3.org/TR/2001/CR-css3-selectors- 
20011113/#selectors 
• http://junit.org
31 www.ExigenServices.com 
Questions 
Questions?

Introduction to selenium web driver

  • 1.
    Introduction to SeleniumWeb Driver Kokhanjuk Maria Test Lead 2012 www.ExigenServices.com
  • 2.
    2 www.ExigenServices.com Agenda •What is Selenium 2.0 •Architecture of Selenium 2.0 •Selenium 2.0 API: • Finding elements • Basic operations on elements • Moving between windows and frames • Explicit and Implicit Waits •Creating tests using Selenium 2.0
  • 3.
    3 www.ExigenServices.com Whatis Selenium? Selenium is a set of tools for cross-platform automated testing of web applications. Selenium supports: • IE, Firefox, Safari, Opera and other browsers • Windows, OS X, Linux, Solaris and other OS’s • C#, Java, Perl, PHP, Python, Ruby and other languages • Bromine, JUnit, NUnit, RSpec, TestNG, unittest
  • 4.
    Components of Selenium 4 www.ExigenServices.com • Selenium IDE • Selenium Remote Control (RC) • Selenium Grid • Selenium 2.0 and WebDriver
  • 5.
    What is Selenium2.0 ? Selenium 1.0 Webdriver 5 www.ExigenServices.com merge Selenium Webdriver 2.0 IDE Selenium RC Selenium Grid
  • 6.
    Selenium 1.0 Architecture 6 www.ExigenServices.com Autotests (Java, PHP, Phyton, Ruby, C#, …) Selenium RC Browsers Web-application HTTP
  • 7.
    Selenium 2.0 Architecture 7 www.ExigenServices.com Autotests Driver Browsers Web-application API to control the browser
  • 8.
    Advantages of Selenium2.0 • The development and connection of new drivers, adapted to the specific test environment • A more "advanced" API for writing tests • Events generated are the same as for manual testing • Work with invisible elements is not available 8 www.ExigenServices.com
  • 9.
    Disadvantages of Selenium2.0 • Need to create own webdriver for each test 9 www.ExigenServices.com environment • Only 4 programming languages are supported
  • 10.
    10 www.ExigenServices.com WebDriver WebDriver’s Drivers •HtmlUnit Driver •Firefox Driver •Internet Explorer Driver •Chrome Driver •Opera Driver •iPhone Driver •Android Driver
  • 11.
    WebDriver driver =new FirefoxDriver(); 11 www.ExigenServices.com Selenium API WebDriver – to control the browser WebElement – to work with the elements on the page WebElement element = driver.findElement(By.id(“id”));
  • 12.
    12 www.ExigenServices.com WebDriverAPI  void get(java.lang.String url) – open page  void quit() – close browser  WebDriver.TargetLocator switchTo() – switching between the popup-E, alert, windows  WebElement findElement(By by) -– find element by locator  List<WebElement> findElements(By by) – find elements by locator
  • 13.
    Selenium API: Findelements 13 www.ExigenServices.com  By.id("idOfObject")  By.linkText("TextUsedInTheLink")  By.partialLinkText("partOfThelink")  By.tagName("theHTMLNodeType")  By.className("cssClassOnTheElement")  By.cssSelector("cssSelectorToTheElement")  By.xpath("//Xpath/to/the/element")  By.name("nameOfElement")
  • 14.
    Selenium API: Findelements 14 www.ExigenServices.com Tools for finding elements: 1. Firebug. Download firebug at http://getfirebug.com/ 2. Firefinder for Firebug
  • 15.
    Selenium API: Findelements http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#selectors 15 www.ExigenServices.com
  • 16.
    Selenium API: Basicoperations on elements 16 www.ExigenServices.com  void click()  void submit()  String getValue()  void sendKeys(keysToSend)  void clear()  String getElementName()  String getAttribute(java.lang.String name)  boolean toggle()
  • 17.
    17 www.ExigenServices.com SeleniumAPI: Waits Implicit Waits Explicit Waits
  • 18.
    Working with windows 18 www.ExigenServices.com  Working with browser windows driver.getWindowHandles() driver.switchTo().window(windowName)  Working with frames driver.switchTo().frame( "frameName" );  Working with alerts driver.switchTo().alert();
  • 19.
    19 www.ExigenServices.com Createtests 1. Java http://java.com/ru/download 2. IDE 3. Library Selenium WebDriver http://seleniumhq.org/download/ 4. Firebug
  • 20.
    20 www.ExigenServices.com Createtest Test Case: Selenium is in the first line of request for rambler search Condition: Browser is open Steps: 1. Enter “selenium webdriver” into search request 2. Press search button Expected result: The first line of request must be a link to the official Selenium website
  • 21.
    21 www.ExigenServices.com Createtest public class Rambler { protected WebDriver driver; @Before public void setUp() throws Exception { System.out.println("tmp"); // driver = new FirefoxDriver(); driver = new InternetExplorerDriver(); driver.get("http://www.rambler.ru/"); }
  • 22.
    22 www.ExigenServices.com Createtest @Test public void RamblerSearch() throws Exception { System.out.println(" TC: Selenium is in the first line of request for rambler search"); waitUntilDisplayed(By.cssSelector(Constants.txtRambler)); driver.findElement(By.cssSelector(Constants.txtRambler)).sendKeys("selenium webdriver"); driver.findElement(By.className("pointer")).click(); //wait first result waitUntilDisplayed(By.cssSelector("div[class='b-left-column__wrapper']")); assertTrue(driver.findElement(By.cssSelector("div[class='b-podmes_books b-podmes_ top_1']")).getText().contains("Selenium - Web Browser Automation")); }
  • 23.
    23 www.ExigenServices.com Createtest public class Constants { public static final String txtRambler = "input[class='r--hat-form-text-input']"; }
  • 24.
    24 www.ExigenServices.com Createtest @Test public void RamblerSearch() throws Exception { System.out.println(" TC: Selenium is in the first line of request for rambler search"); waitUntilDisplayed(By.cssSelector(Constants.txtRambler)); driver.findElement(By.cssSelector(Constants.txtRambler)).sendKeys("selenium webdriver"); driver.findElement(By.className("pointer")).click(); //wait first result waitUntilDisplayed(By.cssSelector("div[class='b-left-column__wrapper']")); assertTrue(driver.findElement(By.cssSelector("div[class='b-podmes_books b-podmes_ top_1']")).getText().contains("Selenium - Web Browser Automation")); }
  • 25.
    25 www.ExigenServices.com Createtest public void waitUntilDisplayed(final By locator) { ( new WebDriverWait(driver, 120)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.findElement(locator).isDisplayed(); } }); } @After public void tearDown() throws Exception { //close browser driver.quit(); }
  • 26.
  • 27.
  • 28.
    28 www.ExigenServices.com Structureof the test 1. Use Set UP () and tearDown() 2. All tests should finish with assertion 3. Elements’ locators should be defined in separate class
  • 29.
    30 www.ExigenServices.com Usefullinks • http://seleniumhq.org/docs/ • http://software-testing.ru/library/testing/functional-testing/ 1398-selenium-20 • http://automated-testing. info/knowledgebase/avtomatizaciya-funkcionalnogo- testirovaniya/selenium • http://autotestgroup.com/ru/ • http://www.w3.org/TR/2001/CR-css3-selectors- 20011113/#selectors • http://junit.org
  • 30.