SlideShare a Scribd company logo
1 of 57
Selenium: Test Automation of
      Web Application
 Weekend Workshop for QA professionals
          Trainer: Dipesh Bhatewara
             Date: 23rd June 2012


                                      trainings@digitalinfobytes.com
Introduction




               trainings@digitalinfobytes.com
                                            2
Why Test Automation




                 trainings@digitalinfobytes.com
                                              3
Advantages of Test Automation
• Frequent and quick regression testing
• Rapid feedback to developers
• Virtually unlimited iterations of test case
  execution
• Support for Agile and extreme development
  methodologies
• Increased test coverage
• Enables QA team to utilize bandwidth in
  exploratory testing.
                                      trainings@digitalinfobytes.com
                                                                   4
When to automate?
• Long projects – regression
• Frequent releases and extreme programming
• Quick feedback to developer – Sanity




                                 trainings@digitalinfobytes.com
                                                              5
Web Testing: Approaches
• GUI Automation
  – locating by coordinates
  – using generic OS mouse/keyboard events
  – suitable for any GUI app
• HTML/DOM Automation
  –   parsing HTML
  –   evaluating HTML elements (forms, input...)
  –   DOM as presentation of application
  –   DOM traversal
  –   interacting with DOM tree (target.dispatchEvent,...)
                                              trainings@digitalinfobytes.com
                                                                           6
Introduction to Selenium
•   Open Source Test Automation Framework
•   Developed by ThoughtWorks and Google
•   Robust set of tools for web-based applications
•   On multiple browsers
•   On multiple Operating Systems
•   Support many languages, including Ruby,
    Python, Java, c# and so on

                                      trainings@digitalinfobytes.com
                                                                   7
Selenium Components
•   Selenium IDE
•   Selenium RC
•   Selenium Grid
•   WebDriver (Selenium 2.0)




                               trainings@digitalinfobytes.com
                                                            8
Selenium IDE
• Firefox plug-in
• Integrated Development Environment for Selenium
  Tests.
• Provides record and playback functionality.
• Provides the ability to debug test scripts.
• Auto complete common selenium commands.
• Export tests in different formats like HTML, Java,
  Ruby, Python and so on.

                                         trainings@digitalinfobytes.com
                                                                      9
Installation
• Download IDE from -
  http://seleniumhq.org/download/
• Add as Add On to Firefox
• Launch it from Tools -> Selenium IDE




                                    trainings@digitalinfobytes.com
                                                                10
IDE explained

          • Record/Play
          • Test Case
          • Test Suite
          • Command -Target –
            Value
          • Export/Import



                 trainings@digitalinfobytes.com
                                             11
DEMO
• Click on Etsy logo and verify title
• Search for Vintage shoe and verify
  first item’s name
• Run as suite

                               trainings@digitalinfobytes.com
                                                           12
Assignment - IDE
•   Etsy.com
•   Navigate to Category – Furniture -> Chair
•   Click on the first item in the result list
•   Verify the item details page is displayed
•   Assert the Price of the product shown on this
    page


                                      trainings@digitalinfobytes.com
                                                                  13
Assignment IDE Test Suite
• Click on Kids section on left, on Kids page click
  on Tweet button, Switch to new window, Sign
  in with wrong username and password to
  twitter and check the Error.
• Click on ‘Accessories’ Category and test the
  pagination functionality
• Save the Test Suite
• Run as Test Suite
                                       trainings@digitalinfobytes.com
                                                                   14
Commonly Used Selenium
                Commands
Action Commands
• Open(Link) – This Command will open the specified page
• click(Locator) – This Command will Click at specified target
• check(Locator) – Toggles the checked value of a checkbox
• type(Locator, value) –Sends text input to an element
• select (Locator, value)– This will select the specified item in a list

Note: most action commands in Selenium IDE also have a duplicate
command with the AndWait suffix. When these are used the action
is performed and a page load is expected and the command will not
complete until the page has loaded or the timeout is reached.



                                                         trainings@digitalinfobytes.com
                                                                                     15
Commonly Used Selenium
               Commands
Store, Check, and Wait
• isElementPreset(locator) – Checks if an element is present on the
   page
• store(expression, variableName) – Allows you to temporarily store
   a value
• verify(pattern) – performs verification and skip execution, if fails.
• assert(pattern) – performs verification and stop execution, if fails.
• waitFor(pattern) – Waits until the value matches the specified
   value or the timeout.

Note: These Commands are heart of Selenium ,as these deal with
verifiacation and validation part. There are variations available in
these commands eg. waitForPageToLoad(), waitForPopUp()

                                                      trainings@digitalinfobytes.com
                                                                                  16
Object Identification
• Using HTML properties of the Object
  – Name
  – Id
  – Class
• Using Xpaths (DOM address)
  – XPath is a language for finding information in an
    XML document


                                         trainings@digitalinfobytes.com
                                                                     17
Xpath Explained




                  trainings@digitalinfobytes.com
                                              18
FireBug installation & DEMO




                     trainings@digitalinfobytes.com
                                                 19
Assignment
• Etsy.com
• Find Unique HTML Ids as well as Xpaths for
  below
  – Regsiter Button
  – Search text box
  – Fashion link
  – 3rd Item in second row on home page


                                      trainings@digitalinfobytes.com
                                                                  20
Handy tool for Xpaths
• Fire Path (Lets use this)
• Xpather




                              trainings@digitalinfobytes.com
                                                          21
OOPS Concepts
•   Objects
•   Classes
•   Data abstraction
•   Inheritance
•   Polymorphism



                              trainings@digitalinfobytes.com
                                                          22
Sample Java Program




                 trainings@digitalinfobytes.com
                                             23
Selenium RC
• A server, written in Java and so available on all
  the platforms.
• Acts as a proxy for web requests from tests.
• Client libraries for many popular languages.
• Bundles Selenium Core and automatically
  loads into the browser


                                      trainings@digitalinfobytes.com
                                                                  24
Selenium RC components
• Selenium Server: launches and kills browsers,
  interprets and runs the Selenese commands
  passed from the test program, and acts as an
  HTTP proxy, intercepting and verifying HTTP
  messages passed between the browser and
  the AUT.
• Client Libraries: provide the interface
  between each programming language and the
  Selenium RC Server.
                                    trainings@digitalinfobytes.com
                                                                25
trainings@digitalinfobytes.com
                            26
Install & Start
• Ensure that JDK is present on the machine and
  is in the class path.
• Downloaded Selenium RC from
  http://seleniumhq.org/download/
• Unzip to any directory on your file system.
• Change directory to the Selenium Server on
  the command line or terminal.
• Start Selenium Server.
                                   trainings@digitalinfobytes.com
                                                               27
Change Directory to Selenium Server




                    Start selenium Server



                                trainings@digitalinfobytes.com
                                                            28
Eclipse and Project setup
• Launch Eclipse
• Create Java project
• Import selenium-client library
• Add JUnit plugin to eclipse
• Export the code of your Selenium IDE
  assignment as Selenium RC Junit4 code
• Add the exported java file to the project and
  run
                                     trainings@digitalinfobytes.com
                                                                 29
Handling different types of elements
              & Demo
•   Text Box
•   List
•   Check Box
•   Radio Buttons




                           trainings@digitalinfobytes.com
                                                       30
Assignment
• Create a fresh project in Eclipse
• Add a test case to register a new user at
  Etsy.com




                                     trainings@digitalinfobytes.com
                                                                 31
More Assignments
• Test User Sign In – Valid & Error
• Test Add To Cart and verify the country can be
  changed on the cart page.
• Run them as suite from Eclipse




                                    trainings@digitalinfobytes.com
                                                                32
End of Day 1




               trainings@digitalinfobytes.com
                                           33
Day 2




        trainings@digitalinfobytes.com
                                    34
History

 2004        2007      2009    2011



Selenium   WebDriver

                          Selenium2



                                  trainings@digitalinfobytes.com
                                                              35
WebDriver
• Is a Self Contained Library
• Uses browser capabilities over injected javascripts
• “Best fit” technology
• Clean & Object Oriented API
• Easy to maintain
• Faster than Selenium 1
• Tightly bound to the browser, no need of Selenium
  Server
• Bindings : Java, C#, Python, Ruby
• Android and iPhone support
                                           trainings@digitalinfobytes.com
                                                                       36
Selenium Server in Selenium2
• Replicate Selenium RC functionalities
• Remote WebDriver
• Selenium Grid 2




                                    trainings@digitalinfobytes.com
                                                                37
WebDriver

WebDriver Interface

          Internet             HTML
Firefox              Chrome             Opera    Andriod       iPhone
          Explorer              Unit
Driver                Driver            Driver    Driver        Driver
           Driver              Driver




                                                     trainings@digitalinfobytes.com
                                                                                 38
“BestFit”s
• Internet Explorer Driver accesses the browser via the COM
  layer using some automation hooks that Microsoft have put
  there and maintain. The core code is written in C++.

• FirefoxDriver is a Firefox addon that accesses items at the
  Chrome layer

• ChromeDriver is a Chrome Extension that allows drive
  Chrome.

• The Android driver is an APK that allows us to drive the
  Web View and the same with iPhone

                                                trainings@digitalinfobytes.com
                                                                            39
WebDriver




            trainings@digitalinfobytes.com
                                        40
Sample Code for Demonstration




                      trainings@digitalinfobytes.com
                                                  41
Let’s setup a project
• Download
• New Project
• Import selenium jar
• Add class imported from IDE (as Junit4
  Webdriver)
• Run the tests



                                    trainings@digitalinfobytes.com
                                                                42
Assignment – Import Class From IDE
             and Run




                         trainings@digitalinfobytes.com
                                                     43
Let’s code
• Add a new test class to test Etsy.com
• Launch the site




                                     trainings@digitalinfobytes.com
                                                                 44
Locator Strategies
• ID
    – webDriver.findElement(By.id("logo"));
• Name
    – webDriver.findElement(By.name("q"));
• Tag Name
    – webDriver.findElement(By.tagName("H1"));
• Class name
    – webDriver.findElements(By.className("sponsor_logos"));
• XPath
    – webDriver.findElement(By.xpath("//section*@id=‘miniconfs’+/a*2+"));
• Link Text
    – webDriver.findElements(By.linkText("About"));
• Partial Link Text
    – webDriver.findElement(By.partialLinkText("visitcanberra"));

                                                           trainings@digitalinfobytes.com
                                                                                       45
Page Interactions
•   webElement.click()
•   webElement.sendKeys(...)
•   webElement.submit()
•   Actions class -> Mouse Events / Drag and Drop




                                     trainings@digitalinfobytes.com
                                                                 46
Demo of Etsy Registration with
           Firefox




                        trainings@digitalinfobytes.com
                                                    47
Assignment




             trainings@digitalinfobytes.com
                                         48
Demo: Run Same Test On Different
           Browser




                        trainings@digitalinfobytes.com
                                                    49
Assignment: Run earlier assignment
       on another browser




                         trainings@digitalinfobytes.com
                                                     50
Pop-up/Alert handling
• Pop up window
  – driver.switchTo().window(windowHan
    dle);
• Alerts
  – alert = driver.switchTo().alert();
  – alert.Accept();
  – alert.Dismiss();


                             trainings@digitalinfobytes.com
                                                         51
Sample Code




              trainings@digitalinfobytes.com
                                          52
Demo
• http://www.blazonry.com/javascript/windows
  .php




                                 trainings@digitalinfobytes.com
                                                             53
Assignment




             trainings@digitalinfobytes.com
                                         54
Additional useful commands
• Polling the DOM for N seconds
   – webDriver.manage().timeouts().implicitlyWai
     t(30, TimeUnit.SECONDS);
• Testing CSS properties
   – webElement.getCssValue(“height”);
• Javascript execution
   – JavascriptExecutor js =
     (JavascriptExecutor) webDriver;
   – Long value = (Long)
     js.executeScript("return window.scrollY");
• Navigation
   – Navigation nav = webDriver.navigate();
   – nav.back(); / nav.forward(); nav.to(“url”);


                                         trainings@digitalinfobytes.com
                                                                     55
Backward Compatibility with
             Selenium 1
Selenium selenium = new
WebDriverBackedSelenium(webDriver,
“http://osdc.com.au”);

selenium.open("http://osdc.com.au");

selenium.click("id=follow_twitter");

selenium.waitForPageToLoad("10000");

WebDriver webDriver =
((WebDriverBackedSelenium)
selenium).getUnderlyingWebDriver();
                                     trainings@digitalinfobytes.com
                                                                 56
Reference Sites
• Xpath
  – http://hedleyproctor.com/2011/05/tutorial-
    writing-xpath-selectors-for-selenium-tests/




                                        trainings@digitalinfobytes.com
                                                                    57

More Related Content

What's hot

Selenium WebDriver with Java
Selenium WebDriver with JavaSelenium WebDriver with Java
Selenium WebDriver with JavaFayis-QA
 
Selenium Webdriver Interview Questions
Selenium Webdriver Interview QuestionsSelenium Webdriver Interview Questions
Selenium Webdriver Interview QuestionsJai Singh
 
Selenium using Java
Selenium using JavaSelenium using Java
Selenium using JavaF K
 
Automation Testing using Selenium Webdriver
Automation Testing using Selenium WebdriverAutomation Testing using Selenium Webdriver
Automation Testing using Selenium WebdriverPankaj Biswas
 
Testing Java Web Apps With Selenium
Testing Java Web Apps With SeleniumTesting Java Web Apps With Selenium
Testing Java Web Apps With SeleniumMarakana Inc.
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupDave Haeffner
 
Selenium 2 - PyCon 2011
Selenium 2 - PyCon 2011Selenium 2 - PyCon 2011
Selenium 2 - PyCon 2011hugs
 
Introduction to Selenium
Introduction to SeleniumIntroduction to Selenium
Introduction to Seleniumrohitnayak
 
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...Edureka!
 
Practical Tips & Tricks for Selenium Test Automation - Dave Haeffner
Practical Tips & Tricks for Selenium Test Automation - Dave HaeffnerPractical Tips & Tricks for Selenium Test Automation - Dave Haeffner
Practical Tips & Tricks for Selenium Test Automation - Dave HaeffnerApplitools
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium SuccessfullyDave Haeffner
 
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...Applitools
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with SeleniumDave Haeffner
 
Interview question & Answers for 3+ years experienced in Selenium | LearningSlot
Interview question & Answers for 3+ years experienced in Selenium | LearningSlotInterview question & Answers for 3+ years experienced in Selenium | LearningSlot
Interview question & Answers for 3+ years experienced in Selenium | LearningSlotLearning Slot
 

What's hot (20)

Selenium WebDriver with Java
Selenium WebDriver with JavaSelenium WebDriver with Java
Selenium WebDriver with Java
 
Selenium Webdriver Interview Questions
Selenium Webdriver Interview QuestionsSelenium Webdriver Interview Questions
Selenium Webdriver Interview Questions
 
Selenium using Java
Selenium using JavaSelenium using Java
Selenium using Java
 
Automation Testing using Selenium Webdriver
Automation Testing using Selenium WebdriverAutomation Testing using Selenium Webdriver
Automation Testing using Selenium Webdriver
 
Testing Java Web Apps With Selenium
Testing Java Web Apps With SeleniumTesting Java Web Apps With Selenium
Testing Java Web Apps With Selenium
 
Automation Testing by Selenium Web Driver
Automation Testing by Selenium Web DriverAutomation Testing by Selenium Web Driver
Automation Testing by Selenium Web Driver
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
 
Selenium 2 - PyCon 2011
Selenium 2 - PyCon 2011Selenium 2 - PyCon 2011
Selenium 2 - PyCon 2011
 
Selenium with java
Selenium with javaSelenium with java
Selenium with java
 
Introduction to Selenium
Introduction to SeleniumIntroduction to Selenium
Introduction to Selenium
 
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...
 
Practical Tips & Tricks for Selenium Test Automation - Dave Haeffner
Practical Tips & Tricks for Selenium Test Automation - Dave HaeffnerPractical Tips & Tricks for Selenium Test Automation - Dave Haeffner
Practical Tips & Tricks for Selenium Test Automation - Dave Haeffner
 
Selenium presentation
Selenium presentationSelenium presentation
Selenium presentation
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
 
Selenium Handbook
Selenium HandbookSelenium Handbook
Selenium Handbook
 
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with Selenium
 
Interview question & Answers for 3+ years experienced in Selenium | LearningSlot
Interview question & Answers for 3+ years experienced in Selenium | LearningSlotInterview question & Answers for 3+ years experienced in Selenium | LearningSlot
Interview question & Answers for 3+ years experienced in Selenium | LearningSlot
 

Viewers also liked

Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using SeleniumNaresh Chintalcheru
 
White-box Unit Test Generation with Microsoft IntelliTest
White-box Unit Test Generation with Microsoft IntelliTestWhite-box Unit Test Generation with Microsoft IntelliTest
White-box Unit Test Generation with Microsoft IntelliTestDávid Honfi
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchMats Bryntse
 
A Buffer's Guide to Selenium 2
A Buffer's Guide to Selenium 2A Buffer's Guide to Selenium 2
A Buffer's Guide to Selenium 2onlinemindq
 
SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...
SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...
SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...Sencha
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testingmalcolmt
 
Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016vodqasg
 
Automated Tests in Agile based on Serenity BDD - Michał Szybalski
Automated Tests in Agile based on Serenity BDD - Michał SzybalskiAutomated Tests in Agile based on Serenity BDD - Michał Szybalski
Automated Tests in Agile based on Serenity BDD - Michał SzybalskiŁódQA
 
Test Automation Frameworks: Assumptions, Concepts & Tools
Test Automation Frameworks: Assumptions, Concepts & ToolsTest Automation Frameworks: Assumptions, Concepts & Tools
Test Automation Frameworks: Assumptions, Concepts & ToolsAmit Rawat
 
Serenity BDD - from executable specifications to living documentation
Serenity BDD - from executable specifications to living documentationSerenity BDD - from executable specifications to living documentation
Serenity BDD - from executable specifications to living documentationAlex Soto
 
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...Sencha
 

Viewers also liked (19)

Introduction to Selenium Web Driver
Introduction to Selenium Web DriverIntroduction to Selenium Web Driver
Introduction to Selenium Web Driver
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
 
White-box Unit Test Generation with Microsoft IntelliTest
White-box Unit Test Generation with Microsoft IntelliTestWhite-box Unit Test Generation with Microsoft IntelliTest
White-box Unit Test Generation with Microsoft IntelliTest
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
 
A Buffer's Guide to Selenium 2
A Buffer's Guide to Selenium 2A Buffer's Guide to Selenium 2
A Buffer's Guide to Selenium 2
 
test generation
test generationtest generation
test generation
 
SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...
SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...
SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testing
 
Selenium basic
Selenium basicSelenium basic
Selenium basic
 
Selenium topic 1- Selenium Basic
Selenium topic 1-  Selenium BasicSelenium topic 1-  Selenium Basic
Selenium topic 1- Selenium Basic
 
Python in Test automation
Python in Test automationPython in Test automation
Python in Test automation
 
BDD in Automation Testing
BDD in Automation TestingBDD in Automation Testing
BDD in Automation Testing
 
Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016
 
Automated Tests in Agile based on Serenity BDD - Michał Szybalski
Automated Tests in Agile based on Serenity BDD - Michał SzybalskiAutomated Tests in Agile based on Serenity BDD - Michał Szybalski
Automated Tests in Agile based on Serenity BDD - Michał Szybalski
 
Test Automation Frameworks: Assumptions, Concepts & Tools
Test Automation Frameworks: Assumptions, Concepts & ToolsTest Automation Frameworks: Assumptions, Concepts & Tools
Test Automation Frameworks: Assumptions, Concepts & Tools
 
Selenium
SeleniumSelenium
Selenium
 
Serenity BDD - from executable specifications to living documentation
Serenity BDD - from executable specifications to living documentationSerenity BDD - from executable specifications to living documentation
Serenity BDD - from executable specifications to living documentation
 
Ui BDD Testing
Ui BDD TestingUi BDD Testing
Ui BDD Testing
 
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
 

Similar to Basic Selenium Training

How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfullyTEST Huddle
 
Selenium for everyone
Selenium for everyoneSelenium for everyone
Selenium for everyoneTft Us
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)Dave Haeffner
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Applitools
 
Selenium web driver_2.0_presentation
Selenium web driver_2.0_presentationSelenium web driver_2.0_presentation
Selenium web driver_2.0_presentationsayhi2sudarshan
 
Team Development on Force.com
Team Development on Force.comTeam Development on Force.com
Team Development on Force.comDaniel Hoechst
 
Automated Acceptance Testing from Scratch
Automated Acceptance Testing from ScratchAutomated Acceptance Testing from Scratch
Automated Acceptance Testing from ScratchExcella
 
Test Automation with Twist and Sahi
Test Automation with Twist and SahiTest Automation with Twist and Sahi
Test Automation with Twist and Sahiericjamesblackburn
 
Selenium rc ppt
Selenium rc pptSelenium rc ppt
Selenium rc pptmindqqa
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium SuccessfullyDave Haeffner
 
Selenium training
Selenium trainingSelenium training
Selenium trainingShivaraj R
 
Beginners overview of automated testing with Rspec
Beginners overview of automated testing with RspecBeginners overview of automated testing with Rspec
Beginners overview of automated testing with Rspecjeffrey1ross
 
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan KuštInfinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan KuštInfinum
 
Test_Automation using Selenium.ppt
Test_Automation using Selenium.pptTest_Automation using Selenium.ppt
Test_Automation using Selenium.pptSamKhan531862
 
Karate _Framework.ppt
Karate _Framework.pptKarate _Framework.ppt
Karate _Framework.pptSamKhan531862
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)Sauce Labs
 
Big datatraining.in devops-part1
Big datatraining.in devops-part1Big datatraining.in devops-part1
Big datatraining.in devops-part1MvkZ
 
Big datatraining.in devops-part1
Big datatraining.in devops-part1Big datatraining.in devops-part1
Big datatraining.in devops-part1sKaushikNarayanan
 

Similar to Basic Selenium Training (20)

How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
 
Selenium for everyone
Selenium for everyoneSelenium for everyone
Selenium for everyone
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)
 
Automated ui-testing
Automated ui-testingAutomated ui-testing
Automated ui-testing
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully
 
Selenium web driver_2.0_presentation
Selenium web driver_2.0_presentationSelenium web driver_2.0_presentation
Selenium web driver_2.0_presentation
 
Team Development on Force.com
Team Development on Force.comTeam Development on Force.com
Team Development on Force.com
 
Automated Acceptance Testing from Scratch
Automated Acceptance Testing from ScratchAutomated Acceptance Testing from Scratch
Automated Acceptance Testing from Scratch
 
Test Automation with Twist and Sahi
Test Automation with Twist and SahiTest Automation with Twist and Sahi
Test Automation with Twist and Sahi
 
Selenium rc ppt
Selenium rc pptSelenium rc ppt
Selenium rc ppt
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
 
Continuous feature-development
Continuous feature-developmentContinuous feature-development
Continuous feature-development
 
Selenium training
Selenium trainingSelenium training
Selenium training
 
Beginners overview of automated testing with Rspec
Beginners overview of automated testing with RspecBeginners overview of automated testing with Rspec
Beginners overview of automated testing with Rspec
 
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan KuštInfinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
 
Test_Automation using Selenium.ppt
Test_Automation using Selenium.pptTest_Automation using Selenium.ppt
Test_Automation using Selenium.ppt
 
Karate _Framework.ppt
Karate _Framework.pptKarate _Framework.ppt
Karate _Framework.ppt
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)
 
Big datatraining.in devops-part1
Big datatraining.in devops-part1Big datatraining.in devops-part1
Big datatraining.in devops-part1
 
Big datatraining.in devops-part1
Big datatraining.in devops-part1Big datatraining.in devops-part1
Big datatraining.in devops-part1
 

Recently uploaded

A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 

Recently uploaded (20)

A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 

Basic Selenium Training

  • 1. Selenium: Test Automation of Web Application Weekend Workshop for QA professionals Trainer: Dipesh Bhatewara Date: 23rd June 2012 trainings@digitalinfobytes.com
  • 2. Introduction trainings@digitalinfobytes.com 2
  • 3. Why Test Automation trainings@digitalinfobytes.com 3
  • 4. Advantages of Test Automation • Frequent and quick regression testing • Rapid feedback to developers • Virtually unlimited iterations of test case execution • Support for Agile and extreme development methodologies • Increased test coverage • Enables QA team to utilize bandwidth in exploratory testing. trainings@digitalinfobytes.com 4
  • 5. When to automate? • Long projects – regression • Frequent releases and extreme programming • Quick feedback to developer – Sanity trainings@digitalinfobytes.com 5
  • 6. Web Testing: Approaches • GUI Automation – locating by coordinates – using generic OS mouse/keyboard events – suitable for any GUI app • HTML/DOM Automation – parsing HTML – evaluating HTML elements (forms, input...) – DOM as presentation of application – DOM traversal – interacting with DOM tree (target.dispatchEvent,...) trainings@digitalinfobytes.com 6
  • 7. Introduction to Selenium • Open Source Test Automation Framework • Developed by ThoughtWorks and Google • Robust set of tools for web-based applications • On multiple browsers • On multiple Operating Systems • Support many languages, including Ruby, Python, Java, c# and so on trainings@digitalinfobytes.com 7
  • 8. Selenium Components • Selenium IDE • Selenium RC • Selenium Grid • WebDriver (Selenium 2.0) trainings@digitalinfobytes.com 8
  • 9. Selenium IDE • Firefox plug-in • Integrated Development Environment for Selenium Tests. • Provides record and playback functionality. • Provides the ability to debug test scripts. • Auto complete common selenium commands. • Export tests in different formats like HTML, Java, Ruby, Python and so on. trainings@digitalinfobytes.com 9
  • 10. Installation • Download IDE from - http://seleniumhq.org/download/ • Add as Add On to Firefox • Launch it from Tools -> Selenium IDE trainings@digitalinfobytes.com 10
  • 11. IDE explained • Record/Play • Test Case • Test Suite • Command -Target – Value • Export/Import trainings@digitalinfobytes.com 11
  • 12. DEMO • Click on Etsy logo and verify title • Search for Vintage shoe and verify first item’s name • Run as suite trainings@digitalinfobytes.com 12
  • 13. Assignment - IDE • Etsy.com • Navigate to Category – Furniture -> Chair • Click on the first item in the result list • Verify the item details page is displayed • Assert the Price of the product shown on this page trainings@digitalinfobytes.com 13
  • 14. Assignment IDE Test Suite • Click on Kids section on left, on Kids page click on Tweet button, Switch to new window, Sign in with wrong username and password to twitter and check the Error. • Click on ‘Accessories’ Category and test the pagination functionality • Save the Test Suite • Run as Test Suite trainings@digitalinfobytes.com 14
  • 15. Commonly Used Selenium Commands Action Commands • Open(Link) – This Command will open the specified page • click(Locator) – This Command will Click at specified target • check(Locator) – Toggles the checked value of a checkbox • type(Locator, value) –Sends text input to an element • select (Locator, value)– This will select the specified item in a list Note: most action commands in Selenium IDE also have a duplicate command with the AndWait suffix. When these are used the action is performed and a page load is expected and the command will not complete until the page has loaded or the timeout is reached. trainings@digitalinfobytes.com 15
  • 16. Commonly Used Selenium Commands Store, Check, and Wait • isElementPreset(locator) – Checks if an element is present on the page • store(expression, variableName) – Allows you to temporarily store a value • verify(pattern) – performs verification and skip execution, if fails. • assert(pattern) – performs verification and stop execution, if fails. • waitFor(pattern) – Waits until the value matches the specified value or the timeout. Note: These Commands are heart of Selenium ,as these deal with verifiacation and validation part. There are variations available in these commands eg. waitForPageToLoad(), waitForPopUp() trainings@digitalinfobytes.com 16
  • 17. Object Identification • Using HTML properties of the Object – Name – Id – Class • Using Xpaths (DOM address) – XPath is a language for finding information in an XML document trainings@digitalinfobytes.com 17
  • 18. Xpath Explained trainings@digitalinfobytes.com 18
  • 19. FireBug installation & DEMO trainings@digitalinfobytes.com 19
  • 20. Assignment • Etsy.com • Find Unique HTML Ids as well as Xpaths for below – Regsiter Button – Search text box – Fashion link – 3rd Item in second row on home page trainings@digitalinfobytes.com 20
  • 21. Handy tool for Xpaths • Fire Path (Lets use this) • Xpather trainings@digitalinfobytes.com 21
  • 22. OOPS Concepts • Objects • Classes • Data abstraction • Inheritance • Polymorphism trainings@digitalinfobytes.com 22
  • 23. Sample Java Program trainings@digitalinfobytes.com 23
  • 24. Selenium RC • A server, written in Java and so available on all the platforms. • Acts as a proxy for web requests from tests. • Client libraries for many popular languages. • Bundles Selenium Core and automatically loads into the browser trainings@digitalinfobytes.com 24
  • 25. Selenium RC components • Selenium Server: launches and kills browsers, interprets and runs the Selenese commands passed from the test program, and acts as an HTTP proxy, intercepting and verifying HTTP messages passed between the browser and the AUT. • Client Libraries: provide the interface between each programming language and the Selenium RC Server. trainings@digitalinfobytes.com 25
  • 27. Install & Start • Ensure that JDK is present on the machine and is in the class path. • Downloaded Selenium RC from http://seleniumhq.org/download/ • Unzip to any directory on your file system. • Change directory to the Selenium Server on the command line or terminal. • Start Selenium Server. trainings@digitalinfobytes.com 27
  • 28. Change Directory to Selenium Server Start selenium Server trainings@digitalinfobytes.com 28
  • 29. Eclipse and Project setup • Launch Eclipse • Create Java project • Import selenium-client library • Add JUnit plugin to eclipse • Export the code of your Selenium IDE assignment as Selenium RC Junit4 code • Add the exported java file to the project and run trainings@digitalinfobytes.com 29
  • 30. Handling different types of elements & Demo • Text Box • List • Check Box • Radio Buttons trainings@digitalinfobytes.com 30
  • 31. Assignment • Create a fresh project in Eclipse • Add a test case to register a new user at Etsy.com trainings@digitalinfobytes.com 31
  • 32. More Assignments • Test User Sign In – Valid & Error • Test Add To Cart and verify the country can be changed on the cart page. • Run them as suite from Eclipse trainings@digitalinfobytes.com 32
  • 33. End of Day 1 trainings@digitalinfobytes.com 33
  • 34. Day 2 trainings@digitalinfobytes.com 34
  • 35. History 2004 2007 2009 2011 Selenium WebDriver Selenium2 trainings@digitalinfobytes.com 35
  • 36. WebDriver • Is a Self Contained Library • Uses browser capabilities over injected javascripts • “Best fit” technology • Clean & Object Oriented API • Easy to maintain • Faster than Selenium 1 • Tightly bound to the browser, no need of Selenium Server • Bindings : Java, C#, Python, Ruby • Android and iPhone support trainings@digitalinfobytes.com 36
  • 37. Selenium Server in Selenium2 • Replicate Selenium RC functionalities • Remote WebDriver • Selenium Grid 2 trainings@digitalinfobytes.com 37
  • 38. WebDriver WebDriver Interface Internet HTML Firefox Chrome Opera Andriod iPhone Explorer Unit Driver Driver Driver Driver Driver Driver Driver trainings@digitalinfobytes.com 38
  • 39. “BestFit”s • Internet Explorer Driver accesses the browser via the COM layer using some automation hooks that Microsoft have put there and maintain. The core code is written in C++. • FirefoxDriver is a Firefox addon that accesses items at the Chrome layer • ChromeDriver is a Chrome Extension that allows drive Chrome. • The Android driver is an APK that allows us to drive the Web View and the same with iPhone trainings@digitalinfobytes.com 39
  • 40. WebDriver trainings@digitalinfobytes.com 40
  • 41. Sample Code for Demonstration trainings@digitalinfobytes.com 41
  • 42. Let’s setup a project • Download • New Project • Import selenium jar • Add class imported from IDE (as Junit4 Webdriver) • Run the tests trainings@digitalinfobytes.com 42
  • 43. Assignment – Import Class From IDE and Run trainings@digitalinfobytes.com 43
  • 44. Let’s code • Add a new test class to test Etsy.com • Launch the site trainings@digitalinfobytes.com 44
  • 45. Locator Strategies • ID – webDriver.findElement(By.id("logo")); • Name – webDriver.findElement(By.name("q")); • Tag Name – webDriver.findElement(By.tagName("H1")); • Class name – webDriver.findElements(By.className("sponsor_logos")); • XPath – webDriver.findElement(By.xpath("//section*@id=‘miniconfs’+/a*2+")); • Link Text – webDriver.findElements(By.linkText("About")); • Partial Link Text – webDriver.findElement(By.partialLinkText("visitcanberra")); trainings@digitalinfobytes.com 45
  • 46. Page Interactions • webElement.click() • webElement.sendKeys(...) • webElement.submit() • Actions class -> Mouse Events / Drag and Drop trainings@digitalinfobytes.com 46
  • 47. Demo of Etsy Registration with Firefox trainings@digitalinfobytes.com 47
  • 48. Assignment trainings@digitalinfobytes.com 48
  • 49. Demo: Run Same Test On Different Browser trainings@digitalinfobytes.com 49
  • 50. Assignment: Run earlier assignment on another browser trainings@digitalinfobytes.com 50
  • 51. Pop-up/Alert handling • Pop up window – driver.switchTo().window(windowHan dle); • Alerts – alert = driver.switchTo().alert(); – alert.Accept(); – alert.Dismiss(); trainings@digitalinfobytes.com 51
  • 52. Sample Code trainings@digitalinfobytes.com 52
  • 53. Demo • http://www.blazonry.com/javascript/windows .php trainings@digitalinfobytes.com 53
  • 54. Assignment trainings@digitalinfobytes.com 54
  • 55. Additional useful commands • Polling the DOM for N seconds – webDriver.manage().timeouts().implicitlyWai t(30, TimeUnit.SECONDS); • Testing CSS properties – webElement.getCssValue(“height”); • Javascript execution – JavascriptExecutor js = (JavascriptExecutor) webDriver; – Long value = (Long) js.executeScript("return window.scrollY"); • Navigation – Navigation nav = webDriver.navigate(); – nav.back(); / nav.forward(); nav.to(“url”); trainings@digitalinfobytes.com 55
  • 56. Backward Compatibility with Selenium 1 Selenium selenium = new WebDriverBackedSelenium(webDriver, “http://osdc.com.au”); selenium.open("http://osdc.com.au"); selenium.click("id=follow_twitter"); selenium.waitForPageToLoad("10000"); WebDriver webDriver = ((WebDriverBackedSelenium) selenium).getUnderlyingWebDriver(); trainings@digitalinfobytes.com 56
  • 57. Reference Sites • Xpath – http://hedleyproctor.com/2011/05/tutorial- writing-xpath-selectors-for-selenium-tests/ trainings@digitalinfobytes.com 57