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.