VBScript 常用函數總結

來源:互聯網
上載者:User

下面是我總結的VBScript中常用的函數及其用法。

  1,GetROProperty

  說明:You use the GetROProperty method to retrieve the current value of a test object property from a run-time object in your application.

  一般來說,所有的對象都可以使用此方法得到運行時對象的實際值。

  文法:object.GetROProperty (Property, [PropertyData])

  如 ButtonName=Browser("QA Home Page")。Page("QA Home Page")。WebButton("Submit")。GetTOProperty("Name")

  2,WaitProperty

  說明:Waits until the specified object property achieves the specified value or exceeds the specified timeout before continuing to the next step.

  此方法可以解決由於等待系統進行處理某些操作或網路原因引起的測試對象同步問題。

  文法:object.WaitProperty (PropertyName, PropertyValue, [TimeOut])

  如

  Window("Test")。Static("Status:")。WaitProperty "text", "Ready", 30000

  3,Instr

  Returns the position of the first occurrence of one string within another.

  可以得到一個字串在另外一個字串中首次出現的位置。

  文法: InStr([start, ]string1, string2[, compare])

  4,Split

  Returns a zero-based, one-dimensional array containing a specified number of substrings.

  此函數可以把原來用某個特殊字元串聯接起來的字串分割開,得到一個一維的數組。

  5,UBound

  Returns the largest available subscript for the indicated dimension of an array.

  得到某個維度最大值。

  6,Trim

  Returns a copy of a string without leading spaces (LTrim), trailing spaces (RTrim), or both leading and trailing spaces (Trim)。

  如果需要刪除字串左邊的所有空格,那麼可以使用LTrim 函數;如果需要刪除字串右邊的所有空格,那麼可以使用RTrim 函數。如果需要刪除字串左邊和右邊的所有空格,那麼可以使用Trim 函數。

  7,Ucase

  Returns a string that has been converted to uppercase.

  此函數可以把所有的字元都轉換成相應的大寫。

  8,LCase

  Returns a string that has been converted to lowercase.

  此函數可以把所有的字元都轉換成相應的小寫。

  9,Cstr

  Returns an expression that has been converted to a Variant of subtype String.

  由於VBScript只有一種類型Variant,你可以使用此函數把某個變數強制轉換成String類型。

  10,CInt

  Returns an expression that has been converted to a Variant of subtype Integer.

  由於VBScript只有一種類型Variant,你可以使用此函數把某個變數強制轉換成Integer類型。

  在描述性編程語句中,最常用的函數有:

  11,Create

  這是建立一類或一個對象時必須要使用的方法。

  12,ChildObjects

  使用此方法可以得到符合某些條件的一類對象的集合。

  13,Count

  使用使用此方法可以得到符合某些條件的一類對象的個數。

  The following example uses the Create method to return a Properties collection object named EditDescription, and then uses the returned object to instruct QuickTest to enter the text: MyName in the first WebEdit object in the Mercury Tours page with the name UserName.

  Set EditDesc = Description.Create()

  EditDesc("micclass")。Value = "WebEdit"

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

  Set Lists = Browser("Welcome: Mercury")。Page("Welcome: Mercury")。ChildObjects(EditDesc)

  NumberOfLists = Lists.Count()

  If NumberOfLists > 0 Then

  Browser("Welcome: Mercury")。Page("Welcome: Mercury")。Lists(0)。Set "MyName"

  End If

  一些具體的用法可以在 QTP的協助裡面找到。 個人的建議是:你最好按照 QTP裡面提供的例子,自己使用這些函數自己寫幾行語句,運行後看一下運行結果,結合QTP協助裡面的說明,這樣學習會快,也記得牢固。

  在輸出結果時, 常用的函數有 Msgbox 和 Print 函數。Msgbox 函數在 QTP8.2 及其以上版本都可以使用;Print 函數需要在 QTP 9.2 版本上使用,QTP 8.2 不支援此函數,不知道 QTP 9.0是否支援此函數。

  希望大家共同總結一下,一起進步。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.