SlideShare a Scribd company logo
1 of 32
Connect. Collaborate. Innovate.




                               Web Application Testing
                                  using Selenium


                                      Amit Saxena
                                      17/08/2011



© Copyright GlobalLogic 2010                                                    1
Web Application Testing using Selenium                Connect. Collaborate. Innovate.




    Training Agenda:
              Selenium Introduction
              Selenium Components
              Recording & Testing with Selenium IDE
              Exercise 1 – Selenium IDE
              Testing using Selenium RC
              Exercise 2 – Selenium RC
              Parallel testing using Selenium Grid




© Copyright GlobalLogic 2010                                                             2
Selenium – What is it?                                Connect. Collaborate. Innovate.




    • Selenium is a set of tools to automate web application testing
    across many platforms.
    • Selenium runs in many browsers and operating systems.
    • Selenium can be controlled by many programming languages and
    testing frameworks.
    • Selenium is highly flexible.
    • Selenium is an Open Source project. The code can be modified and
    enhancements can be submitted for contribution.




© Copyright GlobalLogic 2010                                                            3
Selenium Components                                       Connect. Collaborate. Innovate.




         Selenium IDE - is a Firefox add-on that records
        clicks, typing, and other actions to make a test, which you
        can play back in the browser.
         Selenium RC - runs your tests in multiple browsers and
        platforms. Tweak/Customize your tests in your preferred
        programming language.
         Selenium Grid - extends Selenium RC to distribute
        your tests across multiple servers, saving you time by
        running tests in parallel.




© Copyright GlobalLogic 2010                                                                4
Selenium Components…           Connect. Collaborate. Innovate.




© Copyright GlobalLogic 2010                                     5
Platforms Supported by Selenium   Connect. Collaborate. Innovate.




© Copyright GlobalLogic 2010                                        6
Connect. Collaborate. Innovate.
Selenium Commands – Selenese

          Selenium commands come in three “flavors”: Actions, Accessors and
          Assertions.


          Actions are commands that generally manipulate the state of the application. They do things
          like “click this link” and “select that option”. If an Action fails, or has an error, the execution of the
          current test is stopped.

          Accessors examine the state of the application and store the results in variables, e.g.
          “storeTitle”. They are also used to automatically generate Assertions.

          Assertions are like Accessors, but they verify that the state of the application conforms to what
          is expected. Examples include “make sure the page title is X” and “verify that this checkbox is
          checked”.
          All Selenium Assertions can be used in 3 modes:

          Assert – Upon failure test is aborted
          Verify – Upon failure error is logged and test continues
          WaitFor – Waits for a conditions for a given timeout




© Copyright GlobalLogic 2010                                                                                                            7
Connect. Collaborate. Innovate.
Selenium Scripts Syntax


    Selenium commands are simple, they consist of the command and two parameters.
    For example:

        type                         id=phone                      (555) 666-7066

       Parameters vary, however they are typically:
       a locator for identifying a UI element within a page.
       a text pattern for verifying or asserting expected page content
       a text pattern or a selenium variable for entering text in an input field or for selecting
       an option from an option list.




© Copyright GlobalLogic 2010                                                                                                          8
Commonly Used Selenium Commands                                                Connect. Collaborate. Innovate.




 open
       opens a page using a URL.
 click/clickAndWait
       performs a click operation, and optionally waits for a new page to load.
 verifyTitle/assertTitle
       verifies an expected page title.
 verifyTextPresent
       verifies expected text is somewhere on the page.
 verifyElementPresent
       verifies an expected UI element, as defined by its HTML tag, is present on the page.
 verifyText
       verifies expected text and it’s corresponding HTML tag are present on the page.
 verifyTable
       verifies a table’s expected contents.
 waitForPageToLoad
       pauses execution until an expected new page loads. Called automatically when clickAndWait is used.
 waitForElementPresent
       pauses execution until an expected UI element, as defined by its HTML tag, is present on the page.




© Copyright GlobalLogic 2010                                                                                     9
Locating Elements                                                                               Connect. Collaborate. Innovate.




  For many Selenium commands, a target is required. This target identifies an element in the
  content of the web application, and consists of the location strategy. Some of the location
  strategies using in Selenium are:
     Locating by Identifier
     This is probably the most common method of locating elements and is the catch-all default when no
     recognized locator type is used. With this strategy, the first element with the id attribute value matching the
     location will be used. If no element has a matching id attribute, then the first element with a name attribute
     matching the location will be used.
     Locating by Id
     This type of locator is more limited than the identifier locator type, but also more explicit. Use this when
     you know an element’s id attribute.
     Locating by Name
     The name locator type will locate the first element with a matching name attribute.
     Locating by XPath
     XPath is the language used for locating nodes in an XML document. As HTML can be an implementation of
     XML (XHTML), Selenium users can leverage this powerful language to target elements in their web
     applications. One of the main reasons for using XPath is when you don’t have a suitable id or name attribute
     for the element you wish to locate. You can use XPath to either locate the element in absolute terms (not
     advised), or relative to an element that does have an id or name attribute.




© Copyright GlobalLogic 2010                                                                                                      10
Selenium IDE                                                          Connect. Collaborate. Innovate.




    Selenium IDE is an integrated development environment for Selenium
    scripts. It is implemented as a Firefox extension, and allows you to
    record, edit, and debug tests.

       Features:
       •Easy record and playback
       •Intelligent field selection will use IDs, names, or XPath as needed
       •Autocomplete for all common Selenium commands
       •Walk through tests
       •Debug and set breakpoints
       •Save tests as Html, Java, .NET, Php, Perl, Ruby scripts etc.
       •Support for Selenium user-extensions.js file




© Copyright GlobalLogic 2010                                                                            11
Selenium IDE Installation                                        Connect. Collaborate. Innovate.




Selenium IDE is installed as a Firefox extension. It can be installed directly within
Firefox by going to http://seleniumhq.org/download/ and downloading
http://release.seleniumhq.org/selenium-ide/1.0.7/selenium-ide-1.0.7.xpi (XPIs are
the Firefox Extensions)




© Copyright GlobalLogic 2010                                                                       12
Opening Selenium IDE                                     Connect. Collaborate. Innovate.




Selenium IDE is opened from the Tools menu of Firefox.




© Copyright GlobalLogic 2010                                                               13
Connect. Collaborate. Innovate.
Selenium IDE Features

              Menu Bar


             Toolbar




                                   Test Case Pane
          Test Case Pane




       Log/Reference Pane




© Copyright GlobalLogic 2010                                     14
Connect. Collaborate. Innovate.
Selenium IDE Basic Toolbar Commands


     Speed Control: controls how fast your test case runs.

       Run All: Runs the entire test suite when a test suite with multiple test cases is loaded.

       Run: Runs the currently selected test. When only a single test is loaded this button
       and the Run All button have the same effect.

       Pause/Resume: Allows stopping and re-starting of a running test case.

       Record: Records the user’s browser actions.

      Step: Allows you to “step” through a test case by running it one command at a time.
      Use for debugging test cases.




© Copyright GlobalLogic 2010                                                                             15
Connect. Collaborate. Innovate.
Building Test Cases using IDE

        Recording
        When Selenium-IDE is first opened, the record button is ON by default.
        During recording, Selenium-IDE will automatically insert commands into your test case based
        on your actions. Typically, this will include:
        • clicking a link - click or clickAndWait commands
        • entering values - type command
        • selecting options from a drop-down listbox - select
        command
        • clicking checkboxes or radio buttons - click command

        Adding Verifications and Asserts With the Context Menu
        Your test cases will also need to check the properties of a web-page. This requires assert and
        verify commands.
        With Selenium-IDE recording, go to the browser displaying your test application and right click
        anywhere on the page. You will see a context menu showing verify and/or assert commands.
        Insert Commands in Table View or Source View
        Commands can also be inserted in the Table view and Source View manually.




© Copyright GlobalLogic 2010                                                                                          16
Exercise 1 – Selenium IDE                          Connect. Collaborate. Innovate.




  1. Install Selenium IDE
  2. Record & Save the following test cases in Selenium IDE:
      Open Google.com. Search GlobalLogic in Google. Click
     GlobalLogic link in search result. GlobalLogic homepage should
     open up.
      Open GlobalLogic.com. Click About Us. Verify that the About Us
     page opens up.
      Open GlobalLogic.com. Click Careers Page. Go to current
     openings section. Conduct Search. Verify that the search results
     show up.
  3. Execute the above test cases individually in Selenium IDE.
  4. Execute the above created test cases as a test suite in Selenium
     IDE.


© Copyright GlobalLogic 2010                                                           17
Selenium RC                                                            Connect. Collaborate. Innovate.




  Selenium-RC is the solution for tests that need more than simple browser actions
  and linear execution. Selenium-RC uses the full power of programming languages to
  create more complex tests like reading and writing files, querying a database, and
  emailing test results.

    You’ll want to use Selenium-RC whenever your test requires logic not supported by
    Selenium-IDE. What logic could this be? For example, Selenium-IDE does not
    directly support:

             condition statements
             iteration
             logging and reporting of test results
             error handling, particularly unexpected errors
             database testing
             test case grouping
             re-execution of failed tests
             test case dependency
             screenshot capture of test failures



© Copyright GlobalLogic 2010                                                                             18
Selenium RC Components                                Connect. Collaborate. Innovate.




  Selenium-RC components are:

  The Selenium Server which 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 (Application Under Test).

  Client libraries which provide the interface between each
  programming language and the Selenium-RC Server.




© Copyright GlobalLogic 2010                                                            19
How Selenium RC Works          Connect. Collaborate. Innovate.




© Copyright GlobalLogic 2010                                     20
Installing Selenium RC Server                        Connect. Collaborate. Innovate.




• The Selenium Server is written in Java, and requires the Java
  Runtime Environment (JRE) version 1.5.0 or higher in order to start.
• Go to the http://seleniumhq.org/download/ and download
  selenium RC (Latest version is 1.0.3) -
  http://selenium.googlecode.com/files/selenium-remote-control-
  1.0.3.zip
• Unzip and extract it any directory.




© Copyright GlobalLogic 2010                                                           21
Start the RC Server                               Connect. Collaborate. Innovate.




• Open command prompt and go to the directory where you have
  extracted the Selenium RC.
• Run the command –
  java -jar selenium-server.jar




© Copyright GlobalLogic 2010                                                        22
Using Java Client Driver                                                     Connect. Collaborate. Innovate.




•      Extract the file selenium-java-client-driver.jar from selenium-remote-control-1.0.3.zip
•      Open your desired Java IDE (Eclipse, NetBeans, IntelliJ etc.)
•      Create a new project.
•      Add the selenium-java-client-driver.jar files to your project as references.
•      Add to your project classpath the file selenium-java-client-driver.jar.
•      From Selenium-IDE, export a script to a Java file and include it in your Java project, or write
       your Selenium test in Java using the selenium-java-client API.
•      Run Selenium server from the console.
•      Execute your test from the Java IDE or from the command-line.




© Copyright GlobalLogic 2010                                                                                   23
Exercise 2 – Selenium RC                            Connect. Collaborate. Innovate.




  1. Install Selenium RC.
  2. Create a Java Project in Eclipse and add JUnit and Selenium
     Client Driver in project classpath.
  3. Export Test Cases From Selenium IDE as JUnits.
  4. Export Test Case Suite From Selenium IDE as JUnit Test Suite.
  5. Import the Test Cases in Eclipse.
  6. Start the Selenium Server.
  7. Execute the test cases individually from Eclipse as JUnit.
  8. Execute the test cases as a JUnit Suite from Eclipse.




© Copyright GlobalLogic 2010                                                            24
Selenium Grid                                            Connect. Collaborate. Innovate.




     Selenium-Grid allows the Selenium-RC solution to scale for large
     test suites or test suites that must be run in multiple
     environments.

     With Selenium-Grid, multiple instances of Selenium-RC are
     running on various operating system and browser configurations;
     Each of these when launching register with a hub. When tests are
     sent to the hub they are then redirected to an available Selenium-
     RC, which will launch the browser and run the test. This allows for
     running tests in parallel, with the entire test suite theoretically
     taking only as long to run as the longest individual test.




© Copyright GlobalLogic 2010                                                               25
Typical Selenium Grid Setup    Connect. Collaborate. Innovate.




© Copyright GlobalLogic 2010                                     26
Installing Selenium Grid                             Connect. Collaborate. Innovate.




• Selenium Grid requires the following to be installed:
                   • JDK 1.5 or above
                   • Apache Ant 1.7 or above
• Go to the http://selenium-grid.seleniumhq.org/download.html and
  download Selenium Grid (Latest version is 1.0.8) –
  http://release.seleniumhq.org/selenium-grid/selenium-grid-1.0.8-
  bin.zip
• Unzip and extract it any directory.




© Copyright GlobalLogic 2010                                                           27
Starting Selenium Grid                                                       Connect. Collaborate. Innovate.



  Selenium Grid requires the Hub and RCs to be started :

  Hub
  To start Hub, open command prompt and go to the directory where you have extracted
  Selenium Grid and type:
  ant launch-hub

  RCs
  To start RCs, open command prompt and go to the directory where you have extracted
  Selenium Grid and type:
  ant -Denvironment=“*firefox“ -Dport=5555 launch-remote-control
  ant -Denvironment=“*iexplore” -Dport=5556 launch-remote-control
  The above commands would start RCs on ports 5555 and 5556 for firefox and internet
  explorer environments.

  When having multiple machines for RCs, following parameters should be used to provide the Hub URL and
  RC host:
  ant -Dport=<port> -Dhost=<hostname> -DhubURL=<hub url> launch-remote-control

  Grid Console
  Open http://localhost:4444/console to view the registered RCs and their status.
© Copyright GlobalLogic 2010                                                                                   28
Exercise 3 – Selenium Grid                                 Connect. Collaborate. Innovate.




  1.       Install Selenium Grid.
  2.       Start Selenium Grid & RCs.
  3.       Add Parallel JUnit to the classpath in the Eclipse project.
  4.       Export Test Case Suite From Selenium IDE as JUnit Suite.
  5.       Import the Test Case Suite in Eclipse.
  6.       Execute the Test Case suite using Parallel JUnit from Eclipse.
  7.       View the available/active RCs in Grid Console.




© Copyright GlobalLogic 2010                                                                   29
References                      Connect. Collaborate. Innovate.




    Selenium Documentation
    http://seleniumhq.org/docs/




© Copyright GlobalLogic 2010                                        30
Questions                         Connect. Collaborate. Innovate.




                               ??

© Copyright GlobalLogic 2010                                          31
Connect. Collaborate. Innovate.
Web Application Testing using Selenium




                               Thank You!




© Copyright GlobalLogic 2010                                                  32

More Related Content

What's hot

What's hot (16)

Ajit jadhav automation_qa_4_ yrs
Ajit jadhav automation_qa_4_ yrsAjit jadhav automation_qa_4_ yrs
Ajit jadhav automation_qa_4_ yrs
 
Selenium and JMeter
Selenium and JMeterSelenium and JMeter
Selenium and JMeter
 
Selenium and JMeter Testing
Selenium and JMeter TestingSelenium and JMeter Testing
Selenium and JMeter Testing
 
Android Automation Testing with Selendroid
Android Automation Testing with SelendroidAndroid Automation Testing with Selendroid
Android Automation Testing with Selendroid
 
International journal of applied sciences and innovation vol 2015 - no 1 - ...
International journal of applied sciences and innovation   vol 2015 - no 1 - ...International journal of applied sciences and innovation   vol 2015 - no 1 - ...
International journal of applied sciences and innovation vol 2015 - no 1 - ...
 
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 training in chennai
Selenium training in chennaiSelenium training in chennai
Selenium training in chennai
 
C# Security Testing and Debugging
C# Security Testing and DebuggingC# Security Testing and Debugging
C# Security Testing and Debugging
 
Testing Java applications with Maveryx
Testing Java applications with MaveryxTesting Java applications with Maveryx
Testing Java applications with Maveryx
 
Eclipse 40 and Eclipse e4
Eclipse 40 and Eclipse e4 Eclipse 40 and Eclipse e4
Eclipse 40 and Eclipse e4
 
Testing Android applications with Maveryx
Testing Android applications with MaveryxTesting Android applications with Maveryx
Testing Android applications with Maveryx
 
Robotium Tutorial
Robotium TutorialRobotium Tutorial
Robotium Tutorial
 
Expert selenium with core java
Expert selenium with core javaExpert selenium with core java
Expert selenium with core java
 
Android testing
Android testingAndroid testing
Android testing
 
Eclipse e4 on Java Forum Stuttgart 2010
Eclipse e4 on Java Forum Stuttgart 2010Eclipse e4 on Java Forum Stuttgart 2010
Eclipse e4 on Java Forum Stuttgart 2010
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with Selenium
 

Similar to GL_Web application testing using selenium

Top 21 Selenium FAQs.pdf
Top 21 Selenium FAQs.pdfTop 21 Selenium FAQs.pdf
Top 21 Selenium FAQs.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 training
Selenium trainingSelenium training
Selenium training
Robin0590
 
Selenium ide made easy
Selenium ide made easySelenium ide made easy
Selenium ide made easy
Narayanan Palani
 

Similar to GL_Web application testing using selenium (20)

Top 30 Selenium Interview Questions.pptx
Top 30 Selenium Interview Questions.pptxTop 30 Selenium Interview Questions.pptx
Top 30 Selenium Interview Questions.pptx
 
Selenium Primer
Selenium PrimerSelenium Primer
Selenium Primer
 
Selenium
SeleniumSelenium
Selenium
 
Top 21 Selenium FAQs.pdf
Top 21 Selenium FAQs.pdfTop 21 Selenium FAQs.pdf
Top 21 Selenium FAQs.pdf
 
Making Sense of Selenium
Making Sense of SeleniumMaking Sense of Selenium
Making Sense of Selenium
 
Sel
SelSel
Sel
 
Selenium
SeleniumSelenium
Selenium
 
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...
 
Basics of Selenium IDE,Core, Remote Control
Basics of Selenium IDE,Core, Remote ControlBasics of Selenium IDE,Core, Remote Control
Basics of Selenium IDE,Core, Remote Control
 
Selenium training
Selenium trainingSelenium training
Selenium training
 
Web Testing
Web TestingWeb Testing
Web Testing
 
Upcoming new features of selenium in automation testing
Upcoming new features of selenium in automation testingUpcoming new features of selenium in automation testing
Upcoming new features of selenium in automation testing
 
Selenium
SeleniumSelenium
Selenium
 
Interview Question & Answers for Selenium Freshers | LearningSlot
Interview Question & Answers for Selenium Freshers | LearningSlotInterview Question & Answers for Selenium Freshers | LearningSlot
Interview Question & Answers for Selenium Freshers | LearningSlot
 
Selenium
SeleniumSelenium
Selenium
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
A Simple Guide to Selenium Software Testing
A Simple Guide to Selenium Software TestingA Simple Guide to Selenium Software Testing
A Simple Guide to Selenium Software Testing
 
Selenium ide made easy
Selenium ide made easySelenium ide made easy
Selenium ide made easy
 
Selenium interview-questions-freshers
Selenium interview-questions-freshersSelenium interview-questions-freshers
Selenium interview-questions-freshers
 
What is selenium
What is seleniumWhat is selenium
What is selenium
 

More from Pragya Rastogi (20)

Gl android platform
Gl android platformGl android platform
Gl android platform
 
Qtp questions
Qtp questionsQtp questions
Qtp questions
 
Qtp not just for gui anymore
Qtp   not just for gui anymoreQtp   not just for gui anymore
Qtp not just for gui anymore
 
Qtp tutorial
Qtp tutorialQtp tutorial
Qtp tutorial
 
Qtp4 bpt
Qtp4 bptQtp4 bpt
Qtp4 bpt
 
Get ro property outputting value
Get ro property outputting valueGet ro property outputting value
Get ro property outputting value
 
Bp ttutorial
Bp ttutorialBp ttutorial
Bp ttutorial
 
Gl istqb testing fundamentals
Gl istqb testing fundamentalsGl istqb testing fundamentals
Gl istqb testing fundamentals
 
Gl scrum testing_models
Gl scrum testing_modelsGl scrum testing_models
Gl scrum testing_models
 
My Sql concepts
My Sql conceptsMy Sql concepts
My Sql concepts
 
Oops
OopsOops
Oops
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
70433 Dumps DB
70433 Dumps DB70433 Dumps DB
70433 Dumps DB
 
70 433
70 43370 433
70 433
 
70562-Dumps
70562-Dumps70562-Dumps
70562-Dumps
 
70562 (1)
70562 (1)70562 (1)
70562 (1)
 
32916
3291632916
32916
 
70 562
70 56270 562
70 562
 
Mobile testingartifacts
Mobile testingartifactsMobile testingartifacts
Mobile testingartifacts
 
Gl qtp day 3 1
Gl qtp day 3   1Gl qtp day 3   1
Gl qtp day 3 1
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

GL_Web application testing using selenium

  • 1. Connect. Collaborate. Innovate. Web Application Testing using Selenium Amit Saxena 17/08/2011 © Copyright GlobalLogic 2010 1
  • 2. Web Application Testing using Selenium Connect. Collaborate. Innovate. Training Agenda:  Selenium Introduction  Selenium Components  Recording & Testing with Selenium IDE  Exercise 1 – Selenium IDE  Testing using Selenium RC  Exercise 2 – Selenium RC  Parallel testing using Selenium Grid © Copyright GlobalLogic 2010 2
  • 3. Selenium – What is it? Connect. Collaborate. Innovate. • Selenium is a set of tools to automate web application testing across many platforms. • Selenium runs in many browsers and operating systems. • Selenium can be controlled by many programming languages and testing frameworks. • Selenium is highly flexible. • Selenium is an Open Source project. The code can be modified and enhancements can be submitted for contribution. © Copyright GlobalLogic 2010 3
  • 4. Selenium Components Connect. Collaborate. Innovate.  Selenium IDE - is a Firefox add-on that records clicks, typing, and other actions to make a test, which you can play back in the browser.  Selenium RC - runs your tests in multiple browsers and platforms. Tweak/Customize your tests in your preferred programming language.  Selenium Grid - extends Selenium RC to distribute your tests across multiple servers, saving you time by running tests in parallel. © Copyright GlobalLogic 2010 4
  • 5. Selenium Components… Connect. Collaborate. Innovate. © Copyright GlobalLogic 2010 5
  • 6. Platforms Supported by Selenium Connect. Collaborate. Innovate. © Copyright GlobalLogic 2010 6
  • 7. Connect. Collaborate. Innovate. Selenium Commands – Selenese Selenium commands come in three “flavors”: Actions, Accessors and Assertions. Actions are commands that generally manipulate the state of the application. They do things like “click this link” and “select that option”. If an Action fails, or has an error, the execution of the current test is stopped. Accessors examine the state of the application and store the results in variables, e.g. “storeTitle”. They are also used to automatically generate Assertions. Assertions are like Accessors, but they verify that the state of the application conforms to what is expected. Examples include “make sure the page title is X” and “verify that this checkbox is checked”. All Selenium Assertions can be used in 3 modes: Assert – Upon failure test is aborted Verify – Upon failure error is logged and test continues WaitFor – Waits for a conditions for a given timeout © Copyright GlobalLogic 2010 7
  • 8. Connect. Collaborate. Innovate. Selenium Scripts Syntax Selenium commands are simple, they consist of the command and two parameters. For example: type id=phone (555) 666-7066 Parameters vary, however they are typically: a locator for identifying a UI element within a page. a text pattern for verifying or asserting expected page content a text pattern or a selenium variable for entering text in an input field or for selecting an option from an option list. © Copyright GlobalLogic 2010 8
  • 9. Commonly Used Selenium Commands Connect. Collaborate. Innovate. open opens a page using a URL. click/clickAndWait performs a click operation, and optionally waits for a new page to load. verifyTitle/assertTitle verifies an expected page title. verifyTextPresent verifies expected text is somewhere on the page. verifyElementPresent verifies an expected UI element, as defined by its HTML tag, is present on the page. verifyText verifies expected text and it’s corresponding HTML tag are present on the page. verifyTable verifies a table’s expected contents. waitForPageToLoad pauses execution until an expected new page loads. Called automatically when clickAndWait is used. waitForElementPresent pauses execution until an expected UI element, as defined by its HTML tag, is present on the page. © Copyright GlobalLogic 2010 9
  • 10. Locating Elements Connect. Collaborate. Innovate. For many Selenium commands, a target is required. This target identifies an element in the content of the web application, and consists of the location strategy. Some of the location strategies using in Selenium are: Locating by Identifier This is probably the most common method of locating elements and is the catch-all default when no recognized locator type is used. With this strategy, the first element with the id attribute value matching the location will be used. If no element has a matching id attribute, then the first element with a name attribute matching the location will be used. Locating by Id This type of locator is more limited than the identifier locator type, but also more explicit. Use this when you know an element’s id attribute. Locating by Name The name locator type will locate the first element with a matching name attribute. Locating by XPath XPath is the language used for locating nodes in an XML document. As HTML can be an implementation of XML (XHTML), Selenium users can leverage this powerful language to target elements in their web applications. One of the main reasons for using XPath is when you don’t have a suitable id or name attribute for the element you wish to locate. You can use XPath to either locate the element in absolute terms (not advised), or relative to an element that does have an id or name attribute. © Copyright GlobalLogic 2010 10
  • 11. Selenium IDE Connect. Collaborate. Innovate. Selenium IDE is an integrated development environment for Selenium scripts. It is implemented as a Firefox extension, and allows you to record, edit, and debug tests. Features: •Easy record and playback •Intelligent field selection will use IDs, names, or XPath as needed •Autocomplete for all common Selenium commands •Walk through tests •Debug and set breakpoints •Save tests as Html, Java, .NET, Php, Perl, Ruby scripts etc. •Support for Selenium user-extensions.js file © Copyright GlobalLogic 2010 11
  • 12. Selenium IDE Installation Connect. Collaborate. Innovate. Selenium IDE is installed as a Firefox extension. It can be installed directly within Firefox by going to http://seleniumhq.org/download/ and downloading http://release.seleniumhq.org/selenium-ide/1.0.7/selenium-ide-1.0.7.xpi (XPIs are the Firefox Extensions) © Copyright GlobalLogic 2010 12
  • 13. Opening Selenium IDE Connect. Collaborate. Innovate. Selenium IDE is opened from the Tools menu of Firefox. © Copyright GlobalLogic 2010 13
  • 14. Connect. Collaborate. Innovate. Selenium IDE Features Menu Bar Toolbar Test Case Pane Test Case Pane Log/Reference Pane © Copyright GlobalLogic 2010 14
  • 15. Connect. Collaborate. Innovate. Selenium IDE Basic Toolbar Commands Speed Control: controls how fast your test case runs. Run All: Runs the entire test suite when a test suite with multiple test cases is loaded. Run: Runs the currently selected test. When only a single test is loaded this button and the Run All button have the same effect. Pause/Resume: Allows stopping and re-starting of a running test case. Record: Records the user’s browser actions. Step: Allows you to “step” through a test case by running it one command at a time. Use for debugging test cases. © Copyright GlobalLogic 2010 15
  • 16. Connect. Collaborate. Innovate. Building Test Cases using IDE Recording When Selenium-IDE is first opened, the record button is ON by default. During recording, Selenium-IDE will automatically insert commands into your test case based on your actions. Typically, this will include: • clicking a link - click or clickAndWait commands • entering values - type command • selecting options from a drop-down listbox - select command • clicking checkboxes or radio buttons - click command Adding Verifications and Asserts With the Context Menu Your test cases will also need to check the properties of a web-page. This requires assert and verify commands. With Selenium-IDE recording, go to the browser displaying your test application and right click anywhere on the page. You will see a context menu showing verify and/or assert commands. Insert Commands in Table View or Source View Commands can also be inserted in the Table view and Source View manually. © Copyright GlobalLogic 2010 16
  • 17. Exercise 1 – Selenium IDE Connect. Collaborate. Innovate. 1. Install Selenium IDE 2. Record & Save the following test cases in Selenium IDE:  Open Google.com. Search GlobalLogic in Google. Click GlobalLogic link in search result. GlobalLogic homepage should open up.  Open GlobalLogic.com. Click About Us. Verify that the About Us page opens up.  Open GlobalLogic.com. Click Careers Page. Go to current openings section. Conduct Search. Verify that the search results show up. 3. Execute the above test cases individually in Selenium IDE. 4. Execute the above created test cases as a test suite in Selenium IDE. © Copyright GlobalLogic 2010 17
  • 18. Selenium RC Connect. Collaborate. Innovate. Selenium-RC is the solution for tests that need more than simple browser actions and linear execution. Selenium-RC uses the full power of programming languages to create more complex tests like reading and writing files, querying a database, and emailing test results. You’ll want to use Selenium-RC whenever your test requires logic not supported by Selenium-IDE. What logic could this be? For example, Selenium-IDE does not directly support: condition statements iteration logging and reporting of test results error handling, particularly unexpected errors database testing test case grouping re-execution of failed tests test case dependency screenshot capture of test failures © Copyright GlobalLogic 2010 18
  • 19. Selenium RC Components Connect. Collaborate. Innovate. Selenium-RC components are: The Selenium Server which 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 (Application Under Test). Client libraries which provide the interface between each programming language and the Selenium-RC Server. © Copyright GlobalLogic 2010 19
  • 20. How Selenium RC Works Connect. Collaborate. Innovate. © Copyright GlobalLogic 2010 20
  • 21. Installing Selenium RC Server Connect. Collaborate. Innovate. • The Selenium Server is written in Java, and requires the Java Runtime Environment (JRE) version 1.5.0 or higher in order to start. • Go to the http://seleniumhq.org/download/ and download selenium RC (Latest version is 1.0.3) - http://selenium.googlecode.com/files/selenium-remote-control- 1.0.3.zip • Unzip and extract it any directory. © Copyright GlobalLogic 2010 21
  • 22. Start the RC Server Connect. Collaborate. Innovate. • Open command prompt and go to the directory where you have extracted the Selenium RC. • Run the command – java -jar selenium-server.jar © Copyright GlobalLogic 2010 22
  • 23. Using Java Client Driver Connect. Collaborate. Innovate. • Extract the file selenium-java-client-driver.jar from selenium-remote-control-1.0.3.zip • Open your desired Java IDE (Eclipse, NetBeans, IntelliJ etc.) • Create a new project. • Add the selenium-java-client-driver.jar files to your project as references. • Add to your project classpath the file selenium-java-client-driver.jar. • From Selenium-IDE, export a script to a Java file and include it in your Java project, or write your Selenium test in Java using the selenium-java-client API. • Run Selenium server from the console. • Execute your test from the Java IDE or from the command-line. © Copyright GlobalLogic 2010 23
  • 24. Exercise 2 – Selenium RC Connect. Collaborate. Innovate. 1. Install Selenium RC. 2. Create a Java Project in Eclipse and add JUnit and Selenium Client Driver in project classpath. 3. Export Test Cases From Selenium IDE as JUnits. 4. Export Test Case Suite From Selenium IDE as JUnit Test Suite. 5. Import the Test Cases in Eclipse. 6. Start the Selenium Server. 7. Execute the test cases individually from Eclipse as JUnit. 8. Execute the test cases as a JUnit Suite from Eclipse. © Copyright GlobalLogic 2010 24
  • 25. Selenium Grid Connect. Collaborate. Innovate. Selenium-Grid allows the Selenium-RC solution to scale for large test suites or test suites that must be run in multiple environments. With Selenium-Grid, multiple instances of Selenium-RC are running on various operating system and browser configurations; Each of these when launching register with a hub. When tests are sent to the hub they are then redirected to an available Selenium- RC, which will launch the browser and run the test. This allows for running tests in parallel, with the entire test suite theoretically taking only as long to run as the longest individual test. © Copyright GlobalLogic 2010 25
  • 26. Typical Selenium Grid Setup Connect. Collaborate. Innovate. © Copyright GlobalLogic 2010 26
  • 27. Installing Selenium Grid Connect. Collaborate. Innovate. • Selenium Grid requires the following to be installed: • JDK 1.5 or above • Apache Ant 1.7 or above • Go to the http://selenium-grid.seleniumhq.org/download.html and download Selenium Grid (Latest version is 1.0.8) – http://release.seleniumhq.org/selenium-grid/selenium-grid-1.0.8- bin.zip • Unzip and extract it any directory. © Copyright GlobalLogic 2010 27
  • 28. Starting Selenium Grid Connect. Collaborate. Innovate. Selenium Grid requires the Hub and RCs to be started : Hub To start Hub, open command prompt and go to the directory where you have extracted Selenium Grid and type: ant launch-hub RCs To start RCs, open command prompt and go to the directory where you have extracted Selenium Grid and type: ant -Denvironment=“*firefox“ -Dport=5555 launch-remote-control ant -Denvironment=“*iexplore” -Dport=5556 launch-remote-control The above commands would start RCs on ports 5555 and 5556 for firefox and internet explorer environments. When having multiple machines for RCs, following parameters should be used to provide the Hub URL and RC host: ant -Dport=<port> -Dhost=<hostname> -DhubURL=<hub url> launch-remote-control Grid Console Open http://localhost:4444/console to view the registered RCs and their status. © Copyright GlobalLogic 2010 28
  • 29. Exercise 3 – Selenium Grid Connect. Collaborate. Innovate. 1. Install Selenium Grid. 2. Start Selenium Grid & RCs. 3. Add Parallel JUnit to the classpath in the Eclipse project. 4. Export Test Case Suite From Selenium IDE as JUnit Suite. 5. Import the Test Case Suite in Eclipse. 6. Execute the Test Case suite using Parallel JUnit from Eclipse. 7. View the available/active RCs in Grid Console. © Copyright GlobalLogic 2010 29
  • 30. References Connect. Collaborate. Innovate. Selenium Documentation http://seleniumhq.org/docs/ © Copyright GlobalLogic 2010 30
  • 31. Questions Connect. Collaborate. Innovate. ?? © Copyright GlobalLogic 2010 31
  • 32. Connect. Collaborate. Innovate. Web Application Testing using Selenium Thank You! © Copyright GlobalLogic 2010 32