Automated test of cainiao (6) -- Text Template Matching of selenium commands

Source: Internet
Author: User
Tags glob sunrise time

Text Template match

========================================================

Text Template matching can be understood as a wildcard. I think you have used the built-in search function in windows.

*An asterisk represents one or more characters.

?A question mark represents a character.

A template is also a parameter frequently used by selenes commands. A template allows you to use special characters to describe the expected value, rather than accurately describe the expected value.

The commands for template in selenium include:

Verifytextpresent, verifytitle, verifyalert, assertconfirmation, verifytext, verfyprompt,

 

So what template types are there?

 Generally, we usually use globbing, regular expressions, and exact.

 

1. globbing Template

Many people are familiar with globbing because it is used as a wildcard in DOS or ELE. Me UNIX \ Linux commands. In selenium implementation, globbing only supports two special symbols:

1) * indicates "matching anything". It is null, one or more characters.

2) [] (character set) indicates "matching any square brackets ". The connector can be used to shorten the duration (must be continuous within the asccii character set ).

Example:

[Aeiou] ---- match any lowercase vowel

[0-9] ----- match any number

[A-zA-Z0-9] ------ match any letter with number

 

To enable the selenese command to specify the globbing template parameter, you can add"Glob:"Prefix. Of course, globbing is the default template mode, so you can do it without adding it.

 

 

Ii. Regular Expressions Template

 

The regular expressions template is the most powerful among the three template types supported by selenese. Regular Expressions is also supported by many advanced languages.

For example, assume that your test requires that a specific table unit contain only numbers,Regexp: [0-9] +Is a simple template that can match any length in decimal number.

Regular Expressions supportJavascript. The table is as follows:

In seleneseThe regular expressions template must contain"Regexp:"Or"Regexpi:"; The former method is case sensitive, and the latter is case insensitive.

Example:

The following example tests Yahoo! Whether the weather page of anchorage and Alaska contains the sunrise time information:

 

 

Explanations of the meaning of the preceding template:

 

 

Iii. Exact Template

 

A template of the exact type is rarely used, and it does not use special characters at all. However, it has its own expertise.

If you want to find a real* What should I do with an asterisk? Because the asterisks are defined as special characters in the previous model.

The exact template is a solution. "Exact:"Prefix.

Example:

If you want to select aReal *.

If you use the globbing template method"Glob: Real *", It may work normally or not. Because the asterisk in The globbing template matches anything or is empty.

In this case, we can use the exact template to represent:

Of course, the effect can also be achieved through the escape asterisks of the regular expressions template.

 

In most tests, asterisks or square brackets with characters are not needed. Therefore, the regular expressions template and globbing template can meet most of our requirements.

 

========================================================== ==============

Summary:

As for the selenium command, I have learned it. I remember the commands recorded with selenium IDE and their corresponding parameters. Now, it will become very clear.

In fact, this part of the command is a relatively basic thing, understanding this part of the study will be more smooth. I believe that all the students who want to learn qtp need to learn vbs scripts. Although they do not understand vbs, you can also use qtp through the qtp recording function.

However, the more you use qtp, the more difficult it will be. you will encounter various problems in project applications. recording is not omnipotent and you need to modify it, sometimes you need to manually write the vbs script. If you are not familiar with vbs, you will be unable to use qtp. Don't cut the woodcutter by mistake!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.