IBM® Rational® Test Workbench provides comprehensive automation solution for Mobile and Web Applications. User can create different mobile & web ui tests as per their requirements. To automate some automation scenarios, user might need to pass parameter from one test to another test. In this blog, we would learn how parameter passing works between RTW (Rational Test Workbench) tests.
There may be various scenarios which can be achieved by this approach, e.g. User gets some confirmation id in one test and same confirmation id is received to his mail box. To cross check the same, user can create one test for the flow where it generates the confirmation id and pass this confirmation id to another test where user compares the same with the confirmation id received in the mail. In other flow, user may get some order id while purchasing a product from some e-commerce website and later in another test user can check it’s order status by passing the order id from first test. Similarly there can be a number of scenarios where parameter passing is required.
In the example in this blog, we will use couple of basic android applications where we will achieve following scenario –
1) In Test 1, User will click on a button which display today’s temperature.
2) In Test 2, based on the temperature, user will select a beach to visit. If temperature is less than 30, user will visit Marina beach else user will select Paradise beach.
Here value of temperature will be passed as a parameter from test 1 to test 2.
To achieve this flow, we will follow below steps in Rational Test Workbench –
1) Create a Mobile Test to get the temperature and store the temperature value in a variable. Below figure shows how to do this.
Figure 1. Setting up Temperature variable in test 1 from text property of the Text View which shows temperature
Below are the detailed steps to achieve this -
1.1) Record a mobile test on Today's Temperature Mobile App. Here we have just clicked on button "Check Today's Temperature". Once user clicks on the button, the textview which displays 0 as a temperature, will display the new temperature as a integer number. We have just recorded a single step and saved the test with name getTemperature.
1.2) Now create a test variable, as we have created here named "Temperature" and do not assign any value to this variable. Change the Visible In property of the variable to "All tests for this user", so that the variable can be visible to other tests too.
1.3) From Mobile and Web UI Data view, select the text view containing whose Text is 0, Right Click on it and select "Create Variable Assignment from Text", this will allow user to assign the text property of the Text View to the "Temperature" variable and a statement will be added in in the test for this action.
2) Create another Mobile Test and use the previous variable in this test to decide on which button to click to select the beach. Below snapshot shows how this flow can be achieved -
Figure 2. Using the Temperature Variable in Test 2 and Creating conditions based on the variable value
Below are the detailed steps to achieve this -
2.1) Create another mobile test on SelectBeachToVisit Mobile Application, Click on Marina Beach Button and Paradise Beach button and exit the test. Here we saved the test with name selectBeachToVisit.
2.2) Create a variable called "Temperature" with no value assigned to it. Make sure that variable name should be same what we have created in Test 1 (named getTemperature).
2.3) Create If conditions, The if conditions says, if Temperature value is less than or equal to 30, then select Marina beach and if Temperature value is greater than 30, then select Paradise beach.
3) Passing the Temperature Variable from Test 1 (getTemperature) to Test 2 (selectBeachToVisit)
Now we have Test 1 (getTemperature) which assigns value to Temperature Variable and we have Test 2 (selectBeachToVisit), which decides what beach to select based on the Temperature Variable's value. The question here is, now how to pass this Temperature Variable from Test 1 to Test 2 and complete the flow ?
To achieve this, We will use a functionality called Compound Tests provided by Rational Test Workbench. As the name says, Compound Test is a container for various RTW Tests (Mobile Tests, Web UI Tests, Selenium Junit & Java eclipse based Tests, Performance Tests etc.) and executing the compound test will execute the tests added to it, in sequence. Using the compound tests, parameter passing between different RTW tests can be achieved as well as user can modularize his tests and achieve the complete flow by using the compound test.
To achieve the flow discussed in the blog, we will add Test 1 and Test 2 to the compound Test and execute this compound Test. Compound Test will automatically take care of passing the "Temperature" variable's value which is assigned in Test 1, to Test 2 and by this way, Test 2 can execute it's conditions. Below snapshot shows how how we have added Test 1 & Test 2 to a compound test named TempVsBeach.
Figure 3. Added Test 1 and Test 2 in compound Test.
Once user executes the compound Test, it will first execute the Test 1 (getTemperature) and set value in Temperature variable, This variable a passed to Test 2 (selectBeachToVisit) and Test 2 will be executed. Below snapshot shows the playback report for the execution of the compound Test -
Figure 4. Mobile & Web UI report snapshot for Compound Test Execution
From this snapshot we can see that, Test 1 has generated temperature value as 24 and which is assigned to "Temperature" variable and as temperature value was less than 30, hence in Test 2, Click on Marina beach button happened. The test project for this example is attached at following location - TempVsBeachSelectionRTWProject and it can be imported to Rational Test Workbench by following import option - "File > Import > Test > Test Assets with Dependencies" .
In similar way, user can achieve different flows by parameter passing between RTW tests. Here we have taken example of simple Android Apps, but same can be achieved for other RTW Tests (e.g. Web UI Tests, http tests etc.) too.