Essentials of IBM® Rational® Functional Tester Essentials of IBM® Rational® Functional Tester Module 2: Creating data-driven tests This presentation will provide an overview of scripting with Rational Functional Tester version 6.1 and describe the steps necessary to work with data-driven tests. Module 2 Module 2 Objectives: Creating Data-Driven Tests. The following topics are covered in this module: Data-driven testing Creating data-driven test scripts Creating and editing datapools Running a data-driven test Exporting and importing datapools Upon completion of this module, you will be able to: Define data-driven testing and explain why you would use it. Create a data-driven test Create and edit a datapool Run a data-driven test Export and import datapools The objective of this module is to introduce data-driven tests. Topics covered include data-driven testing, creating, editing, running, exporting, and importing datapools and data-driven test scripts. Limitations of hard-coded scripts Limitations of hard-coded scripts When you record a test script using literal values, that data is hard-coded into the script. A script with hard-coded data: Runs only one test case, or one set of valid test inputs Is difficult to maintain and reuse There are limitations to testing when using hard-coded scripts. This module will explore the benefits of data driven tests. When recording a test script using literal values, that data is hard-coded into the script. A script with hard-coded data runs only one test case, or one set of valid test inputs, and is difficult to maintain and reuse. Data-driven tests use variable data Data-driven tests use variable data In data-driven testing, you separate the data from the test script. Instead of hard-coding data into the script, the script is coded to accept variable data from an external source. Because data is separated from the test script, you can: Modify test data without affecting the test script Add new test cases by modifying the data, not the test script When hard-coding data into the script, the script is coded to accept variable data from an external source. Because data is separated from the test script, you can modify test data without affecting the test script, and add new test cases by modifying the data, not the test script. Datapools Datapools A datapool is a collection of related data records supplies data values to the variables in a test script uses a different set of test data each time you play back a test Functional Tester allows you to create datapools while recording a script import existing datapools Edit datapools you create within Functional Tester Export and edit datapools you create Share a datapool with multiple test scripts A datapool is a collection of related data records. A datapool supplies data values to the variables in a test script during script playback. Datapools automatically pump a different set of test data to a test script each time you play back a test. Rational Functional Tester makes it easy for you to create datapools while you are recording a script. Alternatively, you can import existing datapools. Rational Functional Tester also allows you to edit datapools you create within Functional Tester, export and edit datapools you create, and share a datapool with multiple test scripts. Functional tester data-driven testing scenarios Functional tester data-driven testing scenarios Different scenarios for implementing data-driven testing in Functional Tester: Create a datapool when recording a data-driven script within Functional Tester. Modify the datapool within Functional Tester. Import an externally created datapool into Functional Tester and associate it with a a data-driven test script. Create a datapool when recording a data-driven script within Functional Tester. Export the datapool and edit it externally. Import the edited datapool to drive a test script. There are different scenarios for implementing data-driven testing in Functional Tester, including: Creating a datapool when recording a data-driven script within Functional Tester. Modifying the datapool within Functional Tester Importing an externally created datapool into Functional Tester and associating it with a data-driven test script Creating a datapool when recording a data-driven script within Functional Tester. Exporting the datapool and editing it externally And, Importing the edited datapool to drive a test script. Scenario 1: creating a data-driven test script and datapool Scenario 1: creating a data-driven test script and datapool Functional Test allows you to create a datapool while you are recording a data-driven test script. You can then edit and add records to the datapool within Functional Tester. Scenario 1: Creating a data-driven test script and datapool. This scenario takes you through the process of creating a datapool while you are recording a test script. You can then edit and add records to the datapool within Rational Functional Tester. Recording a data-driven test script Recording a data-driven test script Begin recording a test script by clicking the Record Test Script button on the Functional Test toolbar. To begin recording a test script, click the Record Test Script button on the Functional Test toolbar. Recording a data-driven test script (cont.) Recording a data-driven test script (cont.) A Private Test Datapool is associated with only one script. A Shared Test Datapool may be shared by many scripts. When Sequential is selected, the script pulls records from the datapool in order. When random is selected, the script randomly accesses every record in the datapool once. A Private Test Datapool is associated with only one script, while a Shared Test Datapool may be shared by many scripts. When the Sequential Order option is selected, the script pulls records from the datapool in order, whereas when the Random Order option is selected, the script randomly accesses every record in the datapool once. Make sure you choose the correct datapool you want to use in the Test Datapool field and the correct datapool selection order. Recording a data-driven test script (cont.) Recording a data-driven test script (cont.) Once you have selected an application to record the script against, the Recording toolbar appears. Stop Recording Pause/Resume Recording Start Application Insert Verification Point or Action Command Insert Data Driven Commands Insert Script Support Commands Display Help Display Toolbar Only Copy Selected Text Clear All Monitor Text Save Monitor Text As Monitor Message Preferences 1 2 3 4 5 6 7 8 9 10 11 12 Once you have selected an application to record the script against, the Recording toolbar appears. You can perform a number of functions as indicated in the toolbar above such as starting and stopping, and inserting verification points. Inserting data-driven commands Inserting data-driven commands When you are ready to data-drive your script, click the Insert Data Driven Commands button on the Recording toolbar. Recording pauses, and the Insert Data Driven Action dialog box appears. Use the Object Finder to select objects in the application that you want to test or use the selection wizard to select particular test objects. When you are ready to data-drive your script, click the Insert Data Driven Commands button on the Recording toolbar (shown on the right). Inserting data-driven commands (cont.) Inserting data-driven commands (cont.) An object selected by the Object selector, is outlined in red. When you have selected the objects, release the mouse. The Insert Driven Actions dialog box appears with data collected about the objects you selected. An object selected by the Object selector, is outlined in red. When you have selected the objects, release the mouse. The Insert Driven Actions dialog box appears with data collected about the objects you selected. Editing data-driven commands Editing data-driven commands You can add descriptive headings to the data in the datapool. Meaningful headings make it easier to later add data to the datapool. Once you create the command, you can add descriptive headings to the data in the datapool. Meaningful headings make it easier to later add data to the datapool. Inserting a verification point that references the datapool Inserting a verification point that references the datapool When you insert a verification point in a data-driven script, you can create a datapool reference instead of a literal value. Click the Convert Value to Datapool Reference button. Type a name for the variable. Check the Add value to new record in datapool checkbox to add the variable to your datapool. When you insert a verification point in a data-driven script, you can create a datapool reference instead of a literal value. Remember, verification points are the components that can be used to check the differences in the actual values against expected values. Datapool display Datapool display When you stop recording, the script and datapool information display. Datapool displayed Datapool references in script When you stop recording, the script and datapool information is shown here. Editing a datapool Editing a datapool Once you have created a datapool you can edit the data you input or add additional data. Double-click the datapool title bar to begin editing the datapool. From the shortcut menu you can: Edit, add, and remove records Edit, add, and remove variables Cut, copy, and paste data To add a new data record to the datapool you must first click Add Record. Then, you can copy and paste data from other records into the new record row. Once you have created a datapool you can edit the data you input or add additional data. Remember, to add a new data record, you must first click Add Record. You will then be able to copy and paste data from other records into the new record row. Data-driving a test script Data-driving a test script When you play back the script, you set the datapool iteration count. Each time the script runs, it pulls a different record from the datapool. Or, you can add a parameter to CallScript to iterate through the entire datapool: CallScript ("myScript", DEFAULT_ARGS, DP_ALL) You can add a parameter to CallScript to iterate through a datapool. When you play back the script, you set the datapool iteration count. Each time the script runs, it pulls a different record from the datapool. Scenario 2: Importing an external datapool Scenario 2: Importing an external datapool Functional Test allows you to import data from: An external spreadsheet (.csv file) Another Functional Test datapool An existing IBM Rational TestManager datapool However, keep in mind the following: The data must be imported into the same Functional Test project as the scripts that will access it. Spreadsheet data must be saved as a .csv file before you import it. To import data from a TestManager datapool, you must first associate the Functional Test project with the Rational project that contains the datastore Scenario 2: Importing an external datapool Functional Test allows you to import data from: An external spreadsheet (.csv file) Another Functional Test datapool or An existing IBM Rational TestManager datapool However, keep in mind that: The data must be imported into the same Functional Test project as the scripts that will access it. Spreadsheet data must be saved as a .csv file before you import it. To import data from a TestManager datapool, you must first associate the Functional Test project with the Rational project that contains the datastore. Importing an external datapool Importing an external datapool First, import the datapool into a Functional Tester project. On the main menu click File > New > Add Test Datapool In this scenario, you import an external datapool (.csv file) into a Functional Test project and then associate it with a test script. Importing a datapool (cont.) Importing a datapool (cont.) Type a Name for the datapool and select a target location inside the Functional Test project. Browse to select the datapool file. This window shows how to import from the UI. Follow the directions above to import a datapool. Importing a datapool (cont.) Importing a datapool (cont.) Verify the Import From location. Confirm the Field Separator value. Check the box if the first record of your datapool contains variable information. Verify the Import From location and other information on this window. Checking the datapool and editing the variable row Checking the datapool and editing the variable row Once the datapool is imported, it shows up under the project in the Solution Explorer and opens in the datapool window. Verify the data. Edit the Variable row to include meaningful variable names. Right-click > Edit Variable. Once the datapool is imported, it shows up under the project in the Solution Explorer and opens in the datapool window. Verify the data shown. You can also edit the variable row to include meaningful variable names. Associating the Datapool with a Test Script Associating the Datapool with a Test Script Once you have recorded a test script, associate the datapool with the test script. In the Solution Explorer, right-click the datapool and click Associate With Script on context menu. Select the test script that you want to associate with the datapool. Once you have recorded a test script, associate the datapool with the test script. In the Solution Explorer, right-click the datapool and click Associate With Script on context menu. Changing the verification point reference to the datapool Changing the verification point reference to the datapool OrderTotal Open a verification point. Click the Convert Value to Datapool Reference button. From the Datapool Variable drop down list, select the variable that you want to replace the literal value. You can also change the Verification Point Reference to the Datapool here. Replacing literals in the test script with variables Replacing literals in the test script with variables Click the Find Literals and Replace with Datapool Reference button to replace literal values in the script with variables. In the Datapool Literal Substitution box, click Find Next to move to the next literal. To replace a literal, select a variable to from the Datapool Variable drop down list. You can replace literals in the Replacing Literals in the Test Script with Variables. This feature allows you to check verification points dynamically. Playing back the test script to test the datapool Playing back the test script to test the datapool Click verification point to navigate the test log. Click to view verification point results in the comparator. After you playback the script, the log will be displayed, showing the results in the comparator. Scenario 3: Exporting, editing, and importing a datapool Scenario 3: Exporting, editing, and importing a datapool Functional Test also allows you to export a public or a private datapool from a Functional Test project. The datapool is exported to a .csv file. Exporting a datapool allows you to: Add data to the datapool using a spreadsheet application Use the datapool in a different Functional Test project Scenario 3: Exporting, editing, and importing a datapool Functional Test also allows you to export a public or a private datapool from a Functional Test project. The datapool is exported to a .csv file. Exporting a datapool allows you to: Add data to the datapool using a spreadsheet application Use the datapool in a different Functional Test project Exporting a datapool Exporting a datapool To export a private datapool, open the script the datapool is associated with. Right-click the datapool in the Script Explorer, and then click Export on the shortcut menu. Choose a name and location, and select a field separator for the .csv file. This window explains how to export the datapool. Follow the steps above to complete the export. For more information on exporting, editing, and importing a datapool, review the tutorials from the dynamic help menu. Trademarks