-
Notifications
You must be signed in to change notification settings - Fork 3
Automated Testing
This page explains how to setup and run soapui automated test cases against a server running on your localhost. It will also explain how to create new soapui test cases and explain some of the trickier aspects of soapui.
Soapui can be downloaded and installed from the soapui website. For the purposes of our project we are using the free version. Also, make sure that when you are going through the installation process you select "loadui" otherwise you may have trouble running the test cases.
Once you have soapui installed, run the program and open up the test case project. The testcase project file for wifilocator is an xml file located in the repo folder "testing". Once the project has been opened you should see the tree view on the left side of the screen populated with the wifilocator project.
Before you run any test cases you should make sure the server url is configured properly. By default the tests are setup to run against "localhost:8081". This value is stored in a property attached to the project. To change this property click on the node in the project tree named "wifilocator", which should be just below the root node named "Projects". Once you have clicked on it you will see below the tree is a panel with two tabs. Click on the tab that says "Custom Properties". In the custom properties tab you will see a property called "ServiceEndpoint" with the value set to "localhost:8081". Changing the value of the ServiceEndpoint property will then apply to all of your testcases, as long as their endpoint starts with http://${#Project#ServiceEndpoint}/
Once you have configured the server path, you are ready to run the test cases. Testcases should appear in the tree view as children of the testsuite, and they should have green checkmark icons beside them. Double clicking on one of these testcases will open a window for controlling that test case. To run the test case click the green arrow at the top left of the test case window. This will run through all of the test steps sequentially. In the center of the window you will see a list of test steps. As the test runs the icon to the left of the test step name should change color, green if the test passed, and red if the test failed. If a test step fails the test case will stop. (Note: I have noticed that some times a testcase will fail to reach the server, for example when the server has just be restarted, so if a test case fails right away the first time you try to run it, wait a second and try again)
To add a new test case to a test suite, simply right click on the test suite in the tree view and click "New TestCase" in the context menu. This will create a new empty test case. The next thing you will want to do is add test steps. Right click on your new test case in the tree and in the context menu select "Add Step>HTTP Test Request". Give the test step a name and if any other dialog appears just continue through with default values. Once you have created a new test step, a window for that test step will appear. At the top of the window you can set the method and the url you want the test step to send the request to. Make sure that in the url field you always start your url with: http://${#Project#ServiceEndpoint}/ so that it will be updated when someone changes the Service Endpoint property attached to the project. Lastly, to add a body to your request, make sure you select the post method and then type the body into the text area on the left side below the drop box saying media type. (note: the only media types available are for xml, but since our server does not differentiate request types this field should not make a difference). Then to run the test step individually you can click the green arrow at the top left of the test step window.
What an Assert does is compare the server response to an expected response in order to say if the test passed or failed. Asserts in Soapui are a bit tricky, since they are not explained very well for the free version on the soapui website. To add an assert double click on a test step and at the bottom of the test step window click on the button labeled Assertions. This will popup a new panel, in this panel right click and select "Add Assertion". In the add assertion dialog we want to select "Property Content" on the left and then "XPath Match" on the right, and then hit the "add" button at the bottom. Then another dialog will appear that is split into a top and a bottom half. The top half is where you specify which part of the response you are verifying. The first thing we need to do in this part is click on the word declare to specify the namespace. Now, lets consider the response to the friendship request method, which returns a status code and a request id. On the line below the namespace declaration you could type either "//ns1:Response[1]" to match against the entire response or "//ns1:status" to match against just the status field. In the bottom half of the window is value that we want to assert. If you have run the test step once already you can just click "Select from Test" and the result of the previous test will be added to the field, or you can fill in the field yourself.
Property transfer is used for carrying properties between test steps. For example, many of our testcases require user_id as an input, but the user_id may not be known at the start of the test. Property Transfer allows us to send a request to get the id, then store that returned id in a value to be used in later test steps.