【发布时间】:2015-08-24 16:42:01
【问题描述】:
我必须检查是否所有网页元素都显示在网页上。如果未显示,则写入日志,准确记录遗漏了哪个元素。
编写简单的测试并不难:
public boolean allUIElementsExist() {
boolean allPresent = true;
if (!this.tipFrequency.isDisplayed()) {
allPresent = false;
Logger.logFail("no tip `should be the same as how often you get paid`");
}
if (!this.tipAmount.isDisplayed()) {
allPresent = false;
Logger.logFail("no tip 'Borrow equal to the amount of your purchase'");
}
if (!this.payBack.isDisplayed()) {
allPresent = false;
Logger.logFail("no 'Pay it back in'");
}
if (!this.useTool.isDisplayed()) {
allPresent = false;
Logger.logFail("no 'Use our easy finance tool to quickly explore payment options'");
}
if (!this.biWeekly.isDisplayed()) {
allPresent = false;
Logger.logFail("no 'biWeekly'");
}
if (!this.semiMonthly.isDisplayed()) {
allPresent = false;
Logger.logFail("no 'semi-monthly (twice a month)'");
}
if (!this.month.isDisplayed()) {
allPresent = false;
Logger.logFail("no 'monthly'");
}
if (!this.withPayments.isDisplayed()) {
allPresent = false;
Logger.logFail("no 'With payments of:'");
}
if (!this.includingLPP.isDisplayed()) {
allPresent = false;
Logger.logFail("no 'including LPP'");
}
if (!this.startNewApplication.isDisplayed()) {
allPresent = false;
Logger.logFail("no 'Start new application'");
}
if (!this.easyfinancialLink.visibilityOfElementWait()) {
allPresent = false;
Logger.logFail("no 'easyfinancialLink'");
}
return allPresent;
}
它有效。但是遍历所有if 语句看起来并不是最好的解决方案。
如何重新创建此代码以获得更好的方法?
【问题讨论】:
-
那是什么语言?
-
@RobertMoskal 它是java。我添加了适当的标签。
-
什么是tipFrequency等会员?他们是你的班吗?
-
@RobertMoskal 所有这些成员都是网页的元素。
标签: java selenium-webdriver webpage