Pending test objects in TC

Source: Internet
Author: User

When writing an automated test script, it is a common script design problem to wait for the test object to appear and then perform relevant operations on the test object. In TC, there are several methods:

(1) waiting for the web page.
In qtp, you can use browser (). page (). sync method to wait for a page to complete loading. in TC, you can use page. tourl, page. wait or waitpage, for example, the following example is used to wait until the page indicated by the specified URL address is loaded and the specified page element appears:
'Obtain the Page Object
'We assume that the browser window belongs to the iw.e process, not explorer
Set p1 = SYS. Process ("iexplore ")
Set W1 = p1.window ("ieframe", "*", 1 ). window ("shell docobject View", "", 1 ). window ("Internet assumer_server", "", 1)
Set Pg = w1.page ("*")

'Opening the page
Pg. tourl "My URL"

'Waiting for frames
Waitfrm = true
While waitfrm
For I = 0 to pg.doc ument. frames. childcount-1
Set frame = pg.doc ument. frames. Child (I)
If frame. exists then
Waitfrm = waitfrm and (frame. readystatevalue <> 4)
End if
Next

If waitfrm then
Builtin. Delay (100)
End if
Wend
...

(2) Wait for the process.
Wait for a process to appear. You can use the waitprocess method, for example, the following example:
Set P = SYS. waitprocess ("winword", 2000)
If P. exists then 'If the process exists...
...

(3) Wait for the window.
Wait for the window to be created. You can use the waitwindow method, for example, the following example:
Set P = SYS. Process ("Notepad ")
'Waits 10 seconds for the window
Set W = P. waitwindow ("*", "Open *",-1, 10000)
If W. exists then
W. Activate
Log. Picture W, "Open dialog picture"
Else
Log. Warning "Incorrect window"
End if

(4) waiting for object attributes.
Wait for the attribute of an object to be equal to the specified state value. You can use the waitproperty method, for example, the following example:
Set BTN = SYS. Process ("MyApp"). Window ("tmainfrm", "myapplication *"). Child (2)
If BTN. waitproperty ("enabled", true, 2000) then
'Button is enabled
Else
'Button is disabled
Wend

(5) Wait for a son object to appear.
The waitchild method is available when a son object under the test object appears. For example:
If obj. waitchild (childobjectname, 0). exists then
'Child object exists
Else
'There is no such a child
End if

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.