Forum Discussion

VerticalEvent's avatar
13 years ago

Functional Testing with SoapUI with Multi-Variable Data

I want to do some testing and want to know if SoapUI can handle generating requests where elements can have more than set of values. For example, if I wanted to send an XML about a list of books (where the number of books can vary), the body might look like:

<bookList>
<book>
<title>Little Red Riding Hood</title>
<author>B. B. Wolf</author>
</book>
<book>
<title>Humpty Dumpty</title>
<author>M. Goose</author>
</book>
<book>
<title> Cinderella </title>
<author>F. G. Mother</author>
</book>
</bookList>


Sometimes I will want two books, others three, sometimes even none - I just want one template that can cover any number of elements in this list. Is there a way to generate functional testing using Excel or CSV (or, another data format) for situations where there element lists (that can vary in total number of elements)? Either through Groovy or SoapUI pro? I can't seem to find anything on SoapUI's site about this type of situation, although it seems like it would be a common one.

1 Reply

  • Well this code is messy, but it does the job



    import java.io.File;
    import static groovy.io.FileType.*;


    def sortByTypeThenNameFile = {a, b -> a.isFile() != b.isFile() ? a.isFile() <=> b.isFile() : b.name.toLowerCase() <=> a.name.toLowerCase()};

    new File('D:/books/').traverse(
    type : FILES,
    sort : sortByTypeThenNameFile) {
    file ->

    log.info 'reading file ' + file

    log.info createXML(file)
    }

    def createXML(file) {
    //create root xml
    def xml = new XmlParser().parseText('<root/>')

    file.eachLine {
    line ->

    //add "book" node
    xml.appendNode('book')

    if(line.split(';').size() > 1) {
    //[xml.book.size() -1] is for the newest node
    xml.book[xml.book.size() -1].appendNode('author', line.split(';')[0])
    xml.book[xml.book.size() -1].appendNode('title', line.split(';')[1])
    }
    }

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

    return w.toString();
    }


    This will read in files from D:\books, in my case fantasy.txt and science.fiction.txt
    fantasy.txt contains this lines

    Piers Anthony;A Spell for Chameleon
    Piers Anthony;The Source of Magic
    Piers Anthony;Castle Roogna


    science.fiction.txt contains this lines

    Douglas Noel Adams;The Hitchhiker’s Guide to the Galaxy
    Peter Ackroyd;Milton in America
    Peter Ackroyd;The Clerkenwell Tales
    Isaac Asimov;The Caves of Steel
    Isaac Asimov;Foundation


    and will output
    for fantasy.txt

    <root>
    <book>
    <author>Piers Anthony</author>
    <title>A Spell for Chameleon</title>
    </book>
    <book>
    <author>Piers Anthony</author>
    <title>The Source of Magic</title>
    </book>
    <book>
    <author>Piers Anthony</author>
    <title>Castle Roogna</title>
    </book>
    </root>


    for science.fiction.txt

    <root>
    <book>
    <author>Douglas Noel Adams</author>
    <title>The Hitchhiker’s Guide to the Galaxy</title>
    </book>
    <book>
    <author>Peter Ackroyd</author>
    <title>Milton in America</title>
    </book>
    <book>
    <author>Peter Ackroyd</author>
    <title>The Clerkenwell Tales</title>
    </book>
    <book>
    <author>Isaac Asimov</author>
    <title>The Caves of Steel</title>
    </book>
    <book>
    <author>Isaac Asimov</author>
    <title>Foundation</title>
    </book>
    </root>