Not able to set basic authentication for all test requests across all test suites in a REST project.
I am trying to set basic authentication in all requests across multiple test suites in a REST project. To achieve that I am using a groovy script(kept in a different test suite), to set the username, password and endpoint for all requests.
The problem seems to be that the username and password is reflected correctly in the Custom Properties section but when I run the actual REST service, there is an error since the authentication details are not taken up.
Mentioned below is groovy Script I am using. Any insight into this issue is appreciated.
SOAPUI version : Open Source v5.2.1
Groovy Script
import com.eviware.soapui.SoapUI
import com.eviware.soapui.settings.HttpSettings
/* Explantion for the Groovy to set properties for all testsuites/testcases and testrequests inside a SOAP project
* ===================================================================================
* def Project : this identifies all the test suites present inside the project
* def soapSuites : this identifies all the test cases inside the project
* def soapRequestsList : this identifies all the requests inside a test case
* method setPropertyValue : used to set all the properties as desired
*
* Auth preemptively is set true at the SOAP level
* ===================================================================================
*/
def project = context.testCase.testSuite.project;
for (testSuite in project.testSuiteList) {
//log.info testSuite.name;
def soapSuites = testSuite.getTestCaseList()
for(soapTestCase in soapSuites){
//log.info soapTestCase.name
def soapRequestsList = soapTestCase.getTestStepList()
//log.info soapRequestsList.name
for(soapRequest in soapRequestsList ){
soapRequest.setPropertyValue("Username","<username>")
soapRequest.setPropertyValue("Password","<password>")
soapRequest.setPropertyValue("Endpoint","<Using the endpoint of the environment under test>")
}
}
}
//To enable Pre-emptive authentication, set it true. Set it to false otherwise.
//This is a SOAP level setting and is applicable for all projects in SOAPUI
SoapUI.getSettings().setBoolean(HttpSettings.AUTHENTICATE_PREEMPTIVELY, true)
SoapUI.saveSettings()