The difference between data-driven and keyword-driven. Write a testing framework that you are familiar with and parse its architecture.
[Data-driven] uses data to control the test business flow, that is, different data is used in the test to direct different test results.
Four ways to achieveData-driven.
1. datatable
The qtp program provides us with such a data table. We can enter the test data or test cases in this data table.
Example: design case
Username passwd
Case1 Mercury
Case2 xxxxxxx xxxxxx
Recording script
For I = 1 to datatable. getrowcount
Dialog ("login"). winedit ("agent name:"). Set datatable ("username", dtglobalsheet)
Dialog ("login"). winedit ("Password:"). Set datatable ("passwd", dtglobalsheet)
Dialog ("login"). winbutton ("OK"). Click
Datatable. globalsheet. setnextrow
Next
In this example, a login system is verified, and the test result is achieved through the different use case design of datatable. of course, there is still one very important step in the above example, that is, result comparison. automated tests that cannot compare results cannot be called automated tests.
Of course, here we mainly talk aboutData-driven.
2. Text Files
We can use a text file as a data file and perform read/write operations on the text file.Data-driven.
For example, content in a text file
Mercury, mercuy
Code for reading files
Function writeorderno (orderno)
Dim FSO, myfile, username, passwd
Set FSO = Createobject ("SCR reject pting. FileSystemObject ")
Set myfile = FSO. opentextfile ("C: esting.txt", 1, false)
TMP = Split (myfile. Readline ,",")
Username = TMP (0)
Passwd = TMP (1)
Myfile. Close
End Function
Code for writing text files
Function writeorderno (orderno)
Dim FSO, myfile
Set FSO = Createobject ("SCR reject pting. FileSystemObject ")
Set myfile = FSO. opentextfile ("C:
Esult1.txt ", 8, false)
Myfile. writeline orderno
Myfile. Close
End Function
3. Excel files
We can use an Excel file as a data file, through the read and write operations on the Excel file, to achieveData-driven.
Excel files can be written as objects.
Dim excel, excelsheet
Set Excel = Createobject ("Excel. application ")
Set excelsheet = Createobject ("Excel. Sheet ")
Excelsheet. application. Visible = true
Excelsheet. activesheet. cells (1, 1). value = 1
Excelsheet. activesheet. cells (1, 2). value = 2
Excelsheet. activesheet. cells (1, 3). value = 3
Excel. Save "C: est.xls"
Set excelsheet = nothing
Use ADO to connect Excel files for read Operations
Dim Conn, input, filename
Filename = "D: Basic Public Information (tb_gsgk316-standard format .xls "'
Set conn = Createobject ("ADODB. Connection ")
Conn. Open "provider = Microsoft. Jet. oledb.4.0; persist Security info = false; Data Source =" & filename & "; extended properties = 'excel 8.0; HDR = Yes '"
Set input = Createobject ("ADODB. recordset ")
Input. Open "select * from [common basic information-Standard Format $]", Conn
Input. Close
Set input = nothing
4.Database
You can use the design data table to store test data and test cases in the data table, and connect to the database by using ADO or any other means that you can access the database.Data-driven
Dim res, CMD, SQL
Set res = Createobject ("ADODB. recordset ")
Set cmd = Createobject ("ADODB. Command ")
Cmd. activec 'to connect to the database data source, which needs to be modified
Cmd. commandtype = 1
SQL = "selec T * from table where name = username"
Cmd. commandtext = SQL
Set res = cmd. Execute ()
Set res = nothing
Set cmd. activeconnection = nothing
Set cmd = nothing
The above four methods can help us implementData-driven, It should be saidData-drivenIt is necessary to discuss the wide application in automated testing.
Access through SQL connection
Dim Conn
Set conn = Createobject ("ADODB. Connection ")
Dim srvname
Srvname = "DSN = dblis50; uid = sa; Pwd =; APP = quicktest professional; wsid = admin; database = dblis50" 'to connect to the database data source, which needs to be modified
Conn. connectionstring = srvname
Conn. Open
Dim rec
Set rec = Createobject ("ADODB. recordset ")
Dim SQL
SQL = "select top 1 * From lis_list"
Rec. Open SQL, Conn
Dim Username
Username = Rec. Fields ("patname ")
Msgbox Username
Access through SQL connection
Dim Conn, res, CMD, SQL, strconn
Set conn = Createobject ("ADODB. Connection ")
Set res = Createobject ("ADODB. recordset ")
Set cmd = Createobject ("ADODB. Command ")
Strconn = "DSN = dblis50; uid = sa; Pwd =; APP = quicktest professional; wsid = admin; database = dblis50" 'to connect to the database data source, which needs to be modified
Conn. connectionstring = strconn
Conn. Open
Cmd. activeconnection = Conn
Cmd. commandtype = 1
SQL = "select Top 2 * From lis_list"
Cmd. commandtext = SQL
Set res = cmd. Execute ()
Dim Username
Username = res. Fields ("patname ")
Msgbox Username
Set res = nothing
Set cmd. activeconnection = nothing
Set cmd = nothing
[Keyword-driven] uses keywords to control the test business flow. different keywords are used in the test to guide different test results.
Keyword-driven testing is an improved type of data-driven testing. The key words include three types: operated objects (controls), actions (events) and values can be expressed as controls in the form of object-oriented. operation (value), the test logic is decomposed according to these keywords to form a data file, and the test logic is encapsulated in the data file in the form of keywords, test Tools can automate their applications as long as they can interpret these keywords. Use specific steps to explain the keyword-driven:
1. Create an Object Library:
Encapsulate all object (Control) attributes and Methods
2. Compile the script and assign values to the operations by using the encapsulated controls and their corresponding methods.
Keyword-Driven Testing indicates that there is no need to perform real recording and playback, and there is no need to perform automated testing when the software is very stable. In addition, testers can directly intervene as long as they know enough about the software business.
Initially, qtp is a simple recording, and then the script is modified. The disadvantages are as follows:
1. The application software must have a certain degree of stability and must be fully implemented in the entire business process. Otherwise, it can be achieved through sequential recording?
2. the maintenance cost of automated scripts is very high.
3. the reusability of automated scripts is relatively poor.
The keyword-driven concept emerged, and everything started with objects. This is a bit like converting from procedural to object-oriented in programming languages. The specific implementation methods in qtp are as follows:
1. manually add The objects involved in the test to the object library on a single program interface
2. Compile automated test scripts based on objects in the object library in the expert view
The obvious advantages of the above operations are:
1. Strong controllability of scripts and good Modular Organization
2. A test script can be created before all business flow functions can be fully implemented in the development process, which occupies a large amount of initiative and provides more space for time arrangement: "Test first"
From: http://bbs.51testing.com/viewthread.php? Tid = 113729 & extra = & Highlight = % Ca % fd % be % DD % C7 % fd % B6 % AF & page = 1
[Test Job Search] related to automated testing