Simple monkey testing using qtp in Web Applications

Source: Internet
Author: User

Qtp allows simple monkey testing on Web Applications
For example, you can traverse every link on the home page, select a link each time, click the link, return to the home page, select the next link, and so on. During the test, each action is written to the test log.

 

The following code is taken from codesamplesplus of qtp and some necessary modifications are made:

 

'Start IE browser
Systemutil. Run "ipolice.exe"

'Save the report filter mode
Oldfilter = Reporter. Filter
Reporter. Filter = 2' enables errors only
 
'Link Description
Set DESC = description. Create ()
DESC ("HTML Tag"). value = ""
DESC ("href"). value = "http://blog.csdn.net/testing_is_believing/category /.*"

Set browserobj = browser ("creationtime: = 0 ")
'Navigate to the specified page
Browserobj. navigate "http://blog.csdn.net/Testing_is_believing/category/357781.aspx"
Set pageobj = browserobj. Page ("index: = 0 ")
 
'Start monkey testing"
Call enumerateapp (pageobj, DESC, "click", "reportpage", "browserback ")
 
Reporter. Filter = oldfilter 'returns the original Filter

'Traverse the entire program and perform the specified operation. For example, click each link.
Function enumerateapp (parentobj, DESC, operationmethod, postoperationmethod, restoremethod)
Dim objcol, currentobj, idx
Idx = 0
'Retrieve a collection of all the objects of the given descrition get all sub-objects according to the specified description
Set objcol = parentobj. childobjects (DESC)
 
Do While (idx <objcol. Count)
'Get the current object
Set currentobj = objcol. Item (idx)

'Perform the desired operation on the object to perform the specified operation, such as click
Eval ("currentobj." & operationmethod)

'Form the post operations (after the object operation) the action to be performed after the specified operation is completed, such as writing test logs
Eval (postoperationmethod & "(parentobj, currentobj )")

'Return the application to the original state to bring the program back to the initial state, for example, let the browser navigate back to the home page
Eval (restoremethod & "(parentobj, currentobj )")
 
Idx = idx + 1
'Reretrieve the collection of objects
'(As the application might have changed)
Set objcol = parentobj. childobjects (DESC)
Loop
End Function
 
'Write test log
Function reportpage (parentobj, currentobj)
Dim funcfilter, pagetitle
 
Pagetitle = parentobj. getroproperty ("title ")
 
Funcfilter = Reporter. Filter
Reporter. Filter = 0
Reporter. reportevent 0, "page information", "page title" & pagetitle
Reporter. Filter = funcfilter
End Function

'Press the return key on the browser.
Function browserback (parentobj, currentobj)
On Error resume next
Browserobj. Back
End Function

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.