Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Apr 3, 2017
1 parent fd3a074 commit 313e79d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 71 deletions.
32 changes: 7 additions & 25 deletions java/client/test/org/openqa/selenium/AlertsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,40 +505,22 @@ public void testCanQuitWhenAnAlertIsPresent() {

private static ExpectedCondition<Boolean> textInElementLocated(
final By locator, final String text) {
return new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
return text.equals(driver.findElement(locator).getText());
}
};
return driver -> text.equals(driver.findElement(locator).getText());
}

private static ExpectedCondition<Boolean> windowCountIs(final int count) {
return new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
return driver.getWindowHandles().size() == count;
}
};
return driver -> driver.getWindowHandles().size() == count;
}

private static ExpectedCondition<WebDriver> ableToSwitchToWindow(final String name) {
return new ExpectedCondition<WebDriver>() {
@Override
public WebDriver apply(WebDriver driver) {
return driver.switchTo().window(name);
}
};
return driver -> driver.switchTo().window(name);
}

private static ExpectedCondition<String> newWindowIsOpened(final Set<String> originalHandles) {
return new ExpectedCondition<String>() {
@Override
public String apply(WebDriver driver) {
Set<String> currentWindowHandles = driver.getWindowHandles();
currentWindowHandles.removeAll(originalHandles);
return currentWindowHandles.isEmpty() ? null : currentWindowHandles.iterator().next();
}
return driver -> {
Set<String> currentWindowHandles = driver.getWindowHandles();
currentWindowHandles.removeAll(originalHandles);
return currentWindowHandles.isEmpty() ? null : currentWindowHandles.iterator().next();
};
}
}
64 changes: 18 additions & 46 deletions java/client/test/org/openqa/selenium/WindowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,68 +209,40 @@ private void maximize() {
}

private ExpectedCondition<Boolean> windowSizeEqual(final Dimension size) {
return new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
Dimension newSize = driver.manage().window().getSize();
return driver -> {
Dimension newSize = driver.manage().window().getSize();

return newSize.height == size.height &&
newSize.width == size.width;
}
return newSize.height == size.height &&
newSize.width == size.width;
};
}

private ExpectedCondition<Boolean> windowWidthToBeGreaterThan(final Dimension size) {
return new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
Dimension newSize = driver.manage().window().getSize();
log.info("waiting for width, Current dimensions are " + newSize);
if(newSize.width != size.width) {
return true;
}

return null;
}
return driver -> {
Dimension newSize = driver.manage().window().getSize();
log.info("waiting for width, Current dimensions are " + newSize);
return newSize.width != size.width;
};
}

private ExpectedCondition<Boolean> windowHeightToBeGreaterThan(final Dimension size) {
return new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
Dimension newSize = driver.manage().window().getSize();
log.info("waiting for height, Current dimensions are " + newSize);
if(newSize.height != size.height) {
return true;
}

return null;
}
return driver -> {
Dimension newSize = driver.manage().window().getSize();
log.info("waiting for height, Current dimensions are " + newSize);
return newSize.height != size.height;
};
}
private ExpectedCondition<Boolean> xEqual(final Point targetPosition) {
return new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
Point newPosition = driver.manage().window().getPosition();
if(newPosition.x == targetPosition.x) {
return true;
}

return null;
}
return driver -> {
Point newPosition = driver.manage().window().getPosition();
return newPosition.x == targetPosition.x;
};
}

private ExpectedCondition<Boolean> yEqual(final Point targetPosition) {
return new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
Point newPosition = driver.manage().window().getPosition();
if(newPosition.y == targetPosition.y) {
return true;
}

return null;
}
return driver -> {
Point newPosition = driver.manage().window().getPosition();
return newPosition.y == targetPosition.y;
};
}

Expand Down

0 comments on commit 313e79d

Please sign in to comment.