public class openbowser {
public WebDriver driver= null;
String browser="mozilla";
String url="https://www.google.com";
String actualTitle = driver.getTitle();
String expectedTitle = "googleInd";
assert.assertTrue(actualTitle,expectedTitle);
Reporter.log("Application Launched successfully ");
}
当我运行测试时,它会失败并显示以下错误:
java.lang.AssertionError: expected [googleInd] but found [Google]
有什么方法可以修改断言吗?它应该用更简单的英语提及细节。
示例:
java.lang.AssertionError: Expected title "googleInd" but found "Google"
答案 0 :(得分:0)
您可以使用assertEquals(String actual, String expected, String message)
assert.assertEquals(actualTitle, expectedTitle, "Expected title '" + expectedTitle + "' but found '" + actualTitle + "'");
答案 1 :(得分:0)
你快到了。如果您查看 assertTrue 的签名,则定义为:
void org.testng.Assert.assertTrue(boolean condition)
Asserts that a condition is true. If it isn't, an AssertionError is thrown.
Parameters:
condition the condition to evaluate
因此,当我们调用 assertTrue 时,我们必须将输入参数保持为 boolean 。要实现这一点,而不是传递两个String
文字,如下所示:
assert.assertTrue(actualTitle,expectedTitle);
我们将传递布尔参数,如下所示:
public WebDriver driver= null;
String browser="mozilla";
String url="https://www.google.com";
String actualTitle = driver.getTitle();
String expectedTitle = "googleInd";
Assert.assertTrue(expectedTitle.contains(actualTitle), "Expected title " + expectedTitle +" but found "+ actualTitle);
Reporter.log("Application Launched successfully ");