天天看點

QTP Tips

QTP Tips

1. 生成随機數的函數

Function makeNUMstring(inputlength)

 If IsNumeric(inputlength) Then

  For I = 1 To inputlength

    'A數組中可放入你想随機産生的任何字元串中的字元

   A = Array("1","2","3","4","5","6","7","8","9")

   Randomize

   x=RandomNumber (0,8)

   B = A(x)

   makeNUMstring =makeNUMstring +B

  Next

 else

  msgbox (inputlength&"不是一個數字!!")

 End If

End Function

2. 修改Excel中的資料

set srcData = CreateObject("Excel.Application")

srcData.Visible = true

on error resume next

Set DefalutXls = srcData.Workbooks.Open("C:\Default.xls")

DefalutXls.Worksheets("sheet1").Activate

DefalutXls.Worksheets("sheet2").Cells(3,2).Value = trim(DataTable("Para2", dtLocalSheet))

DefalutXls.Worksheets("sheet2").Cells(3,3).Value = DataTable("Para2", dtLocalSheet)

DefalutXls.Save

srcData.Quit

Set srcData= Nothing

' Cells(x,y)  x: 行,y:列

3. 修改Word文檔

Set oWord = CreateObject("Word.Application")

oWord.documents.open "c:\temp.doc",ForWriting, True

Set oDoc = oWord.ActiveDocument

Set oRange = oDoc.content

oRange.insertafter "test"

Set oRange = Nothing

Set oDoc = Nothing

Set oWord = Nothing

4. 關閉所有IE浏覽器

SystemUtil.CloseProcessByName("IEXPLORE.EXE")

5. 打開制定URL

SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE", http://192.168.1.2/

6. 修改readonly的屬性以适應自動化測試

Browser("Browser").Page("Page").WebFile("myFile").object.outerhtml = "<INPUT type=file size=50 value=C:\MyFuctions.vbs name=myFile unselectable= "&"off " & ">"       

然後再使用Set方法指派就可以了

posted on 2007-06-29 14:55  Ernestine 閱讀( ...) 評論( ...) 編輯 收藏

轉載于:https://www.cnblogs.com/Ernestine/archive/2007/06/29/800243.html