2013-12-03 51 views
0

這對我很有幫助,如果任何人都可以提供給我一個關於以下問題的想法。 我有一個場景,我的腳本將逐行執行每個測試步驟,對於每個測試步驟,它都會在html結果頁面中報告通過和失敗結果。 如果測試步驟結果爲合格,則將繼續進行下一個測試步驟。 類似地,失敗的情況下,它進入下一個測試步驟並執行它。 當腳本失敗時可以停止腳本嗎?當它失敗時可以停止vb腳本(在QTP中)嗎?

下面是示例大綱腳本

Call webEdit_check (「google」,」google」,」nametxtbox」,」xxxx」) 

Call Link_check (strbrowser,strpage,strlink) 

Call WebButton_check (strbrowser,strpage,strWebbutton) 

所以根據上面的腳本,它會調用webEdit功能,並檢查對象是否顯示可見,並且將進入webEdit文本框,結果值將被寫入爲合格在html結果中,如果所有條件都滿足。 完成上述功能後,現在會調用鏈接函數並啓動執行,同時會檢查是否顯示對象,如果成功,將進入下一步。讓我們假設鏈接不可見,這裏這個函數的第二步失敗,所以結果寫成失敗,第三個函數的執行開始(調用WebButton_check)。我需要的是整個執行應該停止,因爲之前的測試步驟失敗了。是否有任何功能在後端運行,以停止執行?當測試步驟失敗時?有沒有解決我的問題? (請注意,我有多種方案,以便「退出測試/退出鍵功能」是不適用的。) 函數是

webEdit_check

Function webEdit_check(strbrowser,strpage,strwebEdit,strvalue) 
Testobject=Browser(strbrowser).Page(strpage).WebEdit(strlink) 
If Testobject.exist(10) Then 
blnvisible= testobject.getRoproperty(visible) 
If blnvisible =True Then 
Testobject.set strvalue 
Environment.value(result)=pass 
‘It will write result to html page 
Call html (「test step is success」,Environment(result)) 
Else 
Environment.value(result)=fail 
Call html (「test step is fail」,Environment(result)) 
End If 
Else 
Environment.value(result)=fail 
Call html (「test object is not visible fail」,Environment(result)) 
End If 
End Function 

webEdit_check

Function webEdit_check(strbrowser,strpage,strLink) 
Testobject=Browser(strbrowser).Page(strpage).Link(strlink) 
If Testobject.exist(10) Then 
blnvisible= testobject.getRoproperty(visible) 
If blnvisible =True Then 
Testobject.click 
Environment.value(result)=pass 
‘It will write result to html page 
Call html (「test step is success」,Environment(result)) 
Else 
Environment.value(result)=fail 
Call html (「test step is fail」,Environment(result)) 
End If 
Else 
Environment.value(result)=fail 
Call html (「test object is not visible fail」,Environment(result)) 
End If 
End Function 

WebButton_check

Function WebButton_check(strbrowser,strpage,strWebButton) 
Testobject=Browser(strbrowser).Page(strpage).WebButton(strWebButton) 
If Testobject.exist(10) Then 
blnvisible= testobject.getRoproperty(visible) 
If blnvisible =True Then 
Testobject.click 
Environment.value(result)=pass 
‘It will write result to html page 
Call html (「test step is success」,Environment(result)) 
Else 
Environment.value(result)=fail 
Call html (「test step is fail」,Environment(result)) 
End If 
Else 
Environment.value(result)=fail 
Call html (「test object is not visible fail」,Environment(result)) 
End If 
End Function 

(strverify,結果)

Function (strverify,Result) 
If Environment(result)=pass Then 
Td.write(<td(strverify)/>td<xxx><td(Result)/>td) 
'(please note this is sample, which I typed, it’s just for concept) 
Else 
Td.write(<td(strverify)/>td<xxx><td(Result)/>td) 
End If 
End Function 

如果可能的話,請發郵件([email protected])我的解決方案,在我的辦公室,我已經到網站以外的機會有限。我無法立即檢查。這個問題我已經被通過了20天。 感謝&方面的 Jagadeesh瑪尼 [email protected]

回答

1

可能嘗試這種

On Error Resume Next 
Call Link_check (strbrowser,strpage,strlink) 
Err.Raise 6 ' Raise an overflow error. 
MsgBox "Error # " & CStr(Err.Number) & " " & Err.Description 
Err.Clear ' Clear the error. 

在上面,如果函數Link_check導致錯誤的話,執行不會forward.If你移動想執行下一個功能使用

On Error Resume Next 
Call Link_check (strbrowser,strpage,strlink) 
Err.Raise 6 ' Raise an overflow error. 
MsgBox "Error # " & CStr(Err.Number) & " " & Err.Description 
Err.Clear ' Clear the error. 
On Error goto 0 
WebButton_check 

我希望這是你所要求的。

0

爲了使我的問題更簡單,我已經15方案的,並在執行時以下功能每個場景將每次

Call WebEdit_check (「google」,」google」,」nametxtbox」,」xxxx」)

Call Link_check (strbrowser,strpage,strlink)

Call WebButton_check (strbrowser,strpage,strWebbutton)

所以如果被執行第3種情況,下面的步驟功能失敗

Call Link_check (strbrowser,strpage,strlink) 它會在html結果文件中寫入失敗,並應停止第3個場景的執行,並應開始第4個場景的優化。這Err.Raise 6將提高用戶預定義的錯誤味精

0
for cnt i=0 to 15 
    Call WebEdit_check (「google」,」google」,」nametxtbox」,」xxxx」) 
    Error Resume Next 
    Call Link_check (strbrowser,strpage,strlink)'If the Error Occurs here then add On Error Resume Next above this statement 

    Call WebButton_check (strbrowser,strpage,strWebbutton) 

    Err.Clear 'This will clear the error.As,you want to keep this process to run for 15 times for each scenario.just add On Error goto 0 
add On Error goto 0 
Next 

這可能有助於

相關問題