![](/img/trans.png)
[英]Selenium Web Driver - Java - TestNG - Assert.assertEquals how to compare actual result with the range between expected result
[英]Selenium web driver assert webelement contains text and display actual vs expected
我有一個演示 selenium cucumber 項目,它只是在谷歌搜索框中運行一些數學表達式並驗證結果。
我希望報告顯示實際值與失敗時的預期值。
我將返回的文本存儲為字符串...
String resultText = driver.findElement(By.cssSelector("div[class='dDoNo vrBOv vk_bk']")).getText();
然后根據預期斷言從我的功能文件中傳遞的......
assertTrue(resultText.equals(expectedResult));
但報告顯示...
java.lang.AssertionError: expected [true] but found [false]
我希望它顯示實際預期結果與實際結果
java.lang.AssertionError: expected [200] but found [201]
我也試過...
Assert.assertEquals(expectedResult, resultText);
我正在使用... org.testng.Assert
謝謝
通過斷言,您可以使用自定義的錯誤文本。 像這樣:
Assert.assertEquals(resultText, expectedResult, "Expected: " + expectedResult + " but found " + resultText);
或這個
Assert.assertTrue(expectedResult.equals(resultText), "Expected: " + expectedResult + " but found " + resultText);
在參數不相等的情況下,第一種情況會像這樣顯示 output:
java.lang.AssertionError:預期:expectedResult 但找到 resultText
預期:預期結果
實際:結果文本
對於第二種情況:
java.lang.AssertionError:預期:expectedResult 但找到 resultText
預期:真
實際:假
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.