源代码:
public boolean verifyText(String elementName, String expectedText) {
String actualText = getValue(elementName);
if (actualText.equalsIgnoreCase(expectedText)) {
passed("Verify text on " + " " + elementName + " with text"
+ expectedText + "", "Text" + expectedText
+ " should be verified", "verified successfully");
return true;
}
failed("Verify text on " + " " + elementName + " with text"
+ expectedText + "", "Text" + expectedText
+ " should be verified", "verified unsuccessfully");
return false;
}
1. 对于页面上面的元素,我们给一个别名elementName;
2. 这个元素的期待值,或者说期待输出为expectedText;
3. 元素获取之后,实际的输出为actualText;
Selenium 帮助我们做了什么? 这里的Selenium在String actualText = getValue(elementName); 这句话中涉及的getValue方法,其实可以通过下面selenium的自带方法getAttribute来实现: