簡體   English   中英

QTP可重復使用的同步功能

[英]qtp reuseable sync function

我正在學習QTP。 我遇到的一個問題是網頁同步問題。 我確實知道如何使用wait()序列以及Browser(“ Google”)。Page(“ Google”)。Sync。

但是必須有更好的方法來與頁面同步。 我希望QTP同時等待,我希望腳本在找到對象后立即繼續。 我不想更改QTP設置,因為它會減慢腳本速度。

你們能給我一個示例函數,最好使用for循環,這樣我每次需要驗證檢查點時就可以調用該函數。

提前致謝

result = Browser("Google").Page("Google").Exist(20)

要么

result = Browser("Google").Page("Google").WebElement("xyz").Exist(20)

這將等待20秒鍾,直到該頁面或第二種情況下存在一個Web元素。 一旦找到對象或超時,腳本將繼續。

結果將包含truefalse具體取決於對象是否存在

請注意,您可以在“測試設置”中找到的對象同步超時將添加到.Exist(seconds)超時中,除非您使用不帶以下參數的.Exist()

' Quick check-and-continue to see if an object does not exist:

' We expect the page to be existing, wait for it at least 10 second:
if Browser("Google").Page("Google").Exist(20) then
    ' Do a quick check that the warning div does not exist, note the parameter
    ' less usage of Exist()
    if Browser("Google").Page("Google").WebElement("html id:=warningContainer").Exist() Then
        MsgBox "There was a warning on the page!"
    else
        MsgBox "Everything is fine!"
    end if
else
    MsgBox "The page did not exist!"
end if

編輯:

您可以循環使用Exist

' Never ending loop until found:
Do Until Browser("Google").Page("Google").WebElement("xyz").Exist()
    wait 1
Loop

' Or a loop with a timeout
timeout = 20
Do until (timeout = 0 OR Browser("Google").Page("Google").WebElement("xyz").Exist()
    wait 1
    timeout = timeout - 1
Next

我已經故意實現了wait 1 您可以不這樣做,但是以我的經驗,它可能會產生不必要的隨機副作用,例如永遠不會加載的瀏覽器頁面導致測試失敗。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM