Friday, 18 September 2015

echo - Print Command and Pattern Matching

echo - Print Command

In Selenium IDE, we use a simple command called “echo” which allows us to print text to our test’s
output. That is, this “echo” statement can be used to print the contents of Selenium variable in the Log pane of the Selenium IDE.


In the above figure we are storing the value “Hello World” in a variable “value”.
And we can print this by using echo command and by entering the ${value} in the Target field.
Observe that we can view the printed data echo: Hello World in the “Log” pane.

Pattern Matching

Patterns are used to handle the text/elements in a webpage which may change in the future.
ie: what text is expected rather than having to specify that text exactly.

Examples of commands which require patterns are
  1.  verifyTextPresent
  2.  verifyTitle
  3.  verifyAlert
  4.  assertConfirmation
  5.  verifyText
  6.  verifyPrompt
There are three types of patterns
  1.  globbing
  2.  regular expressions
  3.  exact
I will explain you about the Globbing Patterns which is commonly used. Please refer to http://docs.seleniumhq.org/docs/ for the information regarding regular expressions and exact patterns.

Globbing Patterns:

[ ] character class which translates to “match any single character found inside the square brackets.”
- hyphen can be used as shorthand to specify a range of characters (which are contiguous in the ASCII character set).

Examples:
  •  [aeiou] matches any lowercase vowel
  •  [0-9] matches any digit
  •  [a-zA-Z0-9] matches any alphanumeric character

To specify a globbing pattern parameter for a Selenese command, you can prefix the pattern with
a glob: label.
For example, Navigate to https://irctc.co.in/ . Let us test the link text “Mumbai Suburban Season Ticket” on the page.


The actual link text on the page being tested was “Mumbai Suburban Season Ticket“.
By using a pattern rather than the exact text, the click command will work even if the link text is changed to
  •  “Mumbai Ticket“
  •  “Mumbai Season Ticket“.
  • "Mumbai Suburban Ticket"

The glob pattern’s asterisk will match anything or nothing between the word “Mumbai” and the word
"Ticket" 

Saturday, 12 September 2015

Selenium Commands - Selenese

Selenium Commands – Selenese

Selenium commands, often called selenese, are the set of commands that run your tests.
A sequence of these commands is a test script. That is, these commands essentially create a testing language.

Selenese can have up to a maximum of two parameters:
  1. Target
  2. Value
Parameters are not required all the time. It depends on how many the command will need. In selenese, one can test the existence of UI elements based on their HTML tags, test for specific
content, test for links, input fields, selection list options, submitting forms, buttons, table data, etc.

You can refer to the complete list of Selenium IDE commands at this link
http://release.seleniumhq.org/selenium-core/1.0.1/reference.html

Selenium commands are classified as:
  1. Actions
  2. Accessors
  3. Assertions

Actions:

These are the commands that directly interact with page elements.

If an Action fails, or has an error, the execution of the current test is stopped.

Many Actions can be called with the "AndWait" suffix, e.g. "clickAndWait". This suffix tells Selenium that the action will cause the browser to make a call to the server, and that Selenium should wait for a new page to load.

For Example:

The “click” command is an action because you directly interact with the element you are clicking

The “select” command is also an action because you are selecting an option.

Accessors:

These are the commands that allow us to store the results/values in variables.

For Example:

The “storeTitle” command is an accessor because it only reads the page title and saves it in a
variable. It does not interact with any element on the web page.

Assertions:

Assertions are like Accessors, but they verify that the state of the application conforms to what is
expected. If you want clear cut picture, let me give an example: 

The IRCTC webpage is having a title “IRCTC Next Generation eTicketing System”.

We will Verify/Check whether this webpage is having the title or not.


There are 3 types of Assertions
  1. Assert: When an “assert” command fails, the test is stopped immediately.
  2. Verify: When a “verify” command fails, Selenium IDE logs this failure and continues with the test execution.
  3. waitFor: Before proceeding to the next command, “waitFor” commands will first wait for a certain condition to become true.
  • If the condition becomes true within the waiting period, the step passes.
  • If the condition does not become true, the step fails. Failure is logged, and test execution proceeds to the next command.
  • By default, timeout value is set to 30 seconds. You can change this in the Selenium IDE Options dialog under the General tab.
Lets see the following example for verify and compare this with above assert.


In this example, we have used the verifyTitle command and the Test Case execution is completed even though there is an error in second line.
Thus finally we can say that,
  • When an “assert” command fails, the test is stopped immediately.
  • When a “verify” command fails, Selenium IDE logs this failure and continues with the test execution.
Synchronization Commands

We use Synchronization commands in order to provide the synchronization between the Application and the tool. The following are the Commands that we use:
  • wait
  • pause
These commands are used to avoid Timeout errors.

Wait:

There are two types of wait commands
  •  andWait
  •  waitFor
andWait commands:

We can use these commands if we want to wait for a new page to load before moving onto the next
command.

Examples are:

clickAndWait
typeAndWait
selectAndWait

waitFor commands:

We use these commands if we want to wait for a specified condition to become true before proceeding to the next command (irrespective of loading of a new page).

Examples are:

waitForTitle
waitForTextPresent

Pause:

It tells the test to pause for a while. We use pause command to provide the synchronization between the Selenium IDE tool and application. ie: Wait for the specified amount of time (in milliseconds)

Target Format: pause(waitTime)

Here, waitTime is the amount of time to sleep (in milliseconds)

Example: pause 45000

Selenium – Automation Testing

Store commands:

In Selenium IDE, we use the "store" command to store data in variables.
It can be used to simply store a constant value in a selenium variable.
It takes two parameters, the text value to be stored and a selenium variable.

The below figures explains that we are storing the value "Testuser" into a variable "storeValue"


Here we have stored the value “Testuser” into the variable  "storeValue".

Now our task is to type the value “Testuser” in the textbox of IRCTC login username field.


We need to access the value stored in the variable by using ${storeValue}.
We have given the locator for the text box as id=usernameId and typing the value stored in the variable by using ${storeValue}, that is Testuser

Friday, 11 September 2015

Execution of commands - start and break points

How to execute a Command?

In selenium IDE, we can execute any single command without running the whole test case.

We just click on the line we want to execute and then perform of either of the steps

i) click on “Actions -> Execute this command” from the menu bar
ii) simply press “X” on your keyboard.

Now let us consider the previous example of IRCTC.

Step 1:

Make sure that your browser is on the IRCTC homepage.
Click on the command you wish to execute.
In this example, click on the fourth line “type | name=j_password | 123456"




Step 2: Now Press “X” on your keyboard.

Step 3: Observe that the text box for password becomes populated with the text “123456”.
Here in the IRCTC web page the password field is hidden by resembling the characters as bullets.


Remember:

Executing commands this way is directly dependent on the page Firefox is currently displaying.
This means that if you try the above IRCTC example with the Google homepage displayed, then your step may fail because of the following reasons

i) There may be no attribute with "name"
ii) There may be no attribute value with "j_password" 


Start point:

The short-cut key is “S”.
It tells the Selenium IDE, from which line the execution will start.
To set a start-point, select a command, right-click, and from the context menu select Set/Clear Start Point.
Then click the Run button to execute the test case beginning at that start-point.



1. In the above example, playback will start on the second line.
2. We can clear the start point by pressing the “S” key from keyboard again.

Remember:

You can only have one start point in a single test script.
Start point is similar to Execute Command in such that they are dependent on the currently
displayed page. The start point will fail if you are on the wrong page

Breakpoint:

Breakpoints are indicators that tell Selenium IDE where to pause the test automatically.
The short-cut key is “B”.
To set a breakpoint, select a command, right-click, and from the context menu select Toggle Breakpoint, then click the Run button to run your test case from the start-point  to the breakpoint.

Now when we execute the test, command line having pause will be highlighted in yellow color which
means that the current step is pending. We can observe this from the above figure.

Remember:

We can also have multiple breakpoints in one test case but in contrast only one start point.

Tuesday, 1 September 2015

Record playback find button

Now the Test case Editor is updated as


Step 5:

Click on the “Login” button. TestCase editor will be updated as


After clicking on “Login” button, Firefox should take you to this page.


Note: The UI of current IRCTC is changed and added extra feature Captcha. I am excluding the captch and recording the script. 

Step 6:

Toggle the record button off to stop recording. Your script should now look like the one shown below.

                                    

Step 7:

Now we are done with our test script, we shall save it in a test case. In the File menu, select “Save TestCase”. (or Ctrl+S).


Step 8:

Choose your desired location, and then name the test case as “Login”.
Click the “Save” button.




Step 9:

Notice that the file was saved by default as HTML




Step 10:

Now go back to Selenium IDE and click the Playback button to execute the whole script


The script execution will be as in the following figure



Note: Please, ignore the captcha error, I have showed you how to record and playback a test case using Selenium IDE.

Finally we are done with creating the scripts by record and playback. You should practice as many
scenarios like this on the web.


Usage of Find button in Selenium IDE


The Find button is used to see which UI element on the currently displayed webpage (in the browser) is used in the currently selected Selenium command.

From Table view, select any command that has a locator parameter. Click the Find button.
Now look on the webpage. There should be a bright green rectangle enclosing the element specified by the locator parameter.

For Example,

1. Let us use the Login test case that we created earlier.
2. To open the Login.html file, Go To File->Open->Login.html
3. Click on the fourth command with a Target entry ie: name=usernameId.
4. Now click on the Find button.
5. Notice that the Password text box becomes highlighted for a second with green outlines and some yellow shades.





This indicates that Selenium IDE was able to detect and access the expected element correctly.

If the Find button highlighted a different element or no element at all, then there must be something wrong with your script.

Monday, 31 August 2015

Test Case Editor and sample recording of script

Test Case Editor:

The Command, Target and Value entry fields display the currently selected command along with its
parameters.
These are entry fields where you can modify the currently selected command.



Your script is displayed in the test case editor. It has two tabs.

Table View
Source View

Table View:

This is where you create and modify Selenese commands.
After playback, each step is color-coded.
If you start typing in the Command field, a drop-down list will be populated based on the first
characters you type; you can then select your desired command from the drop-down.


Source View:

It displays the steps in HTML (default) format.
It also allows you to edit your script just like in the Table View.


Log/Reference/UI-Element/Rollup Pane/Expert/Stored-Vars:

The bottom pane is used for six different functions

Log
Reference
UI-Element
Rollup
Stored-Vars
Expert

Log:

When you run your test case, error messages and information messages showing the progress are
displayed in this pane automatically, even if you do not first select the Log tab.
These messages are often useful for test case debugging


Clear button is used for clearing the Log.
Info button is a drop-down allowing selection of different levels of information to log.

Reference:

The Reference tab is the default selection whenever you are entering or modifying Selenese commands and parameters in Table mode.
In Table mode, the Reference pane will display documentation on the current command.


When entering or modifying commands, whether from Table or Source mode, it is important to ensure that the parameters specified in the Target and Value fields match those specified in the parameter list in the Reference pane.

If there is a mismatch in any of these three areas, the command will not run correctly.

We will discuss remaining tabs in the pane later in the posts

How to create Test Suites?

Step 1: Open Selenium IDE and go to Menu.
Step 2: Click on File ->  New Test Suite



Remember:

By default the suit name is “untitled”.
Right click on untitled and add the test cases.
Finally save the Test Suite with the extension .html.
We can drag and drop the Test cases for the order of execution.
Even if a Test case fails in the middle, the remaining test cases will execute.

Scripting in Selenium IDE

Selenium IDE is case sensitive and we should type values/attributes exactly as in the application.

Now we will see about –
Scripting by recording option.
Scripting manually using Firebug.
To explain clearly, I am taking the IRCTC website as our web application under test.

It is an online railway reservation system. Its URL is https://www.irctc.co.in/ and this will be our Base URL.

Scripting by recording option

We will create our first test script in Selenium IDE using recording option.
Afterwards, we shall execute our script using the playback feature.

Step 1:

Launch Mozilla Firefox browser and Selenium IDE.
Type the value for our Base URL: https://www.irctc.co.in/
Toggle the record button


Step 2:

In Firefox, navigate to https://www.irctc.co.in/.
Firefox should take you to the page similar to the one shown below


Step 3:

Right-click on IRCTC logo on the upper left corner. This will bring up the Selenium IDE context
menu.
Select the “Show Available Commands” option.
Then, select “assertTitle IRCTC Next Generation eTicketing System”.
This is a command that makes sure that the page title is correct and validating that we entered into the home page

After Selecting the command the TestCase pane is updated as below



Step 4:

In the “User Name” text box, type the username, “TestUser”.
In the “Password” text box, type a password, “123456”.



Thursday, 27 August 2015

Selenium IDE Menu's explanation

Edit:

It contains the options like Undo, Redo, Cut, Copy, Paste, Delete, and Select All.

The two important options are:

Insert New Command
Insert New Comment

The newly inserted command or comment will be placed on top of the currently selected line.
In the below example,

We have placed open command in the first line, and clickAt command in the second line.
Suppose if I want to insert a comment in between these two commands then we have to right click on the second command “ClickAt” and click on the option “Insert New Comment”.

I have typed the comment as “Hi Automation” which is displaying in pink color.





Remember:
Comments displays in pink color
Commands displays in black color

Actions:

The “Actions” menu and “Tool bar” have the same actions.
So, I will explain in detail about this at “Tool bar” section.


Options:

Options dialog box can be launched by clicking Options->Options… on the menu bar.
We can configure various settings of Selenium IDE.
The below diagram shows the various options present in the Selenium IDE.


Some of the important options are as below:

Default Timeout Value: Default timeout value is 30000ms. It is the time that Selenium IDE has
to wait for a certain element to appear in a webpage before it generates an error.

Remember base URL: If you want Selenium IDE to remember the Base URL every time you
launch it then keep this option as checked. If you uncheck this, Selenium IDE will always launch
with a blank value for the Base URL.

Clipboard Format:
Clipboard Format allows us to copy a command from the editor and paste it as a code snippet as
explained in the below figure:


For example, when you choose Java/JUnit 4/Remote Control as your clipboard format, every Selenese command you copy from Selenium IDE’s editor will be pasted as Java code.



Base URL: (Referred from http://docs.seleniumhq.org/)

The Base URL field at the top of the Selenium-IDE window is very useful for allowing test cases to be run across different domains.

For example, Suppose that a site named http://news.portal.com had a beta site named
http://beta.news.portal.com.

Any test cases for these sites that begin with an open statement should specify a relative URL as 
the argument to open rather than an absolute URL (one starting with a protocol such as http: or https :).

Selenium-IDE will then create an absolute URL by appending the open command’s argument onto the end of the value of Base URL. 

For example, the test case below would be run against
http://news.portal.com/about.html:


This same test case with a modified Base URL setting would be run against
http://beta.news.portal.com/about.html


Tool bar:
The tool bar contains buttons for controlling the execution of your test cases, including a step feature for debugging your test cases.

The right-most button, the one with the red-dot, is the record button.




Wednesday, 26 August 2015

Selenium IDE Features

Features of Selenium IDE

Features of Selenium IDE

The below diagram explains the various features of Selenium – IDE:

Menu bar
Base URL
Tool bar
Test Case Pane
Test Case Editor
Log /Stored-Vars /Reference /Expert /UI-Element /Rollup.

Remember:
Learning Selenium IDE is a must. Once we are aware about using the tool then we can write scripting either in Selenium RC or WebDriver.
Before that, we need to know the usage and features of Selenium IDE.

So, let us start with the features of Selenium IDE.




Let us discuss about each feature of Selenium IDE in detail


Menu Bar:

The Menu bar has the following tabs as in below figure:



File:

The File menu contains options to create, open, save, and close tests.




“Export” option allows us to convert Selenium IDE test cases into file formats that can run on Selenium

Export Test Case As” exports only the currently opened test case to source code.

Export Test Suite As” exports all the test cases in the currently opened test suite to source code.

By Selenium IDE, test cases can be exported only to the following formats:

.rb (Ruby source code)
.cs (C# source code)
.java (Java source code)

.py (Python source code)

Now Selenium IDE supports Perl and PHP formats also.

Tuesday, 25 August 2015

Selenium IDE installation and configuration

Selenium IDE Installation 

Let me explain you how to install Selenium IDE before working on it.

Step 1: Open Mozilla Firefox browser and navigate to the below link to download the IDE
http://docs.seleniumhq.org/download/
Step 2: Now refer to the Selenium IDE section and click on the download link that is provided.
Step 3: Once you clicked on the link, a popup appears as in below figure.



Step 4: Now click on the “Allow” button.
Step 5: Again a pop up will appear, as seen in the next screenshot. Click on “Install Now” button once it is
active.




Step 6: Once the installation process is complete, it will ask you to restart Firefox. Click on the Restart button. Firefox will close and then reopens.

Step 7: After Firefox has restarted, we can launch Selenium IDE using either of the following three ways:

         By using Ctrl+Alt+S     -- Keyboard Short cut

         By clicking on the Firefox menu button Web Developer Selenium IDE




By Clicking on the Selenium icon which will available on top right corner of the browser as shown below





Step 8: Selenium IDE should launch as shown below