Forum Discussion

krogold's avatar
Regular Contributor
5 years ago

Cannot change request's username and password dynamically



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 
    ts ->
        tc ->
            step ->
            // step.config.type

            if (("/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"
                        log.error msg
                        step.setPropertyValue("Username", basic_box_username)
                        step.setPropertyValue("Password", basic_box_password)
               "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") current_endpoint "------------------ http req " + step.getHttpRequest().username "username ? " + step.getHttpRequest().getUsername() => admin
step.getHttpRequest().setUsername("test") "username ? " + step.getHttpRequest().getUsername() => admin ??

or maybe there is a particular way to do it ?


thank you



3 Replies