Skip to content

Commit

Permalink
Reusing existing utility method
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Apr 3, 2017
1 parent 9a7082b commit 44cb402
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 45 deletions.
8 changes: 1 addition & 7 deletions java/client/test/org/openqa/selenium/AlertsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
import static org.openqa.selenium.WaitingConditions.newWindowIsOpened;
import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;
import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;
Expand Down Expand Up @@ -516,11 +517,4 @@ private static ExpectedCondition<WebDriver> ableToSwitchToWindow(final String na
return driver -> driver.switchTo().window(name);
}

private static ExpectedCondition<String> newWindowIsOpened(final Set<String> originalHandles) {
return driver -> {
Set<String> currentWindowHandles = driver.getWindowHandles();
currentWindowHandles.removeAll(originalHandles);
return currentWindowHandles.isEmpty() ? null : currentWindowHandles.iterator().next();
};
}
}
24 changes: 7 additions & 17 deletions java/client/test/org/openqa/selenium/WaitingConditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ private WaitingConditions() {
// utility class
}

private static abstract class ElementTextComperator implements ExpectedCondition<String> {
private static abstract class ElementTextComparator implements ExpectedCondition<String> {
private String lastText = "";
private WebElement element;
private String expectedValue;
ElementTextComperator(WebElement element, String expectedValue) {

ElementTextComparator(WebElement element, String expectedValue) {
this.element = element;
this.expectedValue = expectedValue;
}
Expand All @@ -56,7 +57,7 @@ public String toString() {

public static ExpectedCondition<String> elementTextToEqual(
final WebElement element, final String value) {
return new ElementTextComperator(element, value) {
return new ElementTextComparator(element, value) {

@Override
boolean compareText(String expectedValue, String actualValue) {
Expand All @@ -67,7 +68,7 @@ boolean compareText(String expectedValue, String actualValue) {

public static ExpectedCondition<String> elementTextToContain(
final WebElement element, final String value) {
return new ElementTextComperator(element, value) {
return new ElementTextComparator(element, value) {

@Override
boolean compareText(String expectedValue, String actualValue) {
Expand Down Expand Up @@ -188,19 +189,8 @@ public Set<String> apply(WebDriver driver) {
}

public static ExpectedCondition<String> newWindowIsOpened(final Set<String> originalHandles) {
return new ExpectedCondition<String>() {

@Override
public String apply(WebDriver driver) {
Set<String> currentWindowHandles = driver.getWindowHandles();
if (currentWindowHandles.size() > originalHandles.size()) {
currentWindowHandles.removeAll(originalHandles);
return currentWindowHandles.iterator().next();
}
return null;
}
};

return driver -> driver.getWindowHandles().stream()
.filter(originalHandles::contains).findFirst().orElse(null);
}

public static ExpectedCondition<WebDriver> windowToBeSwitchedToWithName(final String windowName) {
Expand Down
27 changes: 6 additions & 21 deletions java/client/test/org/openqa/selenium/WindowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,39 +211,24 @@ private void maximize() {
private ExpectedCondition<Boolean> windowSizeEqual(final Dimension size) {
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 driver -> {
Dimension newSize = driver.manage().window().getSize();
log.info("waiting for width, Current dimensions are " + newSize);
return newSize.width != size.width;
};
return driver -> driver.manage().window().getSize().width != size.width;
}

private ExpectedCondition<Boolean> windowHeightToBeGreaterThan(final Dimension size) {
return driver -> {
Dimension newSize = driver.manage().window().getSize();
log.info("waiting for height, Current dimensions are " + newSize);
return newSize.height != size.height;
};
return driver -> driver.manage().window().getSize().height != size.height;
}

private ExpectedCondition<Boolean> xEqual(final Point targetPosition) {
return driver -> {
Point newPosition = driver.manage().window().getPosition();
return newPosition.x == targetPosition.x;
};
return driver -> driver.manage().window().getPosition().x == targetPosition.x;
}

private ExpectedCondition<Boolean> yEqual(final Point targetPosition) {
return driver -> {
Point newPosition = driver.manage().window().getPosition();
return newPosition.y == targetPosition.y;
};
return driver -> driver.manage().window().getPosition().y == targetPosition.y;
}

private void assumeNotLinuxAtSauce() {
Expand Down

0 comments on commit 44cb402

Please sign in to comment.