Forum Discussion

Gonzarelli's avatar
Gonzarelli
New Contributor
25 days ago

How do I change password and Username on every call in a Test Case in SoapUI?

The user ID and password I use for my automated testing and API work in Soap UI needs to change. Because I rely so heavily on Soap UI, I haven't change the password for far too long. As part of testing that change, I want to change the Username to something harder to predict as well as the password. I know the username and passwords are all stored in the XXX-soapui-project.xml file. I have the username in there 9,429 times. I don't want to change those one at a time.

I thought maybe a quick search and replace would do it, but that seems to break the project. I'm happy to test it on just one Test Case, or a copy of the whole Project. Does anyone know how I can do this without change every single Username and password? 

  • Update: Yes, I created global properties to store a bunch of variables. I created a great big list in Excel and imported them. That didn't fix the fact that I had hundreds to change. 

    Then I created a new blank Project, and a new Test Suite, then I cloned over the latest and most complicated Test Case. I saved this, exited SoapUI, then used Notepad++ to do a replace.

    I searched for (names changed to protect the innocent):

    <con:username>OpsUser$109</con:username><con:password>73Marlin</con:password>

    And replaced it with:

    <con:username>${Uid109}</con:username><con:password>${UidPW}</con:password>

    Where ${Uid109} is Global Property Uid109 which contains OpsUser$109 and ${UidPW} contains 73Marlin. I just changed one user id first, and then went back into SoapUI and checked the impacted steps worked. They did, so I exited SoapUI, loaded up the Project in Notepad++ and did the rest. I now have a 296 step Test Case running with the credentials from the Global Properties. Not sure why the search and replace was corrupting the Project, but doing search and replace with the larger block of text seems to be a winner. 

    From now on I just use Global Properties, still have tons of others to update but I can do them as needed. 

    Hopefully this might be useful to know for someone else.

  • Gonzarelli's avatar
    Gonzarelli
    New Contributor

    Additional - I know about the Set Test Case Credentials option but that is all calls in one test case and my userids do vary a little (my userids represent multiple companies, they are differentiated with a $ delimiter so I have userid$1 and userid$27 and so on, I want to change them to newuserid$1 and newuserid$27 also I have some that are completely different user IDs so I'd like to change them to something separate as they have different attributes). Pretty sure that Set Test Case Credentials will just change everything in one Test Case.

  • Gonzarelli's avatar
    Gonzarelli
    New Contributor

    I've now figured out how to set multiple userids as Global parameters and also passwords. It was surprisingly easy. That still requires change every single call, but gives me a long term method for updating userids or passwords once. A way to do a global replace would still be much appreciated.

  • TSOHost's avatar
    TSOHost
    New Contributor

    To change the username and password on every call in a SoapUI test case, you can use Property Transfers to dynamically set the values for each request. You can also configure the test step to load credentials from an external source like a file or environment variable.

  • Gonzarelli's avatar
    Gonzarelli
    New Contributor

    Update: Yes, I created global properties to store a bunch of variables. I created a great big list in Excel and imported them. That didn't fix the fact that I had hundreds to change. 

    Then I created a new blank Project, and a new Test Suite, then I cloned over the latest and most complicated Test Case. I saved this, exited SoapUI, then used Notepad++ to do a replace.

    I searched for (names changed to protect the innocent):

    <con:username>OpsUser$109</con:username><con:password>73Marlin</con:password>

    And replaced it with:

    <con:username>${Uid109}</con:username><con:password>${UidPW}</con:password>

    Where ${Uid109} is Global Property Uid109 which contains OpsUser$109 and ${UidPW} contains 73Marlin. I just changed one user id first, and then went back into SoapUI and checked the impacted steps worked. They did, so I exited SoapUI, loaded up the Project in Notepad++ and did the rest. I now have a 296 step Test Case running with the credentials from the Global Properties. Not sure why the search and replace was corrupting the Project, but doing search and replace with the larger block of text seems to be a winner. 

    From now on I just use Global Properties, still have tons of others to update but I can do them as needed. 

    Hopefully this might be useful to know for someone else.

  • HostMyCode's avatar
    HostMyCode
    New Contributor

    You can dynamically change the username and password for each request by using test case properties and Groovy scripts in SoapUI. This ensures that the credentials are updated before every API call in your test case.