我正在为不同的产品创建自动化产品购买流程。在订单确认页面上,我正在验证税价和运费是否设置为0。
这是我的代码:
String expectedshippingprice = "$0.00";
String actualshipingprice = driver.findElement(By.xpath("html/body/div[1]/div[6]/div[1]/div/fieldset/div[2]/div[2]")).getText();
Assert.assertEquals("Verify Shipping Price", expectedshippingprice, actualshipingprice);
但我收到错误:
java.lang.AssertionError:$ 0.00预期[$ 0.00]但找到[验证 价]
以下是HTML代码:
<div class="row">
<div class="col-sm-8 col-md-8 col-xs-8 col-lg-8">Product Price</div>
<div class="col-xs-4 col-lg-4 col-md-4 col-sm-4">$19.95</div>
</div>
<div class="row">
<div class="col-sm-6 col-md-4 col-xs-8 col-lg-8">Shipping</div>
<div class="col-xs-4 col-lg-4 col-md-4 col-sm-4">$0.00</div>
</div>
<div class="row">
<div class="col-sm-6 col-md-4 col-xs-8 col-lg-8">Tax</div>
<div class="col-xs-4 col-lg-4 col-md-4 col-sm-4">$0.00</div>
</div>
&#13;
请帮忙!
答案 0 :(得分:1)
如果您正确导入org.junit.Assert
(而非其他Assert
),则功能
Assert.assertEquals(message, expected, actual);
将返回AssertionException,如下所示:
java.lang.AssertionError: <message> expected [<expected>] but found [<actual>]
因此,基于您的例外情况(java.lang.AssertionError: $0.00 expected [$0.00] but found [Verify Price].
),我可以得出结论,您这样称为assertEquals
:
Assert.assertEquals(expectedshippingprice, actualshipingprice, "Verify Price");
虽然你的问题显示正确的方法。因此,只需更改参数的顺序,就像您当前显示的问题一样:
Assert.assertEquals("Verify Shipping Price", expectedshippingprice, actualshipingprice);