Skip to content

Commit e88f35a

Browse files
committed
AbstractPage(getElement): extract method and reduce code duplication.
No functional changes.
1 parent a731fe1 commit e88f35a

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

src/test/java/ru/mystamps/web/tests/page/AbstractPage.java

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -199,45 +199,28 @@ protected String getTextOfElementByTagName(final String tagName) {
199199
//
200200

201201
protected boolean elementWithIdExists(final String elementId) {
202-
WebElement el = null;
203-
204-
try {
205-
el = getElementById(elementId);
206-
} catch (final NoSuchElementException ex) {
207-
return false;
208-
}
209-
210-
return el != null;
202+
return getElement(By.id(elementId)) != null;
211203
}
212204

213205
protected boolean elementWithXPathExists(final String xpath) {
214-
WebElement el = null;
215-
216-
try {
217-
el = getElementByXPath(xpath);
218-
} catch (final NoSuchElementException ex) {
219-
return false;
220-
}
221-
222-
return el != null;
206+
return getElement(By.xpath(xpath)) != null;
223207
}
224208

225209
protected boolean elementWithTagNameExists(final String tagName) {
226-
WebElement el = null;
227-
210+
return getElement(By.tagName(tagName)) != null;
211+
}
212+
213+
protected WebElement getLinkByText(final String linkText) {
228214
try {
229-
el = getElementByTagName(tagName);
215+
return driver.findElement(By.linkText(linkText));
230216
} catch (final NoSuchElementException ex) {
231-
return false;
217+
return null;
232218
}
233-
234-
return el != null;
235219
}
236220

237-
protected WebElement getLinkByText(final String linkText) {
221+
private WebElement getElement(By byMethod) {
238222
try {
239-
return driver.findElement(By.linkText(linkText));
240-
223+
return driver.findElement(byMethod);
241224
} catch (final NoSuchElementException ex) {
242225
return null;
243226
}

0 commit comments

Comments
 (0)