Forum Discussion

vkvijayakumar's avatar
vkvijayakumar
Occasional Contributor
13 years ago

Need to Post 500 XML's continously - Help Needed

Hi Smartbear Support,

I want to post a set of 500 XML's one after another. I would like to create 5 XML's which should run for 100 times. Each time, an unique RFC ID in XML should get changed ( ex: xyz, xyz+1,xyz+2 etc.)
Let me know how to make this possible ?

Thanks in advance..
Vijaykumar VK
  • I am assuming you want to read in the xml files.


    import java.io.File;

    new File('d:/test/').traverse {
    file ->
    log.info 'Reading file ' + file
    setRequest(file.getText())
    }

    def setRequest(filecontent) {
    (1 .. 100).each {
    num ->
    xml = new XmlParser().parseText(filecontent);
    xml.RFC_ID[0].value = xml.RFC_ID[0].text().toInteger() + num

    def w = new StringWriter()
    def p = new XmlNodePrinter(new PrintWriter(w))
    p.preserveWhitespace = true;
    p.print(xml)

    log.info w.toString()
    //testRunner.testCase.testSuite.project.testSuites['testsuite'].testCases['testcase'].testSteps['request_2'].getProperty('Request').setValue(w.toString());
    }
    }


    My example uses files like this

    <root>
    <RFC_ID>6000000</RFC_ID>
    <value>A1106F</value>
    </root>


    Change

    xml.RFC_ID[0].value = xml.RFC_ID[0].text().toInteger() + num

    to something appropriate to your files.

    Example, if your file looks like this

    <root>
    <something>
    <RFC_ID>6000000</RFC_ID>
    </something>
    <value>A1106F</value>
    </root>


    you have to change

    xml.RFC_ID[0].value = xml.RFC_ID[0].text().toInteger() + num

    to

    xml.something.RFC_ID[0].value = xml.something.RFC_ID[0].text().toInteger() + num
  • Ashik's avatar
    Ashik
    Occasional Contributor
    Hi,
    Am getting an null pointer exception(cannot invoke method text() on null object).Error in the line
    --new File('D:/Concession/').traverse
    let me make it clear.I have got an xml file named concession.xml.I need this xml to be copied or fetched and set as my request which is will be one among the teststep or as an response xml which i can use for mocking the response.please let me know if any queries.

    Regards,
    Ashik