After unit tests have been created, they can be leveraged into scenario-based tests without any additional work. Scenario tests allow you to emulate business logic or transactions that may occur during normal usage of the web service. This also allows you to find bugs that may surface only after a certain sequence of events.
Parasoft SOAtest allows you to create multi-step scenarios, with each step exercising the same service or completely different application interfaces. This allows you to automate the modeling of business use-case scenarios (as described in End-to-End Business Process Testing). This also allows you to discover unexpected behaviors that may surface only after a certain sequence of events.
The scenario test example given in the test suite "Scenario Test - Search, Add to Cart, and Remove from Cart" represents a typical sequence of operations that a customer may invoke when using a bookstore web service. In this case, it represents a situation where a customer searches for a book, places an order for that book, then removes the previously placed order.
This scenario test introduces a tool called the XML Data Bank. This tool allows you to extract XML element values and store these values in memory so that they can be used in later tests. In this example, you will store the book ID returned by the service after searching for a book and, in the subsequent test, use that ID to purchase the book. You will also store the order number returned after placing an order for the book and, in the subsequent test, use that order number to remove the order from the system.
When you complete this section of the tutorial, your test suite should resemble the "Scenario Test - Search, Add to Cart, and Remove from Cart" test suite in the SOAtestTutorial.tst file.
Note that this lesson assumes that you have completed the previous lessons.
Creating a Scenario Test Suite
To create this scenario:
- Click the Test Suite: Functional Tests node from the previous exercise and click Add Test Suite on the tool bar.
- Choose Empty from the Add Test Suite wizard and click Finish.
- Double-click the new Test Suite: Test Suite node that was added to the test suite tree.
- In the test suite configuration panel, enter
Scenario Test - Search, Add to Cart, and Remove from Cart
into the Name field and click Save on the tool bar. - Copy the positive getItemByTitle, addItemToCart, and updateItemInCart SOAP Client test nodes from the CartServicePort test suite created previously and paste them into the Scenario Test - Search, Add to Cart, and Remove from Cart test suite. If needed, you can drag and drop to reorder them.
These three tests represent a typical business transaction a customer may invoke. This will be the basis for our scenario test.
Storing Results to Be Used in Subsequent Tests
You can store results by configuring an XML Data Bank as follows:
- Double-click the Test 1: getItemByTitle node in the Scenario: Scenario Test - Search, Add to Cart, and Remove from Cart test suite.
- In the test configuration panel, choose Books from the Data Source drop-down menu at the top right.
- Click the Request tab and enable titleKeyword, then choose Parameterized and Keywords from the element drop-down menus and click Save on the tool bar.
- Double-click the Test 2: addItemToCart node in the Scenario Test - Search, Add to Cart, and Remove from Cart test suite.
- For itemID, choose Parameterized and Use Data Source Wizard from the drop-down menus.
- Complete the Parameterize with Value From Existing Message dialog as follows so that when this test is run, the value stored from Test 1 will be automatically inserted as the value for the itemId element:
- Choose Test 1: getItemByTitle from the Existing message menu at the top of the dialog.
- Click the id element from the Expected Message tree and click Add. The id element appears in the Selected Element list with a Data Source Column Name corresponding to the selected test.
- Click OK.
Test 1:id[1] now appears in the right GUI panel as a parameterized value for itemId. You will also notice that a Response SOAP Envelope > XML Data Bank node now appears underneath the Test 1: getItemByTitle node in the Scenario Test - Search, Add to Cart, and Remove from Cart test suite.
- In the test configuration panel, enter a Fixed value of
3
for the quantity element, then click Save on the tool bar. - Double-click the Test 3: updateItemInCart node.
- For cartId, choose Parameterized and Use Data Source Wizard from the drop-down menus.
- Complete the Parameterize with Value From Existing Message dialog as follows so that when this test is run, the cartId element value stored from Test 2 will be automatically inserted as the value for the cartID element here:
- Choose Test 2: addItemtoCart from the Existing message menu at the top of the dialog.
- Click the cartId element from the Expected Message tree and click Add. The cartID element appears in the Selected Element list with a Data Source Column name corresponding to the selected test.
- Click OK.
Test 2:cartId[1] now appears in the test configuration panel as a parameterized value for cartId. You will also notice that a Response SOAP Envelope> XML Data Bank node now appears underneath the Test 2: addItemtoCart node in the Scenario Test - Search, Add to Cart, and Remove from Cart test suite.
- Configure itemId to use the ID from Test 1.
- Click Save on the tool bar.
- Click the Scenario: Scenario Test - Search, Add to Cart, and Remove from Cart node and click Run Tests on the tool bar. When this test is run, the id element value stored from Test 1 will be automatically inserted as the value for the itemID element in Test2 and Test3. Additionally, the cartId from Test2 will be used in Test3.
- Explore the traffic by expanding Scenario: Scenario Test - Search, Add to Cart, and Remove from Cart and double-clicking each test’s Traffic Object > Traffic Viewer nodes.
- Notice that the ID of the book returned from Test1 is used as the input for Test2. Also, the cartId of the order placed in Test2 is used as the input for Test3.
- Right-click the Scenario: Scenario Test - Search, Add to Cart, and Remove from Cart node and choose Create/Update Regression Controls.
- In the Response Validation Wizard, choose Create Regression Controls, click Next, choose Create Multiple Controls, then click Finish. The tests are run and a Regression Control is added to each SOAP Client test.
- Click the Scenario: Scenario Test - Search, Add to Cart, and Remove from Cart node and click Test on the tool bar. Notice the test failures reported.
- Examine the error messages that appear in the Quality Tasks view. These regression failures are due to dynamic content that appears within the response messages. In the following steps we will ignore elements with this type of dynamic data.
- In the Quality Tasks view, right-click the first error reported under each TestSuite node and choose IgnoreXPath. In the IgnoreXPathSettings dialog that opens, click OK. You should ignore two XPaths in this step.
- Click the Test Suite: Scenario Test - Search, Add to Cart, and Remove from Cart node and click Test on the tool bar. All the tests should now succeed.
You have now created a fully functional scenario test that tests one possible business transaction which may occur during normal usage of the bookstore service. For extra practice, you can try to create other scenarios that may possibly occur. Negative test cases could also be created for expanded test coverage.