You can use Groovy scripts to change the authorization profile and credentials that will be used for a request.
Where to use
There are several ways to run this script:
-
As a Groovy Script test step.
-
As a setup or teardown script on the test case level in functional tests.
Example 1 – For Basic authorization
Groovy
import com.eviware.soapui.config.AuthEntryTypeConfig
def request = testRunner.testCase.getTestStepByName("Name of the Request").getHttpRequest()
request.setSelectedAuthProfile(AuthEntryTypeConfig.BASIC.toString())
request.username = "NewUserName"
request.password = "NewPassword"
request.domain = "NewDomain"
Example 2 – For a custom authorization profile
Groovy
import com.eviware.soapui.config.AuthEntryTypeConfig
def authProfileName = "Name of your profile"
def project = testRunner.getTestCase().getTestSuite().getProject()
def authProfile = project.getAuthRepository().getEntry(authProfileName)
authProfile.setUsername("newUsername")
authProfile.setPassword("newPassword")
authProfile.setDomain("newDomain")
//Set to true for pre-emptive authentication
//Set to false for using global preference
authProfile.setPreemptive(true)
def step = testRunner.testCase.getTestStepByName("Name of your request").getHttpRequest()
step.setSelectedAuthProfile(authProfileName)