Friday, 3 October 2014

Selenium - IDE

The Selenium-IDE (Integrated Development Environment) is an easy-to-use Firefox plug-in for develop Selenium test cases. It provides a Graphical User Interface for recording user actions using Firefox which is used to learn and use Selenium, but it can only be used only with Firefox browser as other browsers are not supported.
However, The recorded scripts can be converted into various programming languages supported by Selenium and the scripts can be executed on various other browsers as well.
TitleDescription
Download Selenium IDEThis section deals with how to download and configure selenium IDE
Selenium IDE FeaturesThis section deals with the features available in Selenium IDE
Creating Selenium IDE TestsThis section deals with how to create IDE tests using recording feature
Selenium IDE Script DebuggingThis section deals with debugging the selenium IDE script
Inserting Verification PointsInserting verification points in selenium IDE is discussed in this section.
Selenium Pattern MatchingThis section deals with how to work with regular expressions using IDE.
Selenium User ExtensionsThe Java script that allows user to customize or add new functionality.
Different Browser ExecutionThis section deals with how to execute selenium IDE scripts on different browsers.

Download Selenium IDE:

Step 1 : Launch Firefox and navigate to the URL - http://seleniumhq.org/download/. Under the Selenium IDE section, click on the link that shows the current version number as shown below.
Selenium IDE 1
Step 2 : Firefox add-ons notifier pops up with allow and disallow options. User has to allow the installation.
Selenium IDE 2
Step 3 : The add-ons installer warns the user about untrusted add-ons. Click 'Install Now'.
Selenium IDE 3
Step 4 : The Selenium IDE can now be accessed by navigating to 'Tools' >> 'Selenium IDE'.
Selenium IDE 5
Step 5 : The Selenium IDE can also be accessed directly from quick access menu bar as shown below.
Selenium IDE 4

Selenium IDE Features:

The Features of Selenium IDE are listed with the help of a simple tool tip as shown below.
Selenium IDE 4
The feature of the record tool bar is explained below.
Selenium IDE 11

Creating Selenium IDE Tests:

The following steps are involved in creating Selenium tests using IDE
  1. Recording and adding commands in a test
  2. Saving the recorded test
  3. Saving the test suite
  4. Executing the recorded test

RECORDING AND ADDING COMMANDS IN A TEST

For Demo purposes we will make use of www.ncalculators.com to understand selenium features.
Step 1 : Launch the Firefox browser and navigate to the website - http://www.ncalculators.com/
Step 2 : Open Selenium IDE from the Tools menu and press the record button that is on the top-right corner.
Selenium IDE 7
Step 3 : Navigate to "Math Calculator" >> "Percent Calculator >> enter "10" as number1 and 50 as number2 and click "calculate".
Selenium IDE 7
Step 4 : User can then Insert a checkpoint by right click on the webelement and select "Show all available commands" >> select "assert text css=b 5"
Selenium IDE 8
Step 5 : The recorded script is generated and the script is displayed as shown below.
Selenium IDE 9

SAVING THE RECORDED TEST

Step 1 : Save the Test Case by navigating to "File" >> "Save Test" and save the file in the location of your choice. The file is saved as .HTML as default.
The test can also be saved with an extension htm, shtml and xhtml.
Selenium IDE 9

SAVING THE TEST SUITE

A test suite is a collection of tests that can be executed as a single entity.
Step 1 : Create a test suite by navigating to "File" >> "New Test Suite" as shown below.
Selenium IDE 13
Step 2 : The tests can be recorded one by one by choosing the option "New Test Case" from "File" Menu.
Step 3 : The individual tests are saved with a name alone with saving a "Test Suite".
Selenium IDE 14

EXECUTING THE RECORDED TEST

The recorded scripts can then be executed either by clicking "Play entire suite" or "Play current test" button in the tool bar.
Step 1 : The Run status can be can be seen in status pane that displays number of tests passed and failed.
Step 2 : Once a step is executed, user can see the result in "Log" Pane.
Step 3 : After executing each step, the background of the test step turns "Green" if passed and "Red" if failed as shown below.
Selenium IDE 15

Selenium IDE Script Debugging:

Debugging is the process of finding and fixing errors in the test script which is a common step of any script development. To Make the process more robust we can make use a plugin "Power Debugger" for Selenium IDE
Step 1 : To Install Power Debugger for Selenium IDE, Navigate to https://addons.mozilla.org/en-US/firefox/addon/power-debugger-selenium-ide/ and click on "Add to Firefox" Link as shown below.
Selenium IDE 16
Step 2 : Now launch 'Selenium IDE' and you will notice a new icon, "Pause on Fail" on recording toolbar as shown below. Click on the same to turn it ON. Upon clicking again, it would be turned "OFF".
Selenium IDE 17
Step 3 : Users can turn "pause on fail" on or off any time even when the test is running
Step 4 : Once the test case pauses due to a failed step, you can use the usual resume/step buttons to continue the test execution. The execution will NOT be paused if the failure is on the last command of any test case.
Step 5 : We can also use break points to understand what exactly happens during the step. To Insert a break point on a particular step, perform a "Right Click" and select "toggle Break Point" from the context sensitive menu.
Selenium IDE 18
Step 6 : Upon inserting the breakpoint, the particular step is displayed with a pause icon as shown below.
Selenium IDE 19
Step 7 : When we execute the script, the script execution is paused where the break point is inserted. This will help the user to evaluate the value/presence of an element etc when the execution is in progress.
Selenium IDE 20


Inserting Verification Points:

The test cases that we develop also need to check the properties of a web-page. This requires assert and verify commands. There are two ways to insert any verfication points into the script
To Insert any verification point in recording mode, "Right click" on the element and choose "Show all Available Commands" as shown below.
selenium ide 21
We can also insert a command by performing a "Right Click" and choose "Insert New Command".
selenium ide 22
After Inserting New command, click 'Command' drop down and select appropriate verification point from the available list of commands as shown below
selenium ide 23
Below are the mostly used verification commands which will help us to check if a particular step has passed or failed.
  • verifyElementPresent
  • assertElementPresent
  • verifyElementNotPresent
  • assertElementNotPresent
  • verifyText
  • assertText
  • verifyAttribute
  • assertAttribute
  • verifyChecked
  • assertChecked
  • verifyAlert
  • assertAlert
  • verifyTitle
  • assertTitle

Synchronization points

During Script Execution, the application might respond based on server load, hence it is required for the application and script to be in sync. Below are few commands which we can use to ensure that script and application are in sync.
  • waitForAlertNotPresent
  • waitForAlertPresent
  • waitForElementPresent
  • waitForElementNotPresent
  • waitForTextPresent
  • waitForTextNotPresent
  • waitForPageToLoad
  • waitForFrameToLoad

Selenium Pattern Matching:

In Selenium IDE, like locators, patterns are a type of parameter which are frequently used by selenium. It allows user to describe patterns with the help of special characters. Many a times, the text that we would like to verify are dynamic in that case pattern matching is very useful.
Pattern Matching is used with all verification points commands - VerifyTextPresent, verifyTitle, verifyAlert, assertConfirmation, verifyText, and verifyPrompt
There are three ways to define a pattern - globbing, regular expressions, and exact.

GLOBBING

Globbing is familiar to most techies who have used file matching patterns in Linux or Windows while searching for a certain file type like *.doc or *.jpg. But globbing in Selenium supports only three special characters: *, ? and [ ].
  • - matches any number of characters.
  • - matches a single character.
  • [ ] - called a character class, lets you match any single character found within the brackets. [0-9] matches any digit
To specify a glob in a selenium command, prefix the pattern with the keyword 'glob:'. For example if you would like to search for the texts "tax year 2013" or "tax year 2014" then you can use "tax year *" glob as shown below.
However the usage of keyword "glob:" is optional while specifies the text pattern because globbing patterns are the default in Selenium.
CommandTargetValue
clickAndWaitlink=search
verifyTextPresentglob: tax year *

EXACT PATTERNS

Patterns with the prefix 'exact:' will match the given text as it is. Let us say, the user wants an exact match with the value string, i.e without the glob operator doing its work, one can use the 'exact' pattern as below. In this example the operator '*' will work as a normal character rather then a pattern-matching wildcard character.
CommandTargetValue
clickAndWaitlink=search
verifyValueexact: *.doc

REGULAR EXPRESSION PATTERNS

Regular Expressions are the most useful among the pattern matching techniques available. Selenium supports the complete set of reugular expression patterns that Javascript supports. Hence the users are No longer limited by *, ? And [] globbing patterns.
To use RegEx patterns we need to prefix with either "regexp:" or "regexpi:". The prefix "regexpi" is case-insensitive. The glob: and the exact: pattern are the subsets of the Regular Expression patterns. Everything that is done with glob: or exact: can be accomplished with the help of RegExp.

EXAMPLE

For example the following will test if a input field with the id 'name' contains the string 'tax year', 'Tax Year' or 'tax Year'.
CommandTargetValue
clickAndWaitlink=search
verifyValueid=nameregexp:[Tt]ax ([Yy]ear)
Selenium User Extensions:

It is easy to extend Selenium IDE by adding customized actions, assertions and locator-strategies This is done with the help of JavaScript by adding methods to the Selenium object prototype. On startup, Selenium will automatically look through methods on these prototypes, using name patterns to recognize which ones are actions, assertions and locators.
Let us add a 'while' Loop in Selenium IDE with the help of JavaScript.
Step 1 : To Add the js file, first navigate to https://github.com/darrenderidder/sideflow/blob/master/sideflow.js and copy the script and place save it as 'sideflow.js' in your local folder as shown below.
Selenium IDE 24
Step 2 : Now launch 'Selenium IDE' and Navigate to "Options" >> "Options" as shown below.
Selenium IDE 25
Step 3 : Click 'Browse' button under 'Selenium Core Extensions' area and point to the js file that we have saved in Step#1.
Selenium IDE 26
Step 4 : Restart Selenium IDE.
Step 5 : Now you will have access to few more commands such as "Label" "While" etc
Step 6 : Now we will be able to create While loop within Selenium IDE and it will be able to execute as shown below.
Selenium IDE 27

Different Browser Execution:

Selenium-IDE scripts can only run tests against Firefox as the tool IDE itself a plugin of Firefox. Tests developed using Selenium-IDE can be executed against other browsers by saving it as selenium webdriver or Selenium Remote Control Script.
More on Selenium Webdriver and Selenium Remote Control would be dealt in later chapters.
Step 1 : Open any saved Test in SElenium IDE
Step 2 : Navigate to "File" menu and select "Export Test Suite As" and the options would be listed.
Selenium IDE 28
Step 3 : Now let us export the script to "WebDriver" and save it with a name.
Step 4 : The saved webdriver File is displayed as shown below.
Selenium IDE 29


22 comments:

  1. We share this information about Selenium RC Procedure very interesting.I'm also working Testing. Your Selenium Information very useful to us.We perhaps Selenium Automation to RC Procedure all think really useful.
    Selenium Training in Chennai

    ReplyDelete
  2. Nice article about selenium IDE..it was so informative.Thanks for sharing..keep update best selenium training in chennai
    best selenium training institute in chennai

    ReplyDelete
  3. Thanks for providing the information . The articles in your blog helped me a lot for improving the knowledge on the subject. Also check my small collection on this at selenium Online Training blog

    ReplyDelete
  4. 5193AEC842Malcolm7A6EF6B99D11 October 2024 at 10:49

    62B2CCA0C1
    telegram cam şov

    ReplyDelete