Forum Discussion

JimL's avatar
JimL
Contributor
13 years ago

Automatically populate element value?

Hi,

I had posted earlier in a thread:

viewtopic.php?f=5&t=7917

where I was trying to automate population of an attribute (IssueInstant) in an outgoing SOAP request.

Per that thread, I got that working, thanks to this forum, but I'm still trying to "find my way" around with using SOAPUI and automating stuff.

Now, I want to be able to populate an element value in outgoing SOAP requests, and, in particular, would like to be able to populate that value from, for example, a list of values in a text file.

For example, if I have a text file with:

cn=foo1,dc=whatever,dc=com
cn=foo2,dc=whatever,dc=com
.
.
etc.

I'd like to be able to run a load test using a testcase, and have the load test send out the same SOAP message, but each time, both populate the IssueInstant with the current date/timestamp (got that working) and an element value (e.g., <Subject>) populated from that text file.

Can this also be done in a startup script, maybe in the load test configuration, rather than in the testcase setup?

In other words, have the startup script in the test case continue to populate the IssueInstant, but have a startup script in the load test populate the <Subject> element value from the next line in the text file?

If so, can anyone tell me what the startup script would look like (not that familiar with Groovy) and also what the property reference in the SOAP message template would look like?

Thanks,
Jim

9 Replies

  • JimL's avatar
    JimL
    Contributor
    Hi,

    I've been continuing trying to figure out how to go about doing what I described in the earlier post above, but am really stuck on the following:

    I think that I should be able to follow the pattern that I eventually used in the earlier thread that I linked in the 1st post, but include Groovy code in the startup to read lines from the file with the different usernames, and then use the info from a line from the file to populate a property.

    The problem that I'm having is trying to understand how the code in the startup script is suppose to do that for all/each of the text lines in the file?

    Does the Groovy script have to somehow, on its own, keep track of which line in the file is the "next" line, and then read all the lines up to the "next" line, and then populate the property? Also, if that's the case, how can it keep track of the "next" line, i.e., does it have to write (for example) a line number to some temporary file that can then get picked up the next time the startup script is invoked?

    Sorry if I seem confused (because I am ). Maybe I'm "missing" something conceptually?

    Thanks,
    Jimj
  • JimL's avatar
    JimL
    Contributor
    Hi,

    I'm trying to implement what I described in the posts above.

    What I've done so far is add a Groovy Script test step to a test case, so now, in the testcase I have:

    - Groovy script test step
    - A request

    In the Groovy script test step, I've added the following code:

    props = new java.util.Properties ()
    file = new File("E:/SOAPUI-PROPS/testprops.txt")
    if(!file.exists()) {
    log.info "No file found at E:/SOAPUI-PROPS/testprops.txt"
    }
    else {
    log.info "Found E:/SOAPUI-PROPS/testprops.txt"
    fis = new FileInputStream (file)
    props.load (fis)
    requestid = props.getProperty ( "requestid" )
    log.info "requestid = [" + requestid + "]"
    dnstring = props.getProperty ( "dnstring" )
    log.info "dnstring= [" + dnstring + "]"
    testRunner.testCase.setPropertyValue("requestid", requestid);
    log.info "Finished setting 'requestid' property"
    testRunner.testCase.setPropertyValue("dnstring", dnstring);
    log.info "Finished setting 'dnstring' property"
    }


    In the request, I have:

    <saml:Subject xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"><saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName">${#TestCase#dnstring}</saml:NameID>
    </saml:Subject>


    When I run the test case, I can see the new properties (dnstring and requestid) being populated form the text file, but it looks like that ${#Testcase#dnstring) property is not being populated.

    Can anyone tell what I'm doing wrong?

    Thanks,
    Jim
  • Finan's avatar
    Finan
    Frequent Contributor
    Can you show the raw request? From what I can see, it should work....
  • JimL's avatar
    JimL
    Contributor
    Finan,

    That was something that I've noticed with my SOAPUI... When I try to view the RAW request (by clicking the RAW tab), SOAPUI is only showing the HTTP headers, and not the POST data (i.e., not the SOAP request). Is there something in SOAPUI that I have to configure to have it show the RAW data?

    So, what I've been doing is looking at the SOAP request when it arrives at the server, for now.

    Thanks,
    Jim
  • JimL's avatar
    JimL
    Contributor
    Hi,

    BTW, in my test case, I have the steps as shown in the earlier post, i.e.:

    1st test step: Groovy script (as shown above)
    2nd test step: Request with ${#TestCase#dnstring}

    Is that the correct order? It almost seems like the Groovy step might be setting the property after the request is going out. Then again, even re-running the test case isn't showing that property expansion filled in, so I just am puzzled at this point.

    Jim
  • JimL's avatar
    JimL
    Contributor
    Hi,

    Also BTW, those are the only two test steps in my test case. Do I need another step, maybe a property transfer? If so, what order do I put them in in the test case?

    Jim
  • JimL's avatar
    JimL
    Contributor
    Finan wrote:
    Can you show the raw request? From what I can see, it should work....



    Hi,

    I figured out how to get SOAPUI to display the RAW (Had to go into preferences==>UI, and check the "wrap" option), and in the process of doing that, I was able to figure out how to get at least part of what I'm trying to do working.

    So, here's the XML (non-RAW) again:

    <saml:Subject xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"><saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName">${#TestCase#dnstring}</saml:NameID>
    </saml:Subject>


    and, here's the RAW:

    <saml:Subject xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"><saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName">cn=test1,dc=whatever,dc=com</saml:NameID>
    </saml:Subject>


    The text file has:


    requestid =id-1234567
    dnstring =cn=test1,cn=users,dc=whatever,dc=com


    Now, I need to figure out how to do what I *really* want to do (have the test case run with a bunch of different set of requestid/dnstring values.

    I originally was thinking to put all of the sets of requestid/dnstring values in a single big text file, but now I'm thinking that I should have one text file for each "request", i.e.:

    testprop1.txt
    testprop2.txt
    testprop3.txt
    .
    .
    etc.

    where each testpropX.txt file has a different set of values for requestid and dnstring, and then be able to run the test case under a load test, and have SOAPUI send in the requests, rotating through the different testpropX.txt files?

    So, can anyone tell me what I need to do to what I have thus far to do that?

    Thanks,
    Jim
  • JimL's avatar
    JimL
    Contributor
    Hi,

    I think that I'm getting close to getting this working, but I'm running into problems with the way that Groovy treats variables, numbers and strings, I think.

    Here is my current test code, in a Groovy test step:

    def cur_request_number = testRunner.testCase.getPropertyValue("cur_request_number");
    def max_request_number = testRunner.testCase.getPropertyValue("max_request_number");
    log.info "INITIAL cur_request_number=[" + cur_request_number + "]"
    log.info "INITIAL max_request_number=[" + max_request_number + "]"

    cur_request_number++;

    log.info "BUMPED cur_request_number=[" + cur_request_number + "]"

    if (cur_request_number == max_request_number) {
    log.info "In the IF about to reset cur_request_number to 1";
    cur_request_number = "1";
    }

    // set the cur_request_number property (either the incremented one, or "1")
    testRunner.testCase.setPropertyValue("cur_request_number", cur_request_number);

    cur_request_filename = "E:/SOAPUI-PROPS/testprops" + cur_request_number.toString() +".txt";
    log.info "READING FROM Request file [" + cur_request_filename + "]"

    props = new java.util.Properties ()
    file = new File("E:/SOAPUI-PROPS/testprops.txt")
    if(!file.exists()) {
    log.info "No file found at E:/SOAPUI-PROPS/testprops.txt"
    }
    else {
    log.info "max_request_number=[" + max_request_number + "]"

    log.info "In the ELSE, cur_request_number=[" + cur_request_number + "]"
    //testRunner.testCase.setPropertyValue("cur_request_number", cur_request_number);
    log.info "Found E:/SOAPUI-PROPS/testprops.txt"
    fis = new FileInputStream (file)
    props.load (fis)
    requestid = props.getProperty ( "requestid" )
    log.info "requestid = [" + requestid + "]"
    dnstring = props.getProperty ( "dnstring" )
    log.info "dnstring= [" + dnstring + "]"
    testRunner.testCase.setPropertyValue("requestid", requestid);
    context.requestid = requestid;
    log.info "Finished setting 'requestid' property"
    testRunner.testCase.setPropertyValue("dnstring", dnstring);
    context.dnstring = dnstring;
    log.info "Finished setting 'dnstring' property"
    }


    That works fine if I set max_request_number to something less than 10, i.e., 9 works.

    But, if I set cur_request_number to 0 and max_request_number to, say, 11, it blows up after the 9th run, because it looks like the "cur_request_number++" line is incrementing cur_request_number to a semi-colon (":")!!

    I hope that someone who's familiar with Groovy can take a look at the above, and tell me what's wrong??

    Thanks,
    Jim
  • JimL's avatar
    JimL
    Contributor
    Hi,

    I think that I got this working. The key was to judiciously convert variables to integer or string, depending what was needed. Seems to be working ok now.

    Jim