Use descriptive programming (instance) in qtp)

Source: Internet
Author: User

Using descriptive programming in qtp is a good way to improve the qtp script utilization.

Generally, qtp identifies different objects through the object library, while descriptive programming is another way for qtp to recognize objects. It does not depend on the object library, identify objects by adding object descriptions.
 
Note: This example is described on the test page on the login page of the flight aircraft ticket booking system.
 

Step 1: Recording script

  1. Dialog ("login"). winedit ("agent name:"). Set "Holly"
  2. Dialog ("login"). winedit ("Password:"). setsecure "46ef0dc7efe5834c74253898279af1204fea51a7"
  3. Dialog ("login"). winbutton ("cancel"). Click

In three steps, enter the agent name and password and click the cancel button.
 

Step 2: elementary descriptive Programming

  1. Dialog ("regexpwndtitle: = login"). winedit ("attached text: = agent name:"). Set "Holly"
  2. Dialog ("regexpwndtitle: = login"). winedit ("attached text: = password:"). Set "Mercury"
  3. Dialog ("regexpwndtitle: = login"). winbutton ("Class Name: = winbutton", "text: = Cancel"). Click

Note the following three points:
1) if you need more than two features to describe an object, you must use commas (,) to separate descriptive languages.
2) Use: = to connect attributes and attribute values, and: = There cannot be spaces on both sides
3) Use spy to view the object's property name and attribute value (tools-> Object spy)
 

Step 3: Improve descriptive Programming

  1. Dim desceditlogin
  2. Set desceditlogin = description. Create ()
  3. Desceditlogin ("Class Name"). value = "dialog"
  4. Desceditlogin ("regexpwndtitle"). value = "login"
  5. Dialog (desceditlogin). winedit ("attached text: = agent name:"). Set "Holly"
  6. Dialog (desceditlogin). winedit ("attached text: = password:"). Set "Mercury"
  7. Dialog (desceditlogin). winbutton ("Class Name: = winbutton", "text: = Cancel"). Click

Note the following two points:
1) define frequently used objects as an object variable to facilitate future calls and reduce code workload and errors
2) use spy to get object attributes and attribute values
 

Step 4: Use custom environment variables
Choose File> Settings> environment and select user-defined to add a variable.
Dlglogin = "login"
 
In this way, the script can be changed:

  1. Dim desceditlogin
  2. Set desceditlogin = description. Create ()
  3. Desceditlogin ("Class Name"). value = "dialog"
  4. Desceditlogin ("regexpwndtitle"). value = environment. Value ("dlglogin ")
  5. Dialog (desceditlogin). winedit ("attached text: = agent name:"). Set "Holly"
  6. Dialog (desceditlogin). winedit ("attached text: = password:"). Set "Mercury"
  7. Dialog (desceditlogin). winbutton ("Class Name: = winbutton", "text: = Cancel"). Click

Of course, there are many parameterization methods. Here we will introduce the use of environment variables.
 

Step 5: Import environment variables from an XML file

  1. <Enviroment>
  2. <Variable>
  3. <Name> dlglogin </Name>
  4. <Value> login </value>
  5. </Variable>
  6. </Environment>

You can use manual or loadfromfile for automatic import.
 
Summary:
The advantage is that the script is easier to maintain after some attributes of the object are changed.
For example, for a common object, such as Save, reset, and cancel, there are three buttons on a page, and 90 objects on 30 pages,
If you change save to save, reset to reset, and cancel to cancel, the object library will change a lot.
For descriptive programming, you only need to modify a value in the imported XML file.
Of course, descriptive programming has far more functions than that. This time, it is just a reference and I hope everyone can make common progress.

Note: The original source cannot be indicated because I have seen another person's post in this article. Please forgive me.

Related Article

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.