matthew byrom
matthew byrom

Reputation: 1

Using groovy script to set authorization to basic in SoapUI

Screen Shot

I am using groovyscript to run and test SOAP messages to my server. I need my messages to have the basic authorization. I know you can do this manually using the tab under the soap message. I can enter my username and PW using the TestRequest Properties, however I can't find a way to set the auth to basic. I tried editing the 'Authentication Type' property to "Global GTTP Settings", which is the value it's given when I set basic auth manually. As you can see in the code, there are no errors running it and it eddits PW, username, but not Auth Type. Is there a way to either change the property so the message has a basic Auth, or a different way to set basic auth with a UN and PW? The goal is to be able to test several SOAP messages while setting the authentication to basic and give it the UN and PW.

Code/Groovy Script:

def TR = 
testRunner.testCase.testSuite.testCases["Get"].testSteps["getEmployee"]
TR.setPropertyValue("Username","usernamehere")
TR.setPropertyValue("Password","passwordgoeshere")
TR.setPropertyValue("Authentication Type","Global HTTP Settings")
log.info "done"

Current result: changed UN and PW properties, can't change the Authentication Type property.

Goal: give the SOAP message Basic Auth using groovy script

Upvotes: 0

Views: 1585

Answers (1)

Marek
Marek

Reputation: 448

could you, please, try and check this solution?

def httpRequest = context.testCase.getTestStepByName("test_step").getHttpRequest();

httpRequest.setSelectedAuthProfileAndAuthType("Basic", com.eviware.soapui.config.CredentialsConfig.AuthType.PREEMPTIVE);
httpRequest.setUsername("username");
httpRequest.setPassword("password");

here is the link to the API of this class: https://www.soapui.org/apidocs/com/eviware/soapui/impl/support/AbstractHttpRequest.html

Marek

Upvotes: 1

Related Questions