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"