Site icon Tutorial

Vskills Certified Selenium Professional Tutorial | Globs

Globs

Globs

Globs is a part of Selenium testing is a software testing framework for web applications. Selenium is a strong set of tools that supports the quick development of test automation for web-based applications. It was developed in 2004 by Jason Huggins as a JavaScript library used to automate his manual testing routines.

Features of Selenium testing

Globbing Patterns

Most people are familiar with globbing as it is utilized in filename expansion at a DOS or Unix/Linux command line such as ls *.c. In this case, globbing is used to display all the files ending with a .c extension that exist in the current directory. Globs is fairly limited. Only two special characters are supported in the Selenium implementation:

* which translates to “match anything,” i.e., nothing, a single character, or many characters.

[ ] (character class) which translates to “match any single character found inside the square brackets.” A dash (hyphen) can be used as a shorthand to specify a range of characters (which are contiguous in the ASCII character set). A few examples will make the functionality of a character class clear:

[aeiou] matches any lowercase vowel

[0-9] matches any digit

[a-zA-Z0-9] matches any alphanumeric character

In most other contexts, globbing includes a third special character, the ?. However, Selenium globbing patterns only support the asterisk and character class.

To specify a globbing pattern parameter for a Selenese command, you can prefix the pattern with a glob: label. However, because globbing patterns are the default, you can also omit the label and specify just the pattern itself.

Below is an example of two commands that use globbing patterns. The actual link text on the page being tested was “Film/Television Department”; by using a pattern rather than the exact text, the click command will work even if the link text is changed to “Film & Television Department” or “Film and Television Department”. The glob pattern’s asterisk will match “anything or nothing” between the word “Film” and the word “Television”.

Command Target Value
click link=glob:Film*Television Department  
verifyTitle glob:*Film*Television*  

The actual title of the page reached by clicking on the link was “De Anza Film And Television Department – Menu”. By using a pattern rather than the exact text, the verifyTitle will pass as long as the two words “Film” and “Television” appear (in that order) anywhere in the page’s title. For example, if the page’s owner should shorten the title to just “Film & Television Department,” the test would still pass. Using a pattern for both a link and a simple test that the link worked (such as the verifyTitle above does) can greatly reduce the maintenance for such test cases.

Using Selenium as Test Automation tool reduces the cost incurred and also ensures faster delivery. Thus it is cost effective and also not time consuming which proves that this is a standard automation tool for regression.

Since the days of DOS, we have been using globbing. What is globbing? Remember the days you were searching files in DOS by using the command *.doc or  De*.doc and so on. This is where you have used globs. So let’s see how Selenium supports globbing.

Globbing in Selenium is possible with the following set of characters

i)         * (asterisk)

ii)          ? (question mark)

iii)        [ ] (square brackets)

Suppose we want to find/ search for the text “region” or “regional”, then we could use it as reg* . In Selenium, that would mean the following

Command Target Value
verifyTextPresent Glob: reg*  

 

Go back to Tutorial                                                                                Go to Home Page

Exit mobile version