SlideShare une entreprise Scribd logo
1  sur  30
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
4 www.ExigenServices.com
Components of Selenium
• Selenium IDE
• Selenium Remote Control (RC)
• Selenium Grid
• Selenium 2.0 and WebDriver
5 www.ExigenServices.com
Selenium 1.0 Webdriver
merge
Selenium
Webdriver 2.0
What is Selenium 2.0 ?
IDE
Selenium RC
Selenium Grid
6 www.ExigenServices.com
Autotests
(Java, PHP, Phyton,
Ruby, C#, …)
Selenium RC
Browsers
Web-application
HTTP
Selenium 1.0 Architecture
7 www.ExigenServices.com
Autotests Driver Browsers
Web-application
API
to control the
browser
Selenium 2.0 Architecture
8 www.ExigenServices.com
• 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
Advantages of Selenium 2.0
9 www.ExigenServices.com
Disadvantages of Selenium 2.0
• Need to create own webdriver for each test
environment
• Only 4 programming languages are supported
10 www.ExigenServices.com
WebDriver
•HtmlUnit Driver
•Firefox Driver
•Internet Explorer Driver
•Chrome Driver
•Opera Driver
•iPhone Driver
•Android Driver
WebDriver’s Drivers
11 www.ExigenServices.com
Selenium API
WebDriver – to control the browser
WebElement – to work with the elements on the page
WebDriver driver = new FirefoxDriver();
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
13 www.ExigenServices.com
Selenium API: Find elements
 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 www.ExigenServices.com
Selenium API: Find elements
Tools for finding elements:
1. Firebug. Download firebug at http://getfirebug.com/
2. Firefinder for Firebug
15 www.ExigenServices.com
Selenium API: Find elements
http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#selectors
16 www.ExigenServices.com
Selenium API: Basic operations on
elements
 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
18 www.ExigenServices.com
Working with windows
 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

Contenu connexe

Tendances

Boston selenium meetup: Selenium 2
Boston selenium meetup: Selenium 2Boston selenium meetup: Selenium 2
Boston selenium meetup: Selenium 2
epall
 
Automation with Selenium Presented by Quontra Solutions
Automation with Selenium Presented by Quontra SolutionsAutomation with Selenium Presented by Quontra Solutions
Automation with Selenium Presented by Quontra Solutions
Quontra Solutions
 
Selenium withnet
Selenium withnetSelenium withnet
Selenium withnet
Vlad Maniak
 

Tendances (20)

Selenium WebDriver with C#
Selenium WebDriver with C#Selenium WebDriver with C#
Selenium WebDriver with C#
 
Selenium with java
Selenium with javaSelenium with java
Selenium with java
 
Selenium
SeleniumSelenium
Selenium
 
Selenium training
Selenium trainingSelenium training
Selenium training
 
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriver
 
Selenium presentation
Selenium presentationSelenium presentation
Selenium presentation
 
Boston selenium meetup: Selenium 2
Boston selenium meetup: Selenium 2Boston selenium meetup: Selenium 2
Boston selenium meetup: Selenium 2
 
Automated testing using Selenium & NUnit
Automated testing using Selenium & NUnitAutomated testing using Selenium & NUnit
Automated testing using Selenium & NUnit
 
Introduction to Selenium
Introduction to SeleniumIntroduction to Selenium
Introduction to Selenium
 
Selenium Overview
Selenium OverviewSelenium Overview
Selenium Overview
 
Automation with Selenium Presented by Quontra Solutions
Automation with Selenium Presented by Quontra SolutionsAutomation with Selenium Presented by Quontra Solutions
Automation with Selenium Presented by Quontra Solutions
 
Selenium webdriver
Selenium webdriverSelenium webdriver
Selenium webdriver
 
Selenium using Java
Selenium using JavaSelenium using Java
Selenium using Java
 
Web driver training
Web driver trainingWeb driver training
Web driver training
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
 
Selenium withnet
Selenium withnetSelenium withnet
Selenium withnet
 
Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and Ruby
 
Protractor Testing Automation Tool Framework / Jasmine Reporters
Protractor Testing Automation Tool Framework / Jasmine ReportersProtractor Testing Automation Tool Framework / Jasmine Reporters
Protractor Testing Automation Tool Framework / Jasmine Reporters
 
Basic Selenium Training
Basic Selenium TrainingBasic Selenium Training
Basic Selenium Training
 

En vedette (8)

Enterprise service bus part 1
Enterprise service bus part 1Enterprise service bus part 1
Enterprise service bus part 1
 
Career development in exigen services
Career development in exigen servicesCareer development in exigen services
Career development in exigen services
 
Enterprise service bus part 2
Enterprise service bus part 2Enterprise service bus part 2
Enterprise service bus part 2
 
Enterprise Service Bus
Enterprise Service BusEnterprise Service Bus
Enterprise Service Bus
 
Apache cassandra - future without boundaries (part2)
Apache cassandra - future without boundaries (part2)Apache cassandra - future without boundaries (part2)
Apache cassandra - future without boundaries (part2)
 
Apache cassandra - future without boundaries (part3)
Apache cassandra - future without boundaries (part3)Apache cassandra - future without boundaries (part3)
Apache cassandra - future without boundaries (part3)
 
Anti patterns part 1
Anti patterns part 1Anti patterns part 1
Anti patterns part 1
 
Conflicts Resolving
Conflicts ResolvingConflicts Resolving
Conflicts Resolving
 

Similaire à Introduction to selenium web driver

25 Top Selenium Interview Questions and Answers for 2023.pdf
25 Top Selenium Interview Questions and Answers for 2023.pdf25 Top Selenium Interview Questions and Answers for 2023.pdf
25 Top Selenium Interview Questions and Answers for 2023.pdf
AnanthReddy38
 
Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...
Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...
Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...
Simplilearn
 
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...
Simplilearn
 
Best Selenium Online Training
Best Selenium Online TrainingBest Selenium Online Training
Best Selenium Online Training
Samatha Kamuni
 

Similaire à Introduction to selenium web driver (20)

Introduction to selenium web driver
Introduction to selenium web driverIntroduction to selenium web driver
Introduction to selenium web driver
 
selenium-webdriver-interview-questions.pdf
selenium-webdriver-interview-questions.pdfselenium-webdriver-interview-questions.pdf
selenium-webdriver-interview-questions.pdf
 
Getting started with Selenium 2
Getting started with Selenium 2Getting started with Selenium 2
Getting started with Selenium 2
 
Selenium WebDriver FAQ's
Selenium WebDriver FAQ'sSelenium WebDriver FAQ's
Selenium WebDriver FAQ's
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And Answers
 
25 Top Selenium Interview Questions and Answers for 2023.pdf
25 Top Selenium Interview Questions and Answers for 2023.pdf25 Top Selenium Interview Questions and Answers for 2023.pdf
25 Top Selenium Interview Questions and Answers for 2023.pdf
 
Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...
Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...
Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...
 
Selenium
SeleniumSelenium
Selenium
 
Selenium.pptx
Selenium.pptxSelenium.pptx
Selenium.pptx
 
Selenium RC - Web Application Testing Tool
Selenium RC - Web Application Testing ToolSelenium RC - Web Application Testing Tool
Selenium RC - Web Application Testing Tool
 
Selenium&amp;scrapy
Selenium&amp;scrapySelenium&amp;scrapy
Selenium&amp;scrapy
 
Selenium - Introduction
Selenium - IntroductionSelenium - Introduction
Selenium - Introduction
 
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...
 
Learn SELENIUM at ASIT
Learn SELENIUM at ASITLearn SELENIUM at ASIT
Learn SELENIUM at ASIT
 
Best Selenium Online Training
Best Selenium Online TrainingBest Selenium Online Training
Best Selenium Online Training
 
Selenium training
Selenium trainingSelenium training
Selenium training
 
Selenium Webdriver Interview Questions
Selenium Webdriver Interview QuestionsSelenium Webdriver Interview Questions
Selenium Webdriver Interview Questions
 
Selenium
SeleniumSelenium
Selenium
 
Top 15 Selenium WebDriver Interview Questions and Answers.pdf
Top 15 Selenium WebDriver Interview Questions and Answers.pdfTop 15 Selenium WebDriver Interview Questions and Answers.pdf
Top 15 Selenium WebDriver Interview Questions and Answers.pdf
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 

Plus de Return on Intelligence

Plus de Return on Intelligence (20)

Clean Code Approach
Clean Code ApproachClean Code Approach
Clean Code Approach
 
Code Coverage
Code CoverageCode Coverage
Code Coverage
 
Effective Communication in english
Effective Communication in englishEffective Communication in english
Effective Communication in english
 
Anti-patterns
Anti-patternsAnti-patterns
Anti-patterns
 
Database versioning with liquibase
Database versioning with liquibaseDatabase versioning with liquibase
Database versioning with liquibase
 
Effective Feedback
Effective FeedbackEffective Feedback
Effective Feedback
 
English for Negotiations 2016
English for Negotiations 2016English for Negotiations 2016
English for Negotiations 2016
 
Lean Software Development
Lean Software DevelopmentLean Software Development
Lean Software Development
 
Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!
 
Quick Start to AngularJS
Quick Start to AngularJSQuick Start to AngularJS
Quick Start to AngularJS
 
Introduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.jsIntroduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.js
 
Types of testing and their classification
Types of testing and their classificationTypes of testing and their classification
Types of testing and their classification
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
 
Apache cassandra - future without boundaries (part1)
Apache cassandra - future without boundaries (part1)Apache cassandra - future without boundaries (part1)
Apache cassandra - future without boundaries (part1)
 
Apache maven 2. advanced topics
Apache maven 2. advanced topicsApache maven 2. advanced topics
Apache maven 2. advanced topics
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
Jira as a test management tool
Jira as a test management toolJira as a test management tool
Jira as a test management tool
 
Testing your code
Testing your codeTesting your code
Testing your code
 
Quality Principles
Quality PrinciplesQuality Principles
Quality Principles
 
Cross cultural communication
Cross cultural communicationCross cultural communication
Cross cultural communication
 

Dernier

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Dernier (20)

WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration Tooling
 

Introduction to selenium web driver

  • 1. Introduction to Selenium Web 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 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
  • 4. 4 www.ExigenServices.com Components of Selenium • Selenium IDE • Selenium Remote Control (RC) • Selenium Grid • Selenium 2.0 and WebDriver
  • 5. 5 www.ExigenServices.com Selenium 1.0 Webdriver merge Selenium Webdriver 2.0 What is Selenium 2.0 ? IDE Selenium RC Selenium Grid
  • 6. 6 www.ExigenServices.com Autotests (Java, PHP, Phyton, Ruby, C#, …) Selenium RC Browsers Web-application HTTP Selenium 1.0 Architecture
  • 7. 7 www.ExigenServices.com Autotests Driver Browsers Web-application API to control the browser Selenium 2.0 Architecture
  • 8. 8 www.ExigenServices.com • 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 Advantages of Selenium 2.0
  • 9. 9 www.ExigenServices.com Disadvantages of Selenium 2.0 • Need to create own webdriver for each test environment • Only 4 programming languages are supported
  • 10. 10 www.ExigenServices.com WebDriver •HtmlUnit Driver •Firefox Driver •Internet Explorer Driver •Chrome Driver •Opera Driver •iPhone Driver •Android Driver WebDriver’s Drivers
  • 11. 11 www.ExigenServices.com Selenium API WebDriver – to control the browser WebElement – to work with the elements on the page WebDriver driver = new FirefoxDriver(); WebElement element = driver.findElement(By.id(“id”));
  • 12. 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
  • 13. 13 www.ExigenServices.com Selenium API: Find elements  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. 14 www.ExigenServices.com Selenium API: Find elements Tools for finding elements: 1. Firebug. Download firebug at http://getfirebug.com/ 2. Firefinder for Firebug
  • 15. 15 www.ExigenServices.com Selenium API: Find elements http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#selectors
  • 16. 16 www.ExigenServices.com Selenium API: Basic operations on elements  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 Selenium API: Waits Implicit Waits Explicit Waits
  • 18. 18 www.ExigenServices.com Working with windows  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 Create tests 1. Java http://java.com/ru/download 2. IDE 3. Library Selenium WebDriver http://seleniumhq.org/download/ 4. Firebug
  • 20. 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. 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. 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. 23 www.ExigenServices.com Create test public class Constants { public static final String txtRambler = "input[class='r--hat-form-text-input']"; }
  • 24. 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. 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(); }
  • 28. 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
  • 29. 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