Forum Discussion

Andrew_H's avatar
Andrew_H
Occasional Contributor
14 years ago

Using Directory Data Source w/ XPath

I am building a load test. I have a directory of about 1000 XML files (these are from a produciton environment). These XML have a few strings, and 1 -2 base64 encoded blobs of data inside a <Doc> tag (one <Doc> tag per document). What I want to do is have a test case set up that will genrate my new XML. The strings will all come from a Excel data source, I have that covered. What I am not sure of is how I can use the 1,000 XMLs in my directory as the source for the base64 encoded documents.

My requirements would be:
- the test case randomly selects the XML that its going to get the base64 from. It could also be a step through.
- if in the selected XML, there is only 1 <Doc> tag, only put one in the new XML being generated, if theres 2, put 2 in

The main idea here is to use production documents that are value but scramble the rest of the attributes in the XML, and reuse the 1000 valid documents over and over randomly through out the load test.

I dont know how to make the random or step through of the directory documents, or use XPath to get the values from them. Maybe there is a better approach. The XML file I am trying to generate, and the XML files in the directory are the same structure, so maybe a data masking approach is more appropriate.

Thanks in advance for your help!

5 Replies

  • In the first paragraph, you state that there are only one <doc>-tag per document, but in the next paragraph you're saying that there can be one or two <doc>-tags.

    I'm sorry, but I find it's hard to follow your description of the problem.

    /Henrik
    www.eviware.com
  • Andrew_H's avatar
    Andrew_H
    Occasional Contributor
    What I mean is there are documents in the XML, and its one document per <Doc> tag in the XML. Here is an example:

    <RetrieveApplicationsResponse>
    <Applicant>
    <Name></Name>
    <Email></Email>
    <ApplicationTime></ApplicationTime>
    <ChannelId></ChannelId>
    <Rank></Rank>
    <Doc DocumentType="Body" EncodingType="Base64"></Doc>
    <Doc DocumentType="Attachment" FileName="Document2.doc" EncodingType="Base64"></Doc>
    </Applicant>
    </RetrieveApplicationsResponse>

    Each <Doc> tag has a attribute DocumentType. Typically it will be 1 Body and 1 Attachment, though the XML message might have one, the other, or both, but never neither.
  • Thanks for clarifying. Using the code below as a Groovy datasource (remember to add the property "XMLfileContent" to it) should essentially be the same as a randomized Directory Datasource.
    import java.util.Random

    def dirName = "C:/xmlFolder"

    def allXMLFiles = []
    new File(dirName).eachFile() { file ->
    if( file.name =~ /.xml/)
    {
    allXMLFiles.add( file.name )
    }
    }

    def rand = new Random()
    def randomFileName = allXMLFiles[ rand.nextInt(allXMLFiles.size) ]

    result["XMLfileContent"] = new File(dirName + "/" + randomFileName).text

    Hope it helps!

    /Henrik
    http://www.eviware.com
  • Andrew_H's avatar
    Andrew_H
    Occasional Contributor
    Thanks Henrik!

    That helps. Which now brings me to a new issue. So far then I have the groovy data source described above to randomly select a XML file from a directory. Then I have the XML data source which defines the XPath of the value that I want to get from the XML file. What I want to do is get the entire <Applicant> section, tags and all, so my XPath would be MyMessage/Applicant/* , however this doesnt work, and nothing is returned when I run this. The only thing that works is if I use a XPath value that points to a single value. How do I transfer the entire <Applicant> section, tags at all into the property where I could insert that block of XML into a new test request?

    My XML looks like this:

    <MyMessage>
    <Advert>
    .
    .
    .
    .
    </Advert>
    <Applicant>
    <Name>${DataGen#FName} ${DataGen#LName}</Name>
    <Email>${DataGen#FName}.${DataGen#LName}@test.com</Email>
    <ApplicationTime>2011-02-16T20:49:39Z</ApplicationTime>
    <ChannelId>careerbuilder</ChannelId>
    <Rank>Unranked</Rank>
    <Doc DocumentType="Body" EncodingType="Base64">${ApplicantData#Applicant}</Doc>
    </Applicant>
    </MyMessage>
  • Hi!

    hmm... can you show the exact setup you have here? Maybe share the XPath statement also? Or maybe the entire project file?

    regards,

    /Ole
    eviware.com