QTP使用运行时对象的if语句

时间:2014-11-12 20:58:02

标签: if-statement qtp hp-uft

如何设置if语句,以便QTP在满足条件时显示Passed或Failed。目前我拥有有效优惠券和无效优惠券的属性。每个人都会在网站上显示不同的消息。请参阅以下代码:

Set objBrowser = Browser("name:=.*Chico's")
Set objPage = objBrowser.Page("title:=.*Chico's")

Dim x
x=datatable.GetSheet("Global").GetRowCount

'-----for loop---------
For i = 1 To x Step 1

Datatable.SetCurrentRow(i)

objPage.WebEdit("html tag:=INPUT","html id:=claimCodeField","name:=claimCodeField").Set datatable ("Coupon_code", GlobalSheet)
wait 2
objPage.Image("name:=CouponFormHandler","html tag:=INPUT","image type:=Image Button","file name:=btn_apply\.gif").Click                                                        
wait 2

objBrowser.Sync

Dim Coupon, Couponerror

    xlCoupondescription=dataTable ("Coupon_description", GlobalSheet)

    xlInvalid=dataTable("Invalid_coupon", GlobalSheet)

'----Coupon----

    Coupon=objPage.WebElement("class:=sb-promo-msg","html tag:=SPAN","html id:=","Index:=1").GetROProperty("outertext") 

'----Coupon Error msg-----  
    Couponerror=objPage.WebElement("class:=sb-error-message","html tag:=DIV","html id:=").GetROProperty("outertext")


'----if statement---------


    If (Trim(Coupon) = Trim(xlCoupondescription))  Then

            datatable.value("Actual_results", GlobalSheet)="Passed"

        If (Trim(Coupon) = Trim(Couponerror)) Then

        datatable.value("Actual_results", GlobalSheet)="Failed"
        End If 
        End If

1 个答案:

答案 0 :(得分:2)

如果要报告自定义通过/失败条件,请使用Reporter.ReportEvent方法。