assetEquals期望没有返回但.getText返回新行。我怎样才能使.getText()不返回新行?我累了:
assertEquals("first last\n address 1\n state zip\n Country\n email@email.com\n +353 3456546", driver.findElement(By.xpath("//form[@id='mainForm']/div[2]/div")).replaceAll("\n", ""));
但这似乎不起作用。
try {
assertEquals("first last\n address 1\n state zip\n Country\n email@email.com\n +353 3456546", driver.findElement(By.xpath("//form[@id='mainForm']/div[2]/div")).getText());
//
} catch (Error e) {
verificationErrors.append(e.toString());
//e.printStackTrace();
}
java.lang.AssertionError: java.lang.AssertionError: Expected "first last address 1 state zip country email@email.com +353 3456546" but saw "first last
address 1
state zip
country
email@email.com
+353 3456546" instead
有人对如何解决此问题有任何建议吗?
答案 0 :(得分:0)
replace("\n", "");
怎么样? replaceAll
采用正则表达式,\n
是String
字面值,而不是正则表达式。