TestComplete 学习笔记2_Data-Driven Testing

上一篇 / 下一篇  2008-09-21 23:32:43 / 个人分类:TestComplete学习

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


相关阅读:

TAG: TestComplete学习

引用 删除 why771023   /   2018-04-11 13:50:54
-5
测试无极限! 引用 删除 winnertesting   /   2010-01-20 02:04:49
这篇有点高深,没怎么看懂!
 

评分:0

我来说两句

我的栏目

日历

« 2024-04-02  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 2590
  • 日志数: 3
  • 建立时间: 2008-08-27
  • 更新时间: 2008-09-22

RSS订阅

Open Toolbar