Forum Discussion

subhaD's avatar
subhaD
Contributor
7 years ago

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()
    }
    log.info "Profile name for current TestSuite: " + profileName
    try{
    	def profileType = ts.project.getAuthRepository().getEntry(profileName).getType()
    	log.info "It is custom profile created from: " + profileType
    } catch (e){
    	log.info("It is build-in profile")
    }

     

    To find available classes and methods to use in your Groovy scripts, please refer to API Java Docs: https://support.smartbear.com/readyapi/docs/configure/plugins/dev/background/api.html 

     

    • subhaD's avatar
      subhaD
      Contributor

      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()
      log.info "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