Forum Discussion

danielseoane7's avatar
danielseoane7
Occasional Contributor
14 years ago

Need help using GroovyScript

I'm using the trial version for soapui pro and i'm having a little trouble..

I'm testing a web service and im trying to obtain an authorization token (like a session id) after I log in. I need to use this "token" to use the other web services features. I would use property transfer but unfortunately my data is located within CDATA tags. how may i go about getting this information? I was told groovyscript would be best for this from reading other posts...


Thanks

25 Replies

  • danielseoane7's avatar
    danielseoane7
    Occasional Contributor
    M McDonald wrote:
    The script log should at least have a time stamp even if there is no content:

    [tt:a4nlnv31]Thu Jul 12 10:16:06 EDT 2012:INFO:[/tt:a4nlnv31]

    That is the error log; the error is occurring when you try to create the XML holder with something it doesn't like. An empty argument could be one of those. Somehow you are not getting the response content that you should.

    Just to prove the script works, try embedding the (abbreviated) response in the Groovy script and see that you get the token:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

    //def response = context.expand( '${loginClerk#Response}' )
    def response = '''<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
    <ns2:loginClerkResponse xmlns:ns2="randomsite.com/">
    <return><![CDATA[<random><status>100</status><statusMessage>Login Accepted</statusMessage><response><authToken>l463ddsgs4xkhrw3j1yg19uf</authToken></response></random>]]></return>
    </ns2:loginClerkResponse>
    </S:Body>
    </S:Envelope>'''
    log.info response

    def holder = groovyUtils.getXmlHolder( response )
    def cdata = holder.getDomNode('//return/text()').nodeValue

    def holder2 = groovyUtils.getXmlHolder( cdata )
    def authToken = holder2.getDomNode('//authToken/text()').nodeValue
    log.info authToken
    return authToken



    yup, it went through. it said the auth token after i ran the groovy script...
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    So that narrows the problem to getting the response. Can you export your test case and attach it? To export, right-click on the test case in the Navigator pane and select Export.
  • danielseoane7's avatar
    danielseoane7
    Occasional Contributor
    M McDonald wrote:
    The request step name is actually 'loginClerk - Request 1'.



    I changed it. got it. thanks a lot for your help!