Forum Discussion

manAtWork's avatar
manAtWork
New Contributor
15 years ago

Setting HTTP Parameters via testrunner.sh

Hi everone,

I'm quite new to soapUI but so far managed to get everything done. Now I've run into a problem with the SoapUITestCaseRunner that I can't seem to be able to solve.

I need to preemptively send basic authentication to a server when running a test case with the testrunner.sh script. When using a GUI, this is togglable via the reference tab. How do I switch it on when running testrunner.sh, though? When I set the commons httpclient to DEBUG logging I can see that it uses the http.authentication.preemptive = false setting.
I tried searching the forum for preemptive and testrunner but to no avail. Seems nobody ran into this when using the testrunner.sh script.

Can anyone help?

greetz,
chris
  • kamahade's avatar
    kamahade
    Regular Contributor
    I dont know via Testrunner.sh.. I can give you a hint at teststep level.

    NOTE: will work only in 3.5.1 version

    import com.eviware.soapui.impl.wsdl.teststeps.*
    import com.eviware.soapui.support.types.StringToStringMap ;

    def tc = testRunner.testCase.testSuite.getTestCaseByName("TestCase")
    def ts2 =tc.getTestStepByName("r1")
    def headers = new StringToStringMap()
    headers.putIfMissing("Authorization","Basic VEVTVF9JJkFfU3VwZXJVc2VyOmZhYnJpYzEwMQ==")
    ts2.getHttpRequest().setRequestHeaders(headers)
    log.info ts2.getHttpRequest().getRequestHeaders()


    You can as well check this blog : http://thewonggei.wordpress.com/2010/08 ... st-suties/
  • manAtWork's avatar
    manAtWork
    New Contributor
    thanks kamahade,
    that did the trick. I combined your script with the one from the blog and another script for encoding base64 and got:

    import com.eviware.soapui.impl.wsdl.teststeps.*
    import com.eviware.soapui.support.types.StringToStringMap

    for( testCase in testSuite.getTestCaseList() ) {
    log.info("Setting HTTP basic auth for all WSDL test requests in test case ["+
    testCase.getLabel()+"]")
    for( testStep in testCase.getTestStepList() ) {

    if( testStep instanceof WsdlTestRequestStep ) {
    def headers = new StringToStringMap()
    def auth = testSuite.getPropertyValue("basicAuthUser") + ":" + testSuite.getPropertyValue("basicAuthPass")
    log.info "auth: " + auth
    def encodedAuth = auth.bytes.encodeBase64().toString()
    log.info "encodedAuth: " + encodedAuth
    headers.putIfMissing("Authorization","Basic " + encodedAuth)
    testStep.getHttpRequest().setRequestHeaders(headers)
    }
    }
    }


    when I use testrunner.sh (or testrunner.bat) from the console, the script is executed and I get basic authentication in all outgoing messages.
    For this to work, the 'basicAuthUser' and 'basicAuthPass' properties need to be set on the test suite, of course.

    thanks again!