Forum Discussion

AAB's avatar
Regular Contributor
3 years ago

ReadyAPI - add webbased actions for token retrieval

Hi, Could someone help me to add webbased actions to retrieve the token please?   Explanation: I've retrieved my JWT token by using the AuthManager, but up to the moment where the user needs to l...
  • TNeuschwanger's avatar
    3 years ago

    Hello AAB 


    I tried to unpack your question...  If reading to the end, it seems like you have a work around by using a groovy script to accomplish what you ask for guidance about at the top of your post.   I can offer tips or techniques to you that you can further question or discard.


     --  Auth Manager...  I didn't even know that existed.  🙂  When I have needed an OAuth token in the past, i just had a testcase or teststep that I would invoke OAuth token generator itself instead of adding a middle man of Auth Manager.  If you look at all the URL's that you need to provide in the Auth Manager user interface, why not invoke them yourself in a testcase or teststep for better control.  After all, this is ReadyAPI and it invokes API's very well. 🙂 Auth Manager is just invoking them for you.  In short, my technique is to call needed URL's yourself to get JWT or Auth code and abandon Auth Manager.  This may or may not suite your needs but has worked for me in the past.


    -- "I'm looking for a way to do it on the most highest level possible for maintenance purposes."... All the way from the project level on down, the running of an action has a "Setup Script" (in the tabs along the bottom of the editor) available to you to interject code to run at that level.  Put your work around groovy script that you shared in at the highest levels "Setup Script" so that you only maintain it once.  The technique I use is to put a teststep in at testcase in a suite that I have disabled.  I call that testcase/teststep from every location I need it with a couple of lines of groovy script code.  I do have to perpetuate that in all the testcases that I need the code in, but it is just a call out to single task that I only maintain once in the disabled testsuite.  Below is a sample, but googling for ways to invoke a common testcase/teststep are plentiful and often meet needs of keeping code in one place for maintainability.

    def invokeTestSuiteName = 'Common Code';
    def invokeTestCaseName = 'Global Processing By Test Case Name';
    def properties = new;
    def async = false;
    testRunner.testCase.testSuite.project.getTestSuiteByName(invokeTestSuiteName).setPropertyValue(invokeTestSuiteName.replaceAll('\\s', '') + "testCaseName",;
    def result = testRunner.testCase.testSuite.project.getTestSuiteByName(invokeTestSuiteName).getTestCaseByName(invokeTestCaseName).run (properties, async);
    def httpResponse = testRunner.testCase.testSuite.project.getTestSuiteByName(invokeTestSuiteName).getPropertyValue( invokeTestSuiteName.replaceAll('\\s', '') + "APIHttpResponse");
    def requestId = testRunner.testCase.testSuite.project.getTestSuiteByName(invokeTestSuiteName).getPropertyValue( invokeTestSuiteName.replaceAll('\\s', '') + "APIRequestId");
    assert (result.status.toString() == 'FINISHED'), "Invoked testcase should have a 'FINISHED' result but it was a '" + result.status.toString() + "' result instead.  " + httpResponse + '  ' + requestId;