-
TestComplete 学习笔记3_Stores_CheckPoint
2008-09-22 23:59:01
Region CheckPoint的例子:
Sub RegionCompareExample
If (Not Regions.Compare("Logo", Sys.Process("iexplore"). _
Page("http://www.activefocus.net/").Table(0).Cell(1, 0). _
Link(0).Image("nav_r1_c1"), False, False, True, 0)) Then
Call Log.Error("The regions are not identical.")
End If
End SubFile CheckPoint的例子:
Sub FileCompareExample
If (Not Files.Compare("Sample1.txt", "Sample2.txt", 0, True)) Then
Call Log.Error("The files are not identical.")
End If
End Sub如果知道两个文件差异的Hash值,还可以进行Hash值判断
例如HashValue=18471005
Sub FileCompare
If Files.Compare("TestData1.txt","TestData2.txt", 18471005,True) then
Call Log.Message("The Files are diffrent in hashvalue=1847010015")
End IF
End Sub可通过Files.CalculateHashValue("File1.txt","File2.txt")获取两个文件差异的Hash值,例如
Sub FileCompare
If not Files.Compare("TestData1.txt","TestData2.txt", Files.CalculateHashValue("TestData1.txt","TestData2.txt") ) then
Call Log.Message("The Files are diffrent in hashvalue=1847010015")
End IF
End SubObject CheckPoint的例子: 比较实际Object的属性与Stores下的Object的属性是否一致
Sub ObjectCompareExample
If (Not
Objects.Compare(Sys.Process("iexplore").Page("http://www.activefocus.net/").Panel(0), "Panel", True)) Then
Call Log.Error("The objects are not identical.")
End If
End Sub -
TestComplete 学习笔记2_Data-Driven Testing
2008-09-21 23:32:43
TC用DDT来支持数据驱动测试,DDT包括3种类型:
1 CVSDriver is used to read text file such as comma delimited (default) or tab delimited (using a schema.ini file). By default the first row is the header information (or column names) for the driver.
Example:
Case,User,Password
1,"admin","admin"
2,"user1","pass1"
2 ExcelDriver is used to read an Excel spreadsheet. The first row of the sheet is the header information for the driver.
3 ADODriver is a generic driver to read in ADO compatible data source. DDT中几个常用的方法和属性:
ColumnCount: The number of column in the data source.
ColumnName: The name of a given column from the data source.
Name: The Name of the Driver.
Value: Returns the value of a column based on the column name or index.
EOF: Indicates if the driver is at the end of the data source.
DriveMethod: Iterates through all the records of the database, and executes a scrīpt routine for each records. Next: Move to the next record in the data source Example_1:
Dim DDTObject
Sub Main
TestedApps.TestedApp.Run()
Set DDTObject= DDT.CSVDriver(Files.FileNameByName("TestData.txt")) DDTObject.DriveMethod("Unit2.Test1")
DDT.CloseDriver("DDTObject")
End Sub
Sub Test1
Dim w1
Set w1 = Aliases.mainForm
w1.WinFormsObject("trackBar1").wPosition = DDTObject.Value("Iterations") w1.WinFormsObject("checkBox3").Checked = DDTObject.Value("Greedy")
w1.WinFormsObject("comboBox1").ClickItem(DDTObject.Value("Strategy")) w1.WinFormsObject("comboBox2").ClickItem(DDTObject.Value("Stores")) w1.WinFormsObject("button1").ClickButton
End Sub
Example_2:
Sub Main
TestedApps.TestedApp.Run()
DDT.CSVDriver(Files.FileNameByName("TestData.txt"))
DDT.CurrentDriver.DriveMethod("Unit2.Test1")
DDT.CloseDriver("DDTObject")
End Sub
Sub Test1
Dim w1
Set w1 = Aliases.mainForm
w1.WinFormsObject("trackBar1").wPosition = DDT.CurrentDriver.Value("Iterations") w1.WinFormsObject("checkBox3").Checked = DDT.CurrentDriver.Value("Greedy") w1.WinFormsObject("comboBox1").ClickItem(DDT.CurrentDriver.Value("Strategy")) w1.WinFormsObject("comboBox2").ClickItem(DDT.CurrentDriver.Value("Stores")) w1.WinFormsObject("button1").ClickButton
End Sub
Example_3:
Sub Main
TestedApps.TestedApp.Run()
Set DDTObject= DDT.CSVDriver(Files.FileNameByName("TestData.txt"))
While not DDTObject.EOF
Call Test1()
DDTObject.Next()
Wend
End Sub
Sub Test1
Dim w1
Set w1 = Aliases.mainForm
w1.WinFormsObject("trackBar1").wPosition = DDTObject.Value("Iterations") w1.WinFormsObject("checkBox3").Checked = DDTObject.Value("Greedy") w1.WinFormsObject("comboBox1").ClickItem(DDTObject.Value("Strategy")) w1.WinFormsObject("comboBox2").ClickItem(DDTObject.Value("Stores")) w1.WinFormsObject("button1").ClickButton
End Sub
Example_4:
Dim MyDriver
Sub Main
Dim SQLStatement
Dim ConnectionString
' Start Notepad
TestedApps.Notepad.Run
' Limit to 100 records
SQLStatement = "SELECT TOP (100) CustomerID, FirstName, LastName FROM" & _ " Sales.vIndividualCustomer"
ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _ "Persist Security Info=False;" & _ "Initial Catalog=AdventureWorks;Data Source=.\SQLExpress"
' Create Driver
Set MyDriver = DDT.ADODriver(ConnectionString,SQLStatement)
' Call Method 100 times
MyDriver.DriveMethod("Unit1.Test1")
End Sub
Sub Test1
Dim p1
Dim w1
Dim w2
Dim KeyStr
Set p1 = Sys.Process("Notepad")
Set w1 = p1.Window("Notepad", "*")
Set w2 = w1.Window("Edit") w2.VScroll.Pos = 0
' Create String with Customer Information
KeyStr = MyDriver.Value("CustomerID")& "," & _ MyDriver.Value("FirstName")& "," & _ MyDriver.Value("LastName")& "[Enter]"
Call w2.Keys( KeyStr)
End Sub
-
TestComplete 学习笔记1_Namemapping
2008-09-21 15:12:13
- TC没有像QTP一样的对象库以及对象库管理功能,但是对于那些“又长又臭”的代码行,可以通过Named Mappings 和Aliases 来缩短代码行,并且让测试对象的命名更加有意义,从而让录制和编写的脚本更加清晰、直观易懂。
TestComplete provides Named Mappings and Aliases to tame extremely long object identifiers that have meaningless default names. For example:
Sys.Process("Hello").Panel1.Panel2.Container1.Container2.button1
Clearly there are numerous issues with this identifier, its long and awkward not to mention we have no clue about the purpose or identity of "Container1", "Container2" or "button1". Named Mappings allow you to rename Panel1, Panel2, Container1, Container2 and button1 to useful names like MyPanel,myInsidePanel, myTabs, myPages and btnSubmit. The issue here is that you still need to type:
NameMappings.Sys.Process("Hello").MyPanel.myInsidePanel.myTabs.myPages.btnSubmitTestComplete lets you create an Alias to represent this long string. If you create the Alias "btnSubmit",you only need to type:
Aliases.btnSubmit可通过两种方法实现NameMapping:
- Mapping an object with TestComplete’s dialogs and panels
- To map an object’s name via the Object Browser:
- Switch to the Object Browser panel.
- Choose the desired object in this panel and select Map the Object Name from the context menu.
-- or --
- To map an object’s name directly using the Tools toolbar:
- Press the Open the Tools Window button on TestComplete's toolbar or choose the menu item Tools | Tools. This will bring up the Tools toolbar.
- Activate the application's window that holds the onscreen object you want to map.
- Click the Map Object From Screen button (the mouse cursor will turn into the Finder tool glyph ), hold the mouse button down and drag the glyph over the screen. As you move, the red frame will surround onscreen objects which are under the glyth. Release the mouse button over the desired object.
To map an object, use the
AddNamedChild
method of any mapped object (this method is added after the object was mapped). This method uses four parameters:obj.AddNamedChild(SysNode, ChildName, Descrīption, Properties)
- SysNode - Specifies the object to be mapped.
- ChildName - Specifies the desired mapped name for an object.
- Descrīption - Specifies the mapped item’s descrīption.
- Properties - Holds an array of object property names that will be used for object recognition.
By calling the
AddNamedChild
method of a mapped object, you make its child object a child mapping item.The following scrīpt code maps the
Sys
object and then allprocess
objects (children of Sys). We assume that theSys
object has already been mapped tosys2
:Sub TestNameMapping
' Creating the property array
Arr = CreateVariantArray(0, 1)
Arr(0) = "ProcessName"
Arr(1) = "Index"
' Mapping objects
For i = 0 To Sys.ChildCount - 1
Set ProcessObj = Sys.Child(i)
If ProcessObj.MappedName = "" Then
' Generating the mapped name
s = ProcessObj.ProcessName + CStr(ProcessObj.Index)
' Checking if the mapped name can be used
If IsValidIdent(s) Then
' Mapping the object
' We assume that the Sys object is mapped to sys2.
NameMapping.sys2.AddNamedChild ProcessObj, s, "The process object", Arr
Else
Log.Message "Cannot map the object " + ProcessObj.Name
End If
End If
Next
End Sub - TC没有像QTP一样的对象库以及对象库管理功能,但是对于那些“又长又臭”的代码行,可以通过Named Mappings 和Aliases 来缩短代码行,并且让测试对象的命名更加有意义,从而让录制和编写的脚本更加清晰、直观易懂。