Naca
Naca

Reputation: 43

Setting Pre-emptive AuthType for Test Step in SoapUI in script

In SoapUI 5.0.0 I am trying to set the Pre-emptive auth value (Global settings or Pre-emptive) for a Test Request step via scripting. This is for Basic Authorization.

I am able to set the Username, Password, and Domain by script but not the AuthType

def testStep = testRunner.testCase.testSteps["MyTestRequest"]
testStep.setPropertyValue("Username", "myusername")
testStep.setPropertyValue("Password", "mypassword")
testStep.setPropertyValue("Domain", "domain-name")

testStep.setPropertyValue("AuthType", "Preemptive")

Upvotes: 3

Views: 2090

Answers (1)

Rao
Rao

Reputation: 21379

I am putting the required code down here, how one can set the AuthType -> Pre-emptive through the code.

Credentials, Endpoint can be a valid point of concern that they will change depending on the environment like Dev, QA, or Production etc.,

However, AuthType does not fall in the above category as it is fixed across the environments once it is set, do not have to touch it.

Script Below

import com.eviware.soapui.SoapUI
import com.eviware.soapui.settings.HttpSettings
//To enable Pre-emptive, set it true. Set it to false otherwise
SoapUI.getSettings().setBoolean(HttpSettings.AUTHENTICATE_PREEMPTIVELY, true)
SoapUI.saveSettings()

How do you check once the above script is run?

Go to(using menu) File -> Preferences -> Http Settings -> Authenticate Preemptively should be having check box tick marked when it is true. Check box unticked when it is set to false, obviously.

Another way is to check when it is set to true is that make a web service call. Then go to Raw Request tab of the request editor. You should be able to see the authentication is added into the request. Of course, when you get the valid response, that it self tells that above code actually did what is it is intended to do.

Upvotes: 4

Related Questions