java.lang.AssertionError:比较预期的错误消息

时间:2019-12-16 11:20:27

标签: selenium cucumber testng

实际值和预期值仍然相同,为什么我会得到断言错误?

Utility.java

public  String getValue(String filename, String key) throws IOException {
    FileInputStream fis = new FileInputStream(".\\testdata\\" + filename + ".properties");
    Properties p = new Properties();
    p.load(fis);
    String value = p.getProperty(key);
    return value;   
}

errormessage.properties文件

  

错误消息:×\ n错误消息\ n用户名字段为必填项。 \ n密码为必填字段。

步骤定义代码

@And("^User should get errormessage$")
public void user_should_get_error_message() throws Throwable {
    this.errormessage=this.utility.getValue("errormessage", "errormessage");
    Assert.assertEquals(this.errormessage,this.login.getError(), "Comparing error message");
}

错误:

java.lang.AssertionError: Comparing error message expected [×
Error message
Username field is required.
Password field is required.] but found [× 
Error message 
Username field is required. 
Password field is required.]
    at org.testng.Assert.fail(Assert.java:94)
    at org.testng.Assert.failNotEquals(Assert.java:513)
    at org.testng.Assert.assertEqualsImpl(Assert.java:135)
    at org.testng.Assert.assertEquals(Assert.java:116)
    at org.testng.Assert.assertEquals(Assert.java:190)
    at com.nuance.NHDP.tests.stepdefinitions.nhdplogin.nhdplogin.user_should_get_error_message(nhdplogin.java:105)
    at ?.And User should get errormessage(src/main/resources/features/smoke/clu_reports_administration/clulogin.feature:19)

1 个答案:

答案 0 :(得分:0)

第二个(找到的)文本在“用户名字段是必填项。”之后的 *多余的空格

×
Error message
Username field is required.
Password field is required.

vs

× 
Error message 
Username field is required. 
Password field is required.