Keyword-driven test framework

Source: Internet
Author: User

The third phase of the development of the automated testing framework is the keyword-driven test framework phase, which is one of the most popular frameworks, and now the automated Test tool QuickTest has incorporated the keyword-driven framework into the tool. The automated test tool saves object and action properties to the object library during the recording process.

Each test step after recording is composed of three elements: Item: Refers to the object name, can be a window, a button, etc. operation: refers to the action to be performed, such as SELECT, click, etc. Value: The number entered by the action action The value of the data;

Take the airplane booking system of QuickTest as an example, record its login process and generate the following code:

Dialog ("Login"). Winedit ("Agent Name:"). Set "Test"

Dialog ("Login"). Winedit ("Password:"). SetSecure "4d410e55b694bada39e235f9896e6eb810ba0e60"

Dialog ("Login"). Winbutton ("OK"). Click

This is the code that QuickTest generates in a key-driven way, but you can also implement keyword-driven testing through code. Keyword-driven testing is at the heart of the keyword table. For example, the keywords table of the aircraft booking system is shown in table 19-1.

Parent object

Child Object

Describe

Event

Value

Dialog

 

Text:=login

Launch

D:\QuickTest Professional\samples\flight\app\flight4a.exe

Dialog

Winedit

Attached text:=agent Name:

Set

Test

Dialog

Winedit

Attached Text:=password:

Set

Mercury

Dialog

Winbutton

Text:=ok

Click

 

The keyword-driven approach is to extract the objects and data from the keyword tables and construct them into each test step, such as steps:

Dialog ("Login"). Winedit ("Agent Name:"). Set "Test"

You need to read the objects, attributes, and input data from the key table and construct code steps in the same format to implement the keyword-driven functionality.

Here is a keyword-driven framework for debugging a good one, with the following code:

—————————————————————————————————

''

' Project name: keyword driven

'

Method

' Getexcelcells ————— read the values in the cell

' Getexclesheetrowscount ————— get the number of rows in the driver table for the keyword

' Oparentobject ————— Construct Parent Object

' Ochildobject ————— Construction Sub-object

' Oeventobject ————— assigning values to object properties

'

' Version: v1.0

' Author: Huang Wengao

' Time: 2011-01-27

'———————————————————————————————————

Dim Arrobjectname

Dim oparent

Dim Ochild

Dim Oclassname

Dim Ovalue

Dim object

'———————————————————————————————————

''

' Function name: getexcelcells

'

Parameters

' Excelpath ————— the path to the keyword driver table

' SheetName ————— the sheet name of the keyword driver table

' Sheetrow ————— rows in a cell

' Sheetcolumn ————— a column in a cell

'

' Time: 2011-01-27

'——————————————————————————————————

Function Getexcelcells (Excelpath,sheetname,sheetrow,sheetcolumn)

Set Excelbook = CreateObject ("Excel.Application")

Set ExcelSheet = CreateObject ("Excel.Sheet")

Set Myexcelbook = ExcelBook.WorkBooks.Open (Excelpath)

Set Myexcelsheet = myexcelbook.worksheets (sheetname)

Sheetvalue = Myexcelsheet.cells (sheetrow,sheetcolumn). Value

Getexcelcells = Sheetvalue

Excelbook.quit

Set ExcelSheet = Nothing

Set Excelbook = Nothing

End Function

'——————————————————————————————————

''

' Function name: Getexclesheetrowscount

'

Parameters

' Excelpath ————— the path to the keyword driver table

' SheetName ————— the sheet name of the keyword driver table

'

' Time: 2011-01-27

'——————————————————————————————————

Function Getexclesheetrowscount (Excelpath,sheetname)

Set Excelbook = CreateObject ("Excel.Application")

Set ExcelSheet = CreateObject ("Excel.Sheet")

Set Myexcelbook = ExcelBook.WorkBooks.Open (Excelpath)

Set Myexcelsheet = myexcelbook.worksheets (sheetname)

Getexclesheetrowscount = MyExcelSheet.UsedRange.Rows.Count

Excelbook.quit

Set ExcelSheet = Nothing

Set Excelbook = Nothing

End Function

'——————————————————————————————————

''

' Function name: Oparentobject

'

Parameters

' ParentObject ————— the parent column of the keyword driver table

'

' Time: 2011-01-27

'——————————————————————————————————

Function Oparentobject (ParentObject)

Arrobjectname = Array ("Text:=login", "Regexpwndtitle:=flight reservation")

' Here you can add some other object types, such as the browser object

' Because there may be many objects in the Keyword driver table

Select case LCase (parentobject)

Case "Window"

Set object = window (Arrobjectname (1))

Case "Dialog"

Set Object = Dialog (Arrobjectname (0))

Case Else

Print "Object Error"

End Select

End Function

'——————————————————————————————————

''

' Function name: Ochildobject

'

Parameters

' Childobject ————— the child column of the keyword driver table

' Childobjectname ————— The description column of the Keyword driver table

'

' Time: 2011-01-27

'————————————————————————————————

Function Ochildobject (Childobject,childobjectname)

If childobject <> "Then

' Here you can add some other sub-object types

' such as Weblist object

Select case LCase (childobject)

Case "Winedit"

Set Object = object. Winedit (Childobjectname)

Case "Winbutton"

Set Object = object. Winbutton (Childobjectname)

End Select

End If

End Function

'———————————————————————————————————

''

' Function name: Oeventobject

'

Parameters

' EventObject ————— the event column for the keyword driver table

' Ovalue ————— The value column of the Keyword driver table

'

' Time: 2011-01-27

'——————————————————————————————————

Function Oeventobject (Eventobject,ovalue)

If eventobject <> "Then

' Here you can add a variety of other properties, such as type

Select case LCase (eventobject)

Case "Set"

Object.set Ovalue

Case "click"

Object.click

Case Else

Print "Property Error"

End Select

End If

End Function

Systemutil. Run "D:\QuickTest Professional\samples\flight\app\flight4a.exe", "", "", ""

For I =5 to Getexclesheetrowscount ("C:\Data.xls", "TestCase")

Oparent = Getexcelcells ("C:\Data.xls", "TestCase", i,1)

Ochild = Getexcelcells ("C:\Data.xls", "TestCase", i,2)

Oclassname = Getexcelcells ("C:\Data.xls", "TestCase", i,3)

Oevent = Getexcelcells ("C:\Data.xls", "TestCase", i,4)

Ovalue = Getexcelcells ("C:\Data.xls", "TestCase", i,5)

Oparentobject oparent

Ochildobject Ochild,oclassname

Oeventobject Oevent,ovalue

Next

A keyword driven test framework from the QTP Automation test and framework model design book

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.