Ask a Question

Oauth 2 - Script to fetch oauth profile name


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



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

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓

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


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

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Showing results for 
Search instead for 
Did you mean: