Writing to files from soapUI
In this post I aim to show you how to write to files from a soapUI test case. This is really interesting when you have to change properties so that you can automate your tests and get free from manual file changes.
This was made easy by the possibility of running Groovy scripts as a test step and can help you to configure a parameter file or a properties file before running some piece of test.
So, to see this in practice, create a new soapUI Workspace and a new empty Project inside it. Add a new Test Suite to the project:
And add a new Test Case to the Test Suite:
Add a new Groovy Script step to the test case:
Inside the Groovy Script Test Step, enter the following source code:
File file = new File("/tmp/myConfig.properties")
file.delete()
file << ("PROPERTY1=123")
file << ("\r\n")
file << ("PROPERTY2=456")
This piece of code will:
- First open file at “/tmp” called myConfig.properties
- Delete it (if it exists)
- Then we write 2 key/value properties to the file, breaking the line between both of them.
The source code should look like the following image:
Now, run the script and you should see an information alert showing it was successful. Go to the file system and open the /tmp/myConfig.properties file. You should see it was generated as expected like shown in the image bellow:
As you may have noticed, this was pretty easy and this possibility enables you to change properties so that your tests can avoid human intervention to change property and other kinds of files.





Trackback address for this post
Trackback URL (right click and copy shortcut/link location)
No feedback yet
Leave a comment