Showing results for 
Search instead for 
Did you mean: 

Oauth 2 - Script to fetch oauth profile name

New Contributor

Oauth 2 - Script to fetch oauth profile name

I am trying to fetch the auth profile name that is selected for this environment at the test sutie level.


I am using below code, please help me debug the issue on first line


String oAuthProfile = testRunner.testCase.getTestStepByName("Groovy Script").getSelectedAuthprofile()

def oAuthProfile = context.getCurrentStep().testCase.testSuite.project.getAuthRepository().getEntry(oAuthProfile)


Also am newbie, how do i figure out various classes and methods available in readyapi to use in groovy script



Re: Oauth 2 - Script to fetch oauth profile name

Hello @subhaD,


To get name and type of the auth profile applied to the current TestSuite you can use this script:


def ts = testRunner.testCase.testSuite
def profileName = ts.getAuthProfile()
if (profileName == "Inherit From Parent"){
	profileName = ts.project.getAuthProfile()
} "Profile name for current TestSuite: " + profileName
	def profileType = ts.project.getAuthRepository().getEntry(profileName).getType() "It is custom profile created from: " + profileType
} catch (e){"It is build-in profile")


To find available classes and methods to use in your Groovy scripts, please refer to API Java Docs: 


Customer Care Team
New Contributor

Re: Oauth 2 - Script to fetch oauth profile name

Thanks for the reply.


But am changing to diff Environemnt and diff Oauth2 Profile saved with that.

When that happens I want to see what is associted with env and select that auth profile to check token status.


//Get Token Status
def oAuthProfile = project.getAuthRepository().getEntry("Qa-Oauth")
//String oAuthProfile = testRunner.testCase.getTestStepByName("Groovy Script").getSelectedAuthprofile()
def TokenStatus = oAuthProfile.accessTokenStatus.toString() "Access Token Status is: $TokenStatus"


I am trying to change first line with second line, instead of hardcoding the profile name, i want to get that dynamically of what is selected for that env



Re: Oauth 2 - Script to fetch oauth profile name

Hi @subhaD


Instead of your second commented line, you can use this code snippet to get the name of the auth profile, which is applied to a needed service, within the current environment:


def env = context.testCase.testSuite.project.getActiveEnvironment()
def restServ = env.getRestServiceAt(0);





About getting service by name rather than by index you can read here:


I hope I understood your task correctly this time.


Customer Care Team
API Summer News

Congratulate last week's winners here:
1. @sanj - $50
2. @Sehuang and @aaronpliu - $35
3. @jhanzeb1 - $15

To do this week:
- Ask product-related questions
- Reply to any questions

Win $50, $35 or $15 gift card!
Winners will be decided next Monday (Aug 27)

Top Kudoed Authors
Are You In?