Keyword framework of testcomplete Based on Excel

Source: Internet
Author: User
Tags testcomplete

Testcomplete gradually supports keyword Script Development after tc7, but there is no keyword view in previous versions.

 

Using EXCEL to store keywords is a popular practice in many keyword frameworks, which can also be implemented in testcomplete.

 

First, store keywords in Excel:

Object_name

Object_reference

Parent_object

Description

Notepad

SYS. Process ("Notepad ")

 

Notepad Application

Editor

Window ("Notepad", "*", 1). Window ("edit", "", 1)

Notepad

Editor for notepad

Changeddialog

Window ("#32770", "Notepad", 1)

Notepad

Do you want to save the changes Dialog

Nobutton

Window ("button", "& No", 2)

Changeddialog

No button on the Save changes Dialog

 

Then, write the keyword driver script in the TC script to read the Excel Data.

 

The following is a complete framework script (VBScript ):

 

Dim objectmapstorage

 

Class objectmap

Private m_testobject

Private m_objectreference

Private m_parentobject

Private m_objectinfo

Public property get testobject

Testobject = m_testobject

End Property

Public property get objectreference

Objectreference = m_objectreference

End Property

Public property get parentobject

Parentobject = m_parentobject

End Property

Public property get objectinfo

Objectinfo = m_objectinfo

End Property

Public property let testobject (value)

If (value <> m_testobject) then

If objectmapstorage. exists (m_testobject) then

Objectmapstorage. Remove (m_testobject)

End if

If objectmapstorage. exists (value) then

Objectmapstorage. Remove (value)

End if

M_testobject = Value

Call objectmapstorage. Add (m_testobject, me)

End if

End Property

Public property let objectreference (value)

M_objectreference = Value

End Property

Public property let parentobject (value)

M_parentobject = Value

End Property

Public property let objectinfo (value)

M_objectinfo = Value

End Property

Function gettestcompleteobject

Dim s

If (vartype (parentobject) = varnull) then

S = objectreference

Else

If not objectmapstorage. exists (parentobject) then

Log. Error ("unable to find parent [" & parentobject & "] of object [" & testobject & "]")

Set gettestcompleteobject = utils. createstubobject

Exit Function

End if

Dim parentobjmapitem

Set parentobjmapitem = objectmapstorage. Item (parentobject)

Dim parentobj

Set parentobj = parentobjmapitem. gettestcompleteobject

S = parentobj. fullname + "." + objectreference

End if

Set gettestcompleteobject = eval (s)

End Function

End Class

 

Function gettestcompleteobject (objectname)

If objectmapstorage. exists (objectname) then

Dim OBJ

Set OBJ = objectmapstorage. Item (objectname)

Set gettestcompleteobject = obj. gettestcompleteobject

Else

Log. Error ("object does not exist [" & objectname & "]")

Set gettestcompleteobject = utils. createstubobject

End if

End Function

 

Sub readobjectmap (objectmapexcelfile, sheet)

Set objectmapstorage = SYS. oleobject ("scripting. Dictionary ")

Set ddtdriver = DDT. exceldriver (objectmapexcelfile, sheet)

While not ddtdriver. EOF

Dim OBJ

Set OBJ = new objectmap

OBJ. testobject = ddtdriver. Value ("object_name ")

OBJ. objectreference = ddtdriver. Value ("object_reference ")

OBJ. parentobject = ddtdriver. Value ("parent_object ")

OBJ. objectinfo = ddtdriver. Value ("Description ")

Ddtdriver. Next

Wend

End sub

 

 

Sub testobjectmap

 

Set objectmapstorage = SYS. oleobject ("scripting. Dictionary ")

 

Dim OBJ

Set OBJ = new objectmap

OBJ. objectreference = "SYS. Process (" "Notepad "")"

OBJ. testobject = "Notepad"

Set obj1 = new objectmap

Obj1.objectreference = "window (" Notepad "", "*" ", 1 )"

Obj1.testobject = "notepad_main_window"

Obj1.parentobject = "Notepad"

Dim objchild

Set objchild = new objectmap

Objchild. objectreference = "window (" edit "")"

Objchild. testobject = "notepad_edit"

Objchild. parentobject = "notepad_main_window"

Set temp = objchild. gettestcompleteobject

End sub

 

 

 

Sub testreadobjectmap

Call readobjectmap (files. filenamebyname ("objectmap.xls"), "sheet1 ")

Gettestcompleteobject ("Editor"). Keys ("testcomplete ")

Gettestcompleteobject ("Dummy ")

End sub

 

 

Refer:

Simple keyword framework with testcomplete-Part 1-the object Map

Http://www.theholtons.info/eric/post/2008/05/Simple-Keyword-Framework-with-TestComplete---Part-1---The-object-map.aspx

 

Http://blog.csdn.net/Testing_is_believing/archive/2008/06/27/2593103.aspx

 

 

 

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.