When the basic consistent business process, the need to test complex test data, you can parameterize the test data, while using a DataTable to achieve test data and business separation, this method in my current project is applied in many places, feel super convenient, now the work of the application to summarize:
1. Create a local Excel to store the parameter names and values of the test data.
2. Set Excel path in QTP
Open qtp->file->setting->environment->variable (select user-defined), click ... Settings such as:
By setting the LocalPath, the test data table does not need to be placed in a uniform path, increasing the flexibility of Excel path. The implementation of any computer running scripts can be set by QTP LocalPath to the local Excel test data table in advance.
The specific code is as follows:
DATASTR = Environment ("TestDir") & "\login.xls"
Datatable.addsheet ("Login")
Datatable.importsheet datastr, "login", "Login"
RowCount1 = Datatable.getsheet ("Login"). GetRowCount
Systemutil.run "C:\Program files\internet Explorer\iexplore. EXE "," http:\\deliver.sinosure.com.cn "
For i = 1 to RowCount1
DataTable. Setcurrentrow (i)
user = Datatable.value ("User", "Login")
PWD = Datatable.value ("pwd", "Login")
Browser ("China export Credit insurance company. *"). Page ("China Export Credit insurance company. *"). Webedit ("username"). Set User
Browser ("China export Credit insurance company. *"). Page ("China Export Credit insurance company. *"). Webedit ("password"). Set pwd
Browser ("China export Credit insurance company. *"). Page ("China Export Credit insurance company. *"). Webbutton ("Login"). Click
Browser ("China export Credit insurance company. *"). Page ("China Export Credit insurance company. *"). Webbutton ("logout"). Click
Next
The test data table is as follows:
PS:QTP an Excel document that supports XLS suffixes and does not support the xlsx suffix
Separating test data from business using a DataTable