【正文】
After pleting this chapter, you will be able to: ? Build scripts that access data from external sources. ? Import data from an Excel spreadsheet. ? Use the connection and RecordSet objects to query a database. ? Read and output information to text files. External Data Sources Your pany may have an external data source that contains the required test data for its applications. For Eg:Ms Excel,Ms Access The script you build to test the application should retrieve information from the external source. Working with Excel A mon source used for storing application test data is Microsoft Excel. The QTP DataTable object includes the following methods for working with Excel: ?IMPORTSHEET ?EXPORTSHEET Using the Using the (con’t) You use the IMPORTSHEET method to dynamically populate a QTP data sheet. The data in the first row of the Excel worksheet will be used as the columns names for the QTP data sheet. In Figure 82 above, the data stored in worksheet DATASET1 in file IS IMPORTED INTO THE QTP DATA SHEET FOR THE ACTION GETDATA. Once the data is imported, the data sheet can be used to drive the iterations of the actions. Using the Method You use the EXPORTSHEET method to dynamically create an Excel data log from your QTP run session. You can store the data to an existing Excel file and worksheet, or more monly create a new Excel file and worksheet. In Figure 83 above, the data from the PURCHASEFLIGHT data sheet in a new Excel file. The property is used so that the Excel file is created in the same place as the test results. Working with Databases The test data for your application may be stored in a database. The overall steps for a QTP script to retrieve data from a database are as follows: to the Database. a SQL query the query results. the database session. The ADO Objects The M