Wednesday, 19 December 2012

Inserting Existing Actions | QTP Tutorial PDF

Inserting Existing Actions

When you plan a suite of tests, you may realize that each test requires one or more identical activities, such as signing in. Once you have created the action and stored it with one test, you can insert either a call to a copy of the existing action, or a call to the existing action, into other tests.
When you insert a call to copy of an existing action, you can make changes to the copied action, and your changes will neither affect, nor be affected by, any other test. Calls to existing actions, however, are read-only in the calling test. They can be modified only in the test with which they were stored. Calls to existing actions enable you to call the same action from several tests and make it easy to maintain tests, because when your application changes you only have to update the existing action stored with the original test.
In the following exercises you will create a new test that is similar to the ActionA test, except that the Sign_in and ReturnHome actions are external actions (calls to existing actions stored with other tests) and the FlightOrder action is slightly modified.
➤ Inserting Calls to Actions
First, you will insert calls to the reusable Sign_in and ReturnHome actions from ActionA into ActionB.
1 Open a new test.
For more information, see step 1 of “Recording a Test,”.
2 Insert a call to the Sign_in action.
Choose Insert > Call to Existing Action. The Select Action dialog box opens.
Click the browse button next to the From test box. Select the ActionA test in the Open Test dialog box, and click Open. Note that only reusable actions from the ActionA test are displayed in the Select Action dialog box.
Select the Sign_in action. In the Location area, select At the end of the test.
Click OK. The call to Sign_in [ActionA] action is added to the end of the test as a call to an external action with the icon.
Note that you cannot expand the Sign_in action call in the test flow in the Keyword View. To view the steps in the Sign_in action, select it from the Action List. The action call you inserted is read-only. To modify the action, you must open the original (ActionA) test and modify the action there.
Select Test Flow in the Action List to return to the main flow of the test in the Keyword View.
3 Insert a call to the ReturnHome action.
Use the instructions in step 2 to insert a call to the ReturnHome action from ActionA. The ReturnHome action is added to the end of your test.
4 Save the test.
Select File > Save or click the Save button. Save the test as ActionB.
5 Modify the original ReturnHome action.
Choose File > Open. Browse to ActionA, and click Open.
Double-click the ReturnHome action icon to display its contents. (This is equivalent to selecting the ReturnHome action from the Action List.)
Make sure that the Comment column is displayed in the Keyword View. If it is not, right-click on the Keyword View column header and select Comment from the displayed list.
In the Keyword View, select the ReturnHome action icon and choose Insert > Step > Comment to add a comment about the purpose of the Home step. The Insert Comment dialog box opens.
In the edit box, enter: Return to page used in first step of the test. Click OK.
The comment step is added as the first step in the action, and you can see the comment text in the Comment column of that step. If the comment is too long to see, it is displayed in a tooltip when you move your cursor over the Comment column.
6 Save the test.
Select File > Save or click the Save button.
7 Confirm that the modification made in the original ReturnHome action is also included in the calling test.
Choose File > Open. Browse to ActionB and click Open.
Double-click the ReturnHome [ActionA] action icon to display it. Note that the comment you added to the original action (ActionA) also exists in the calling test (ActionB).
In the Action toolbar, select Test Flow from the Action List to return to the main flow of the test in the Keyword View.
➤ Inserting a Copy of an Action
Now, you will insert a copy of the FlightOrder action.
1 Open the ActionB test.
Choose File > Open. Browse to ActionB and click Open.
2 Insert a copy of the FlightOrder action.
Choose Insert > Call to Copy of Action. The Select Action dialog box opens.
Click the browse button next to the From test box. Select the ActionA test in the Open Test dialog box, and click Open. The actions from the ActionA test are displayed in the Action List. Note that the description of the highlighted action is displayed in the Action description box.
Select the FlightOrder action. In the Location area, select At the end of the test. Click OK. The Copy of FlightOrder action is added to the end of the test. Note that the call to the copy of the action you inserted is just like any other action call in your test. You can modify the steps in the call to the copied action just as you would those of any other action call.
3 Modify the Copy of FlightOrder action.
In the Keyword View, expand (+) Copy of FlightOrder > Welcome: Mercury Tours > Find a Flight: Mercury. Select fromPort and click the Value cell.
Change the value in the Value cell to London and click any other row in the Keyword View.
4 Call the Copy of FlightOrder action after the Sign_in action.
You want the Copy of FlightOrder action to be immediately after the Sign_in action. Since you cannot drag any action to be immediately after a reusable action (because it is read-only in the calling test), you must perform the following steps to change the order of the action calls.
Select the Copy of FlightOrder action and drag it immediately below the Action1 action in the Keyword View. Then, select the Sign_in action and drag it immediately below the Action1 action in the Keyword View. The Copy of FlightOrder action is now immediately after the Sign_in action.
5 Delete Action1 from the test.
Every new test contains a default Action1 action call. You can now delete the Action1 action call.
In the Keyword View, select Action1 and choose Edit > Delete or press the Delete key on your keyboard. A confirmation message opens. Click Yes to delete the action call.
6 Save the test.
Choose File > Save or click the Save button.
7 Confirm that the original FlightOrder action was not modified.
Choose File > Open. Browse to ActionA, and click Open.
Expand FlightOrder > Welcome: Mercury Tours > Find a Flight: Mercury.
Note that the change of departure city you made in the ActionB test did not affect the original action in ActionA (New York is still the departure city in
ActionA).

No comments: