A recent customer request was to have a decision tree in an automation test. This is a more advanced tutorial, showing using global variables and decision trees.
Some reasons for wanting a decision tree could be as simple as saying, if a test fails, automatically run an additional set of tests, or more complexed, like saying, if a test returns a value in a given field, run an additional test or different test.
Lets use iTunes JSON service for this tutorial. Here I want to get a list of albums for a artist using the search feature.
1. Start SOAPSonar and lets create a new project. File, New Test Group, then File, New, JSON Test Case. Create 3 JSON tests cases (you can clone them). Name them Search, Lookup A, Lookup B.
2. Lets enter the queries. What I am going to do is a search first, then use the artist ID to get a list of Albums for that artist
- Search A use http://itunes.apple.com/search?term=arctic+monkeys as the Query and GET as the method
- Lookup A use http://itunes.apple.com/lookup?id=62820413&entity=album and GET as the method
- Lookup B use http://itunes.apple.com/lookup?id=5893059&entity=album and GET as the method
3. We need to define a global variable. Policy Settings (in project Tree), Project Globals, Project Global Variables and enter artist=1 (some initial value). We just defined a global variable called artist.
4. Now in Search, we define a Runtime variable for artistId. Look in the Response section, Runtime Variables, and scroll down till you see the artistId value. It should be 62820413. Right-click on the value and add variable reference. Leave the name as artisIsd and accept.
5. Now we need to update our global variable with the runtime variable. Select the Tasks tab, then Actions, Update Global Variable.
6. Now lets select the variable. Edit the Task created in 5, select artist and then right click and [RV]Runtime Variable and find and select artistId.
7. Its time to define our test case in Run View. Drag Search under Default group. Right-click on Search test and select Add Conditional Test Group.
8. Now we define the condition. Select Conditional Tests folder, then drag Lookup A and Lookup B under it. Select Global Variable Match, enter artist (our global variable) and paste 62820413 for the value in Lookup A and 5893059 for the value in Look-up B. Commit and send.
9. You should see that 2 Test cases were run. When we look at the results in report view, they search and Lookup A.
10. Now lets change the search test from
Commit then switch to Run View and Run Suite. This time the second test was Look-up B.
Any questions or comments?