SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 6 of 6
  1. #1
    Member graemeal's Avatar
    Join Date
    Nov 2005
    Location
    Belfast
    Posts
    326
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Can I access javascript variables in AUT?

    Hey,

    I have an web app that sets a javascript variable on that page. Can I check the value of this variable?

    All help appreciated!
    Graeme

  2. #2
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: Can I access javascript variables in AUT?

    Yes. Look at EmbedScript and RunScript method of the Browser and the page object

  3. #3
    Advanced Member
    Join Date
    May 2007
    Posts
    609
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    2 Thread(s)
    Total Downloaded
    0

    Re: Can I access javascript variables in AUT?

    This might be useful with some adjustments. RH is a ReportHandler class I wrote... replace it with your reporting method of choice (e.g. reporter.reportEvent).

    <font class="small">Code:</font><hr /><pre>
    Public Function GetJavaScriptValue(valueName,returnVal)
    On error resume next
    Dim browserObject

    If isempty(activeBrowser) Then
    set activeBrowser = Browser("micClass:=Browser", "CreationTime:=0")
    End If

    Set browserObject = activeBrowser.Object

    err.clear

    returnVal = eval("browserObject.document.script." &amp; valueName)

    If err.number &lt;&gt; 0 Then
    If err.number = 438 Then
    RH.WriteError "GetJavaScriptValue", "The JavaScript variable '" &amp; valueName &amp; "' did not exist."
    Else
    RH.WriteError "GetJavaScriptValue", "An unknown runtime error occurred. Err.number: " &amp; err.number
    End If
    End If
    GetJavaScriptValue = err.number
    End Function
    </pre><hr />
    Dennis Belew

  4. #4
    Member graemeal's Avatar
    Join Date
    Nov 2005
    Location
    Belfast
    Posts
    326
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Can I access javascript variables in AUT?

    Thanks Dennis!
    That works great.
    You da man!
    Graeme

  5. #5
    Member graemeal's Avatar
    Join Date
    Nov 2005
    Location
    Belfast
    Posts
    326
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Can I access javascript variables in AUT?

    One more question.
    I can access javascript variables, but I also want to access javascript variables within objects.
    I'm on QTP 10, and I think EmbedScript &amp; RunScript are from QTP 11 only.
    Anyone any other ideas on accessing js variable within object with QTP 10?
    Graeme

  6. #6
    Advanced Member
    Join Date
    May 2007
    Posts
    609
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    2 Thread(s)
    Total Downloaded
    0

    Re: Can I access javascript variables in AUT?

    It will work the same as any other javascript variable. In the function above, just send object.variable for the valueName parameter.
    Dennis Belew

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.54%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 04:11 PM.

Copyright BetaSoft Inc.