|
本帖最后由 lanbingkafei 于 2012-4-11 10:45 编辑
Test Automation Framework –Creating Test data tables
1 论坛有字数限制,这一部分省略……
2 CONVENTIONS FOR CREATING TEST DATA SOURCES
• Store the required external test data files (created using the template) in corresponding module-specific sub-folders in the “Test_Data” folder.
Note: In Quality Center environment, please ensure that the sub-folder structure that is maintained in the “Test_Data” and “Test_Scripts” folder is identical.
• In each Test data table, the data for only one automated test script should be provided.
• The name of the test data table should be the same as that of the automated test script for which the data is stored.
• The names of each of the columns in the table should be unique.
• Each data table must have an “Execute” column:
o Allowed values in the “Execute” column are “Yes” and “No”.
o These values determine whether the data in the row is used during script execution.
3 PROCEDURE FOR CREATING TEST DATA FILES IN EXCEL FORMAT
Steps to execute: For creating one or multiple Test data sources in Excel format.
a) Copy the template “Test_Data_Source_Template.xls” from the “Test_Templates” folder to the required sub-folder in “Test_Data” folder.
b) After placing it in the desired sub-folder in the “Test_Data” folder, the test data file should be renamed as per requirement.
c) If required, repeat the above steps for creating multiple test data sources that can hold the test data for automated test scripts of multiple modules.
Note: Refer the “instructions” worksheet available in the “Test_Data_Source_Template.xls” file for the conventions to follow when creating test data tables in the test data source files.
4 PROCEDURE FOR CREATING TEST DATA TABLES IN EXTERNAL FILES
Example scenario:
A data file named “Login_Data” is used to store the test data for the “Login” functionality of the “Flight Test” application.
What is the procedure for creating the test data table that meets the following requirements?
• It should have columns named “Agent Name”, “Password”, “Expected Result” and “Execute”
• Both the Agent Name and Password columns in the table stores alphanumeric data.
• The Expected Result column stores the title text of the next window displayed upon successful login.
• Five rows of test data are to be stored in the table.
Steps to execute:
a) Open the test data file named Login_Data.xls stored at c:\MyProject\Test_Data\Login\.
b) Rename the worksheet “Sheet_Name1” to “LoginData”.
c) In the “LoginData” worksheet, select the row where the column names of the table are to be entered and type the names of the required columns as shown here.
d) . Because the requirement is to store five rows of test data values in the table, select the range of cells comprising the column headers and five additional rows below them.
e) From the Insert menu, select Name and then Define.
f) On the Define Name window, in the Names in Workbook field, type LoginTest, and click OK. This step creates a table that can hold five rows of test data in the corresponding columns.
g) Verify that the required table was created. From the list of table names in the upper-left corner, select the name of the table you just created (LoginTest). The range of cells for that table will be selected as shown here.
h ) Define the format of the data in the columns. We’ll format the Agent Name column as an example.
Select the range of cells in the rows below the Agent Name header. From the Format menu, select “Cells”.
i) On the Format Cells window, select Text from the Category list, and click OK.
Note: In instances where different rows of the same column may hold numeric and text values, it is recommended that you select the Text format to avoid runtime errors.
Adding Test data to rows in Test data table
a) In the rows, under the corresponding column enter the required data. Under the “Execute” column, if you want the automated test script to use this row of test data for execution at runtime, enter the value “Yes” else enter the value “No”.
b) Repeat the above steps for all required test data values.
Note : If you have added Test data rows that are less than the number of the rows of the overall table, this will not impact the result of execution in any way. But if you have added rows of test data that are beyond the range of the table, the extra rows will not be considered for execution. In this scenario, you will have to expand the range of the table in the following way.
Delete the table by using “Insert -> Name – Define” and then select the required table name from the list of values and then click on “Delete” button. After this, select all the extra rows of test data (there is no need to delete the data that already exists) and create the table by following the process as explained earlier.
j)Because one worksheet can include multiple tables, it is recommended that you put the name of the table above the corresponding column headers as shown here. This approach helps to identify tables containing the data of an automated test script.
Repeat the same process to add multiple test data tables in the same worksheet or other worksheets of the Test data source in excel format. But in creating multiple tables of data, where each table has data corresponding to its automated script, you have to take care to ensure that the ranges of cells that you select for each table do not overlap.
==============以上是制作数据表格的方法,虽然没办法传图片,按照这个步骤,也可操作======
===================以下是访问刚才制作的数据表格的代码===================================- 'Connect to the External Data file that contains the required test data table.
- Call Connect_Test_Data_Source( "ORDER","Order.xls")
- ' After the above function call is executed, the variable g_objResultSet will have reference to the returned recordset.
- 'Get the count of test data rows in the test data table that have been selected for execution
- total_DataRows_Selected =g_objResultSet.Recordcount
- 'Validate whether the test data table has atleast one row of test data selected for execution.
- If total_DataRows_Selected < 1 Then
- Reporter.ReportEvent micFail, "Validate for Input Data","Please do provide the input data for the execution"
- ExitTest
- End If
- 'Iterate the test for all the selected rows of test data
- For Row_Index =1 to total_DataRows_Selected
- For DummyLoop =1 to 1
- 'The dummy loop Used to establish the following control. In case the script encounters a failure for a particualar data row. instead of aborting the test
- 'the user can use ExitFor to exit the current loop and still continue the test for the remaining rows of test data.
- Reporter.ReportEvent micDone, "Data Iteration : " &Row_Index,"Scenario is executing for " & Row_Index & " data set"
- Username =Get_DataValue(Row_Index,"USERNAME")
- Password = Get_DataValue(Row_Index,"PASSWORD")
- 'TODO:Your automation code
- Next
复制代码- '============================================================================================================================
- 'Function Name : Connect_Test_Data_Source
- 'Description : Establishes the Connection with the Specified Test Data source & assigns the recordset to the global variable - g_objResultSet
- 'Applicable Objects: None
- 'Arguments : FolderName, FileName in which the Test Data is present
- 'Return value : None
- 'Example : Connect_Test_Data_Source("c:\Flight Reservation","Transaction.xls")
- '============================================================================================================================
- Function Connect_Test_Data_Source(FolderName,FileName)
- 'Download the datafile from QC to Local drive
- 'Call Downloadfile_From_QC(FolderName,FileName,Environment.Value("TEST_DATASOURCE_LOCATION"))
- TestID = Environment.value("TestName")
- Set g_objConnection=CreateObject("ADODB.Connection")
- Set g_objResultSet =CreateObject("ADODB.RecordSet")
- If QualityCenter_Environment="Yes" Then
- If FolderName <> "" Then
- RetVal=Downloadfile_From_QC(arrFolders(0) & "\Test_Data\" & FolderName ,strLocalPath & "\Test_Data\" & FolderName &"\" ,FileName)
- Else
- RetVal=Downloadfile_From_QC(arrFolders(0) & "\Test_Data\" & FolderName ,strLocalPath & "\Test_Data\" ,FileName)
- End If
- If RetVal<>"PASS" Then
- Reporter.ReportEvent micFail,"Download File from QC",RetVal
- ExitTest
- End If
- g_objConnection.ConnectionString ="DBQ=" & strLocalPath & "\Test_Data\" & FolderName &"\" & FileName &";Driver=Driver do Microsoft Excel(*.xls)"
- Else
- g_objConnection.ConnectionString ="DBQ=" & arrFolders(0) & "\Test_Data\" & FolderName &"\"& FileName &";Driver=Driver do Microsoft Excel(*.xls)"
- End If
- g_objConnection.Open
- g_objResultSet.Open "select * from " & TestID & " where Ucase(Execute) ='YES'",g_objConnection,1,1
- End Function
复制代码 |
|