Forum Discussion

mgroen2's avatar
mgroen2
Super Contributor
8 years ago

Capture token in url and re-use it

Hi,

I am writing tests for testing a web application. This web application uses accesstokens, to authenticate a user.

After having logged into the webapplication, the url is displayed as follows:

 

http://localhost:4000/main?accessToken=weoiwjfwoefnawioefnOHOHOE&sessionId=b7b8ab96-7c75-40e3-a54c-be8cb90d4

 

The values for accessToken and sessionId changes after every login. So, now my tests fail after every login because of changed values for accesstoken and sessionID.

 

To make my tests re-usable, I want to capture the accesstoken and sessionId in variables, and use these in the name mapping so that my tests are versatile.

What is the best approach for this?

 

Thanks,
Mathijs

 

 

Is this a good approach? 

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    For namemapping, you shouldn't need to capture the tokens.  Simply replace the variable parts of the URL string in your namemapping with an asterisk (*) like http://localhost:4000/main?access=*&sessionid=*.

     

    For that matter, you might be able to just replace everything after the ? with the asterisk.

    • mgroen2's avatar
      mgroen2
      Super Contributor

      tristaanogre wrote:

      For namemapping, you shouldn't need to capture the tokens.  Simply replace the variable parts of the URL string in your namemapping with an asterisk (*) like http://localhost:4000/main?access=*&sessionid=*.

       

      For that matter, you might be able to just replace everything after the ? with the asterisk.


      Hi tristaanogre,

       

      thanks for the tip.

      Suppose I want to 'catch'  the values for the accesstoken, and sessionId, and save them in a variable. How to do that?

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        You'll have to write some sort of function to parse the URL to grab those values, I'd imagine, using some combination of aqString methods to find the segments and pull them out. I think I recall somewhere that those values might be saved as properties or attributes on the page object itself but I can't guarentee the veracity of that. Because they are such variable values and I haven't had need to use them in functional testing, I can't help much with specifics on this. Sorry. :(