Selenium 自動化測試中對頁面元素的value比較驗證 java語言


源代碼:

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

String org. openqa. selenium. WebElement. getAttribute( String arg0)
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM