Forum Discussion

krogold's avatar
krogold
Regular Contributor
5 years ago
Solved

Cannot change request's username and password dynamically

Hello,

 

I'm trying to change my environment dynamically. I thought I managed to do it as it works as far as endpoint is concerned, but it does not work when I want to change credentials.

 currently I'm doing the following :

 

 

project = testRunner.testCase.testSuite.project

// parse all the REST requests 
// updating endpoint and credentials require to modify only once
found = false 
project.testSuites.find(){
    ts ->
    ts.getValue().getTestCaseList().find(){
        tc ->
        
        tc.getTestStepList().find(){
            step ->
            //log.info step.config.type

            if ((tc.name.contains("/m2m/fim/items"))&&( step.config.type == "restrequest"))
            {
                current_endpoint = step.getPropertyValue("endpoint")

                // update environment if it is not the one expected 
                if (current_endpoint != basic_box_endpoint)
                {
                    step.setPropertyValue("endpoint", basic_box_endpoint)

So far this works, my requests point to the correct endpoint, but when it comes to update the credentials it does not work

                    if( (basic_box_username == "")||(basic_box_password == ""))
                    {
                        msg = "the current Username and/or Password have not been set for environment $basic_box_endpoint"
                        testRunner.fail(msg)
                        log.error msg
                    }
                    else
                    {
                        step.setPropertyValue("Username", basic_box_username)
                        step.setPropertyValue("Password", basic_box_password)
                        log.info "updated environment to $basic_box_endpoint"
                    }
                }

I tried a different approach, and made some tests but it seems that it is not possible ot update credentials this way, am I wrong ?

                current_endpoint = step.getPropertyValue("endpoint")
log.info current_endpoint
log.info "------------------ http req " + step.getHttpRequest().username
log.info "username ? " + step.getHttpRequest().getUsername() => admin
step.getHttpRequest().setUsername("test")
log.info "username ? " + step.getHttpRequest().getUsername() => admin ??

or maybe there is a particular way to do it ?

 

thank you

 

 

3 Replies