Method analysis of VBScript developing automatic test script

Time:2020-11-24

I have been in the software testing industry for many years, and my direction is automatic testing. I also know about VBScript script in the process of testing
Also used some, so to talk about how to use VBScript to develop automated testing.
First of all, several VBScript functions that can be used in automatic test development are introduced.

1. Instr function
describe
Returns the position of the first occurrence of a string in another string.
grammar
InStr([start, ]string1, string2[, compare])
The syntax of the instr function has the following parameters:
Parameter description
Start is optional. A numeric expression that sets the starting position of each search. If omitted, the search starts at the position of the first character. If start contains null, an error occurs. If compare is specified, you must have a start parameter.
String1 required. String expression that accepts the search.
String2 required. The string expression to search for.
Compare is optional. A numeric value indicating the type of comparison to use when evaluating substrings. For values, see the settings section. If omitted, a binary comparison is performed.

Example:
This function describes the position of a string in another string. In automated testing, it is often used as a comparison result.
For example:
    

Dim a,b
a=”rtyi”
b=”1345krkrtyi:{“”><?”

If InStr(b,a)>0 Then
Msgbox “test result passed”
Else
Msgbox “test result failed”
End If

2. Split function
describe
Returns a one-dimensional array based on 0 containing the specified number of substrings.
grammar
Split(expression[, delimiter[, count[, start]]])
The syntax of the split function has the following parameters:
Parameter description
Expression is required. A string expression that contains substrings and separators. If expression is a zero length string, split returns an empty array, that is, an array without elements and data.
Qualifier is optional. The character used to identify the bounds of a substring. If omitted, use a space (“) as the separator. If the qualifier is a zero length string, returns a single element array containing the entire expression string.
Count is optional. The number of substrings returned, – 1 indicates that all substrings are returned.
Compare is optional. A numeric value indicating the type of comparison to use when evaluating substrings. For values, see the settings section.

Example:
This function is mainly used to split strings, and it is mainly used to split test data in automatic test development.
For example:

Dim a,b,i

a=”rt124,y556,57777,<>:/*&%”
b=Split(a,”,”)

For i=0 To Ubound(b)
    MsgBox b(i)
Next

Recommended Today

PHP 12th week function learning record

sha1() effect sha1()Function to evaluate the value of a stringSHA-1Hash. usage sha1(string,raw) case <?php $str = “Hello”; echo sha1($str); ?> result f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0 sha1_file() effect sha1_file()Function calculation fileSHA-1Hash. usage sha1_file(file,raw) case <?php $filename = “test.txt”; $sha1file = sha1_file($filename); echo $sha1file; ?> result aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d similar_text() effect similar_text()Function to calculate the similarity between two strings. usage similar_text(string1,string2,percent) case […]