源代碼:
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來實現:
