Login   /   Register

Reusing Web-Objects after the page reloads

Rate this article
     3 votes, average: 4.67 out of 53 votes, average: 4.67 out of 53 votes, average: 4.67 out of 53 votes, average: 4.67 out of 53 votes, average: 4.67 out of 5
Loading ... Loading ...
May 27th, 2008 by Yaron Assa

Will Roden from the Software Inquisition writes about a major undocumented feature in QTP, which could potentially allow you to write far more elegant test than though possible to date.

One of the more frustrating limitations of QTP web test objects was that they went out of sync whenever the webpage reloaded. This means that if you held a reference to a web-object, you couldn’t could on it to work throughout your script.

For example, this script would break at the last line, since the reference was no longer valid after the webpage reloads:

Set oBrowser = Browser("version:=inter.*")
oBrowser.navigate "http://www.google.com" 'Just navigate to a demo page
Set oWebEdit = oBrowser.WebEdit("name:=q", "index:=0″) 'Get a reference to a web object
oWebEdit.Set "software inquisition"
oWebEdit.submit 'This causes the page to reload
oBrowser.sync
 
'The next line would break
oWebEdit.Set "wally llama" 

This means that you cannot count on your variables and references, thus making your script far less elegant than they could have been.

Well, luckily, Will found out an undocumented method which apparently solves the problem. By using a .Init command after the page loads, the web-object "resyncs", and the script will not break:

Set oBrowser = Browser("version:=inter.*")
oBrowser.navigate "http://www.google.com"
Set oWebEdit = oBrowser.WebEdit("name:=q", "index:=0″)
oWebEdit.Set "software inquisition"
oWebEdit.submit 'Page reloads
oBrowser.sync
 
'This "resyncs" oWebEdit:
oWebEdit.init
 
'Now the next line will work
oWebEdit.Set "wally llama" 

 

This means that we can use references, variables, function, and everything we’d ever wanted - we just have to remember to use the .Init command, and all will be well.

 

This post, code examples and knowledge were all taken from this article at Will Roden’s excellent QTP and QA blog - the Software Inquisition.

Posted in Yaron Assa's Blog, web

6 Responses to “Reusing Web-Objects after the page reloads”

  1. chikki Says:

    [-]

    This article is very useful.its really helps a lot

  2. Haridas Says:

    [-]

    Awesome!

  3. kavic.rose Says:

    [-]

    Excellnent!!!

  4. Yaron Assa Says:

    [-]

    That thankyou should go to Will from the Software Inquisition.

  5. bashville Says:

    [-]

    Nice one!

  6. Secret Methods of QTP Objects | AdvancedQTP Says:

    [+]

    [...] Init - As described here, re-links the test-object to the runtime object. Especially useful in a web environment, after a [.... ...

Leave a Reply

You must be logged in to post a comment.

This article was viewed 1196 times