QTP的Utility对象

2010-04-27  吕施娟 

1.Crypt对象
   (1)Crypt.Encrypt(Data) 

  pwd = "GetPasswordfromSomewhere"

  e_pwd = Crypt.Encrypt(pwd)

  Browser("dfgd").Dialog("pass").WinEdit("pwd").SetSecure e_pwd

2.DataTable对象

Methods:

  (1)DataTable.AddSheet(SheetName)

   Variable=DataTable.AddSheet ("MySheet").AddParameter("Time", "8:00")

  (2)DataTable.DeleteSheet SheetID

   DataTable.DeleteSheet "MySheet"

  (3)DataTable.Export(FileName)

    DataTable.Export ("C:\flights.xls")

  (4)DataTable.ExportSheet(FileName, DTSheet)

    DataTable.ExportSheet "C:\name.xls" ,1

  (5)DataTable.GetCurrentRow 

    row = DataTable.GetCurrentRow

    Reporter.ReportEvent 1, "Row Number", row

  (6)DataTable.GetRowCount 

      'add a new column
     DataTable.GetSheet("dtGlobalSheet").AddParameter "NewColumn","Row1Value"

     'copy the cells from the old column into the new column
     cnt=DataTable.GetRowCount
    For i=1 to cnt
         DataTable.SetCurrentRow(i)
         OldVal=DataTable.Value("OldColumn","dtGlobalSheet")
        DataTable.Value("NewColumn","dtGlobalSheet")=OldVal
    Next

     'delete the old column
     DataTable.GetSheet("dtGlobalSheet").DeleteParameter("OldColumn")

    (7)DataTable.GetSheet(SheetID)

    (8)DataTable.GetSheetCount

    sheetcount = DataTable.GetSheetCount

    Reporter.ReportEvent 0, "Sheet number", "There are " & sheetcount & " sheets in the Data Table."

  (9)DataTable.Import(FileName)

     DataTable.Import ("C:\flights.xls")

  (10)DataTable.ImportSheet(FileName, SheetSource, SheetDest)

      DataTable.ImportSheet "C:\name.xls" ,1 ,"name"

  (11)DataTable.SetCurrentRow(RowNumber)

      'add a new column
     DataTable.GetSheet("dtGlobalSheet").AddParameter "NewColumn","Row1Value"

     'copy the cells from the old column into the new column
     cnt=DataTable.GetRowCount
    For i=1 to cnt
       DataTable.SetCurrentRow(i)
       OldVal=DataTable.Value("OldColumn","dtGlobalSheet")
       DataTable.Value("NewColumn","dtGlobalSheet")=OldVal
    Next

   'delete the old column
   DataTable.GetSheet("dtGlobalSheet").DeleteParameter("OldColumn")

  (12)DataTable.SetNextRow

      DataTable.SetNextRow

  (13)DataTable.SetPrevRow

      DataTable.SetPrevRow

Properties:

  (1)DataTable.GlobalSheet

     ParamValue=DataTable.GlobalSheet.AddParameter("Time", "5:45")

     DataTable.GlobalSheet.AddParameter "Time", "5:45"

  (2)DataTable.LocalSheet

     MyParam=DataTable.LocalSheet.AddParameter("Time", "5:45")

  (3)DataTable.RawValue ParameterID [, SheetID]

      FormulaVal=DataTable.RawValue ("Date", "ActionA")

  (4) DataTable.Value(ParameterID [, SheetID])

    or DataTable(ParameterID [, SheetID])

   To set the value:

      DataTable.Value(ParameterID [, SheetID])=NewValue

   or DataTable(ParameterID [, SheetID]) =NewValue

3.Description 对象

(1)set PropertiesColl = Description.Create  

   set EditDesc = Description.Create()

   EditDesc("Name").Value = "userName"

   EditDesc("Index").Value = "0"

   Browser("Welcome: Mercury").Page("Welcome: Mercury").WebEdit(EditDesc).Set "MyName"

4.DotNetFactory对象

(1)Set var_CreateInstance = DotNetFactory.CreateInstance (TypeName [,Assembly] [,args])

  

Set var_CreateInstance = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")

var_CreateInstance.Show

wait 2

var_CreateInstance.Close

The following example uses the CreateInstance method to create an instance of a system environment object, and to display a message box listing the current directory. In this example, there is no need to specify the optional arguments because the required assembly is already in memory.

Set var_CreateInstance = DotNetFactory.CreateInstance("System.Environment")
msgbox var_CreateInstance.CurrentDirectory

5.Environment 对象

To set the value of a user-defined, environment variable:

Environment (VariableName) = NewValue

Methods:

(1)Environment.LoadFromFile(Path)

  Environment.LoadFromFile("C:\QuickTest\Files\MyVariables.xml")

Properties:

(1)Environment.ExternalFileName

'Check if an External Environment file is loaded and if not, load it.

fileName = Environment.ExternalFileName

If (fileName = "") Then

       Environment.LoadFromFile("C:\Environment.xml")

End If

'display value of one of the Environment variables from the External file

msgbox Environment("MyVarName")

(2) Environment.Value(VariableName) = NewValue

Environment.Value("MyVariable")=10

MyValue=Environment.Value("MyVariable")

6.PathFinder对象

(1)PathFinder.Locate (RelativePath)

y=PathFinder.Locate ("MyEnvFile.txt")

7.Reporter对象

(1)Reporter.ReportEvent EventStatus, ReportStepName, Details [, ImageFilePath]

Browser("Browser").Page("WebPage").Image("MyLogo").CaptureBitmap("MyLogo.bmp")

Reporter.ReportEvent micDone, "Display Logo", "This is my logo", "MyLogo.bmp"

(2)Reporter.Filter 属性

The following example uses the Filter property to report the following events in the Test Results: 1, 2, 5, and 6.

Reporter.ReportEvent micGeneral, "1", ""

Reporter.ReportEvent micGeneral, "2", ""

Reporter.Filter = rfDisableAll

Reporter.ReportEvent micGeneral, "3", ""

Reporter.ReportEvent micGeneral, "4", ""

Reporter.Filter = rfEnableAll

Reporter.ReportEvent micGeneral, "5", ""

Reporter.ReportEvent micGeneral, "6",

(3)Reporter.ReportPath 属性

dim Path

Path = Reporter.ReportPath

MsgBox (Path)

(4)Reporter.RunStatus 属性

If Reporter.RunStatus = micFail Then ExitAction

8.

 

 


 

 

 

 

569°/5692 人阅读/0 条评论 发表评论

登录 后发表评论