Qtp framework-Based on Excel and saffron

Source: Internet
Author: User

Download the PDF version of this document:

Http://files.cnblogs.com/testware/QTP_Framework_Saffron.pdf

 

 

QtpTest Framework 

------- By saffron

Directory

Reasons for testing the framework... 2

I. Solution:... 3

Ii. Framework runtime diagram... 4

3. project structure... 5

Iv. script writing specifications... 6

V. Script compiling example... 8

 


Causes of the test framework

1. The script file is too large:

X is mainly caused by two reasons: first, the object library file. By default, each empty object library file is generated as 192 KB, such an empty qtp script file requires at least 192 K * 2 = 384k space (action0 and Action1). If there are more split actions, more space will be occupied. The second is Excel files. Because of the split action, each action requires an independent sheet, including the action called in the script, which is more obvious in complicated scripts.

2. Too many files:

X is the simplest qtp script. There are 4 folders and 15 files. When there are many split actions, the number of files increases in proportion to the number of actions.

In addition, if you use the action reuse method, there will be huge difficulties in maintenance, transfer, version control, and other aspects.

3. It is not conducive to viewing the script:

X uses the Action Method to save the script. When you view the relevant script, you have to open qtp and then import the relevant action. This will not be conducive to viewing the script.

4. It is not convenient to run scripts in batches:

X although qtp comes with a test bath runner, we can use the bathà add method to load the action to be run in batches. However, if you want to re-adjust the execution sequence of actions, you will be busy.


 

I. solution:

1. Use EXCEL to replace the action in the qtp script

√ Save the script to excel, ensure that a task is a table, and then read the script in Excel by String concatenation. The data to be read by the script is also stored with the task, this can directly reduce the number of qtp files.

2. Use EXCEL to manage test objects

√ The objects used by the script are stored in an Excel file and the objects of the same module are placed in a sheet. Before running the script of the relevant module, load the object library of a module in advance, and use Excel to manage the object library more intuitively.

3. Use EXCEL to replace test bath runner

√ Save the test plan to excel, which makes it easy to change the test execution sequence and each tester has a testplan, so that you can better understand how the tester edits the script.

4. Use Saffron to encapsulate scripts

X uses the B/S structure as an example:

Browser (......). Page (......). Webedit (......). Set "text"

√ Script after using saffron:

Obj_set "^ webedit", "$ username", "$ user"

As you can see, after using saffron, our script looks more concise, and because it is encapsulated by methods, we can include test records in this method, in this way, a record can be generated for each step.


 

Ii. Framework runtime Diagram

 

The data is organized as follows:

 

Note:

Idx: When idx is "√", the driver file will read this line, load the object library, read the test data according to the filtering conditions, and run the script. For example, idx is: "X" indicates that the row of data is not run.

Testcase_number: Test Case No.

Testcae_name: Test Case name

Script_file: corresponds to the address where the test script and test data are stored, and instructs the method name that drives the script.

Filter_exp: Data Filtering condition. This is only the data with the running id = 1.

Object_repository: corresponds to the address of the test object library and indicates the Sheet Name of the object to be stored.

Iii. Project Structure

 

 

Project Structure Description:

Driver: the entrance to the entire framework. The function is similar to that of test bath runner, which is used to run scripts in batches.

Frameutil: stores some function libraries that support the framework, including: dictionary. vbs, Excel. vbs, diverutil. vbs (Common driver method), saffron. vbs (test script encapsulation method)

Log: stores the logs after the script is run.

Objectrepository: the object library used to store the test objects used by the script. The function is consistent with the concept of the object library in qtp.

Qtpreport: qtp report file

Testdata: because the test script and test data are stored, we put the data used by the script and the script together, so that we can maintain the script while maintaining the relevant test data.

Driver. vbs: uses the Automation Object Model of qtp, which is also the entrance to the entire framework. You can directly execute this vbs script, so it can be used as an automatic Windows Task and executed at a specified time point.

Testplan: Test Plan, used to record the script information and select the running script based on the relevant filtering conditions, it also records the object library file address and test data address used by the relevant script, which makes the following objectrepository and testdat critical. In addition, we stipulate that each tester will have his own testplan, which makes it easy to manage the test records for batch operation.


 

Iv. script writing specifications

Our script is rewritten based on saffron, so when we formally write the script, let's take a look at the method we want to use:

1. browseto (URL)

Note:

This method is used to open the browser and navigate to the specified URL. If multiple browsers have been opened in the system, this method will close all the previously opened browsers, then open the browser and navigate to the specified URL.

Example:

Browseto "$ URL"

The $ symbol in the parameter represents the parameters used in the method. It is the data stored in different places. Here it refers to the related data in testdata.

Of course, we can also write the parameters directly, such as: browseto "http://www.baidu.com"

 

2. obj_click (objtype, objproperty)

Note:

Call the click method of related objects (currently, the following objects support the click method: Link, webbutton, and image)

Example:

Obj_click "^ webbutton", "$ login"

The ^ symbol in the parameter represents the test object. $ represents the parameters used in the method, which are data stored in different places. Here, it refers to the data in objectrepository.

Of course, you can also write the parameters directly, for example, obj_click "^ webbutton", "Name: = login" Name: = login is the attribute value used to describe the webbutton object.

In addition, if you are running link or image, the script must be written as follows: (other methods are similar here)

Obj_click "^ link", "$ login"

Obj_click "^ image", "$ login"

 

3. obj_exist (objtype, objproperty)

Note:

Call the exist method of the relevant object (all objects are supported)

Example:

Obj_exist ("^ link", "$ register ")

The ^ symbol in the parameter represents the test object. $ represents the parameters used in the method, which are data stored in different places. Here, it refers to the data in objectrepository. You can also write the parameters directly.

 

4. obj_getpropertyvalue (objtype, objident, objproperty)

Note:

Call the getroproperty method of the relevant object (all objects are supported)

Example:

Obj_getpropertyvalue ("^ webedit", "^ value", "$ username ")

There are two ^ symbols. The ^ symbol in the first parameter represents the test object. The ^ symbol in the second parameter, it indicates the relevant property value in the test object (that is, the webedit attribute value); $ indicates the parameters used in the method, which are data stored in different places. Here it refers to the data in objectrepository.

Get the attribute value of the value in the webedit object named $ username

 

5. obj_getvaluebyindex (objtype, objpropetry, introw, intcolumn)

Note:

Obtain the values of related indexes in weblist and webtable.

Example:

Obj_getvaluebyindex "^ webtable", "$ table", "1", "2"

The ^ symbol in the parameter indicates the test object. $ indicates the parameters used in the method and the data stored in different places. Here, it indicates the data in objectrepository. 1 indicates obtaining the first line; 2 indicates that the first 2nd columns are obtained.

To get the value in column 1st of the 2nd row of the webtable object with the attribute name $ table.

To obtain the value in weblist, set the last parameter to 0, for example:

Obj_getvaluebyindex "^ weblist", "$ list", "1", "0"

 

6. obj_select (objtype, objproperty, text)

Note:

Call the select method in ListBox and webradiogroup.

Example:

Obj_select "^ weblist", "$ list", "$ value"

The ^ symbol in the parameter represents the test object. The first $ represents the weblist attribute value. Here it refers to the data in objectrepository; the second $ represents the items selected by weblist.

The entire sentence means: Get the item named $ value in the weblist object with the attribute name $ list. Of course, we can use indexes, such as: obj_select "^ weblist", "$ list", "1"

The entire sentence means: Get the item with the index 1 in the weblist object with the attribute name $ list.

 

7. obj_set (objtype, objproperty, text)

Note:

Call the Set Method in webedit, webcheckbox, and webfile.

Example:

Obj_set "^ webedit", "$ username", "$ user"

The ^ symbol in the parameter represents the test object. The first $ represents the webedit attribute value. Here it refers to the data in objectrepository; the second $ represents the value entered in webedit, data in testdata.

The whole sentence means: Set a $ user value for the webedit object named $ username.


 

V. Script compiling example

The following is an example code of a logon script. The do_login should be the same as the method name in testplan:

Public Function do_login ()

Browseto "$ URL"

 

If obj_exist ("^ webedit", "$ username") then

Obj_set "^ webedit", "$ username", "$ user"

Msgbox obj_getpropertyvalue ("^ webedit", "^ value", "$ username ")

End if

 

If obj_exist ("^ webedit", "$ password") then

Obj_set "^ webedit", "$ password", "$ user"

Msgbox obj_getpropertyvalue ("^ webedit", "^ value", "$ password ")

End if

 

If obj_exist ("^ webbutton", "$ login") then

Obj_click ("^ webbutton", "$ login ")

End if

End Function

 

 

 

Download the PDF version of this document:

Http://files.cnblogs.com/testware/QTP_Framework_Saffron.pdf

 

 

 

 

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.