我正在用Selenium WebDrvier编写测试脚本。我有成功/失败消息的问题。这是代码的一部分,我大喊大叫。我不知道我犯了什么错误,所以如果有人可以帮助我,我会很感激。
WebElement msg=driver.findElement(By.xpath("/html/body/div[4]/div/div[1]/div/p"));
String text=msg.getText();
Object expectedText;
Asserts.assertEquals(text,expectedText);
答案 0 :(得分:1)
WebElement msg=driver.findElement(By.xpath("/html/body/div[4]/div/div[1]/div/p"));
// Get the text value of an element
String actualTxt = msg.getText();
// Expected [instead of Object expectedText ==> String expected]
String expecteTxt = "";
// Assertion (String, String)
Asserts.assertEquals(actualTxt,expectedTxt);
答案 1 :(得分:0)
如果您想 Assert 两个 String 值,请尝试断言:
void org.testng.Assert.assertEquals(String actual, String expected)
定义:
void org.testng.Assert.assertEquals(String actual, String expected)
Asserts that two Strings are equal. If they are not, an AssertionError is thrown.
Parameters:
actual the actual value
expected the expected value
您的代码将是:
import org.testng.Assert;
WebElement msg = driver.findElement(By.xpath("/html/body/div[4]/div/div[1]/div/p"));
String text = msg.getText();
Asserts.assertEquals(text,expectedText);