Forum Discussion

Stalsy's avatar
4 years ago

Authorisation token expires too soon

 I'm running data-driven tests that have 5 steps: 1. Get new Authorisation token 2. DataSource (get a few thousand random rows from DB2) 3. REST Request  4. Assert script  5. DataSource Loop ...
  • Stalsy's avatar
    4 years ago

    The acquisition of a new access token is very slow so I can't afford to have it inside the loop. As you can see from the code snippet below I request for a new token and then wait in a loop till I have one:

    def oldToken = oAuthProfile.getAccessToken();

    def oAuthClientFacade = new OltuOAuth2AzureClientFacade (TokenType.ACCESS);
    oAuthClientFacade.requestAccessToken(oAuthProfile, true,true);

    while(oldToken == oAuthProfile.getAccessToken())



    I'm pretty happy with what I've got now:

    I get the access token in the TestRunListener.beforeRun event which also sets a test case property "Duration" to the time I want to wait till I need another token.

    Inside the test loop, in my groovy asserts script, I check if the test has been running for a time exceeding the Duration property, and if yes, I get a new access token and increment the Duration property