cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot change request's username and password dynamically

SOLVED
Highlighted
Frequent Contributor

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Moderator

Re: Cannot change request's username and password dynamically

If you use Auth profiles, you can change credentials as it is described in this article: 

https://smartbear-cc.force.com/portal/KbArticleViewer?name=How-to-change-credentials-for-an-auth-pro... 



 Join SmartBear Connect next April in Boston to meet with software development, API and testing experts from around the world! Get your ticket today!

View solution in original post

3 REPLIES 3
Moderator

Re: Cannot change request's username and password dynamically

If you use Auth profiles, you can change credentials as it is described in this article: 

https://smartbear-cc.force.com/portal/KbArticleViewer?name=How-to-change-credentials-for-an-auth-pro... 



 Join SmartBear Connect next April in Boston to meet with software development, API and testing experts from around the world! Get your ticket today!

View solution in original post

Highlighted
Community Manager

Re: Cannot change request's username and password dynamically

Nastya, great job providing us with the arcticle!

 

Hi @krogold , did it work?



Sonya Mihaljova
Community and Education Specialist

 Join SmartBear Connect next April in Boston to meet with software development, API and testing experts from around the world! Get your ticket today!
Highlighted
Frequent Contributor

Re: Cannot change request's username and password dynamically

sorry, I didn't have the time to test it yet, but it sounds very interesting, I'll give you a feedback as soon as possible

thanks