Forum Discussion

StooH's avatar
StooH
New Contributor
5 years ago

Groovy Scripts & Base64 Encoding

Hi guys,

 

I'm new to SoapUI and I'm currently creating a SOAP project to test an API and part of the XML request that is sent needs to include user authentication which is a base64 hash of the username and password.

 

At the moment I'm creating the hash using a simple python script then copy & pasting it in to my XML request which is fine for the moment but what I'd rather do is automate the generation of the hash and inserting it in to the request.  What I'm trying to figure out is whether I can do this using a groovy script or if there is a way to get SoapUI to interact with my python script?

 

Any help appreciated.

  • Hi StooH :

     

    You can store the output in class level property by following:

     

    testRunner.testCase.setPropertyValue("KEYNAME", OUTPUT);

     

    and store where ever in Test Case you wanted to use if you want to use by following:

     

    context.expand('${#TestCase#KEYNAME}')

     

     

  • nmrao's avatar
    nmrao
    Champion Level 3
    Does it change for test or is it one time that want to convert?
    • StooH's avatar
      StooH
      New Contributor

      So I've managed to create a groovy script which converts the contents of a txt file in to the base64 has that I need to create, however what I'm now stuggling to do is use the hashed output from the script within the SOAP request as it just keeps returning 

      • HimanshuTayal's avatar
        HimanshuTayal
        Community Hero

        Hi StooH :

         

        You can store the output in class level property by following:

         

        testRunner.testCase.setPropertyValue("KEYNAME", OUTPUT);

         

        and store where ever in Test Case you wanted to use if you want to use by following:

         

        context.expand('${#TestCase#KEYNAME}')