Forum Discussion

jfnumainville's avatar
jfnumainville
Occasional Contributor
9 months ago

TestRunListener beforeRun: Get test step auth profile name

I created a "TestRunListener.beforeRun" event in order to refresh an expired OAuth token before a test step is ran using the Groovy script of this support page. 

 

I noticed that the auth profile entry name (Ora Bannet) is hard coded: 

def authProfile = project.getAuthRepository().getEntry("Ora Bannet");

 

Is there a way to dynamically retrieve the auth entry name? This would allow to make my event applicable to all the auth profiles used in my project. 

 

Thank you in advance for your help! ðŸ˜€

1 Reply

  • nmrao's avatar
    nmrao
    Champion Level 3

    jfnumainville 

    You can define a project custom property and define the value.

    For eg:

    key : AUTH_REPO_ENTRY

    value: Ora Bannet / change any time you want or even pass the value from command line arguments without modifying the value in the project

     

    And use the above property in the event, so that you need not to modify the script.

    Of course, have the change the script as below to refer the above defined the property.

     

    def authProfile = project.getAuthRepository().getEntry(project.getPropertyValue('AUTH_REPO_ENTRY'))