Skip to content

Commit

Permalink
Fix up failing htmlunitdriver test.
Browse files Browse the repository at this point in the history
Also clean up some minor style issues flagged by IntelliJ.
  • Loading branch information
shs96c committed Sep 6, 2015
1 parent 72c7304 commit a34d7fa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void setCredentials(Credentials credentials) {
public void handleAlert(Page page, String message) {
Queue<String> queue = queues.get(page);
if (queue == null) {
queue = new LinkedList<String>();
queue = new LinkedList<>();
queues.put(page, queue);
}
queue.add(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void submit() {
submitForm((HtmlForm) element);
return;
} else if ((element instanceof HtmlSubmitInput) || (element instanceof HtmlImageInput)) {
((HtmlElement) element).click();
element.click();
return;
} else if (element instanceof HtmlInput) {
HtmlForm form = ((HtmlElement) element).getEnclosingForm();
Expand Down Expand Up @@ -263,7 +263,7 @@ public void clear() {
throw new InvalidElementStateException("You may only interact with enabled elements");
}
htmlTextArea.setText("");
} else if (element.getAttribute("contenteditable") != DomElement.ATTRIBUTE_NOT_DEFINED) {
} else if (!element.getAttribute("contenteditable").equals(DomElement.ATTRIBUTE_NOT_DEFINED)) {
element.setTextContent("");
}
}
Expand All @@ -278,7 +278,7 @@ public Boolean call() throws Exception {
}
});

if (displayed == null || !displayed.booleanValue()) {
if (displayed == null || !displayed) {
throw new ElementNotVisibleException("You may only interact with visible elements");
}

Expand All @@ -298,12 +298,12 @@ private void switchFocusToThisIfNeeded() {
if (jsEnabled &&
!oldActiveEqualsCurrent &&
!isBody) {
((HtmlElement) oldActiveElement.element).blur();
oldActiveElement.element.blur();
}
} catch (StaleElementReferenceException ex) {
// old element has gone, do nothing
}
((HtmlElement) element).focus();
element.focus();
}

void sendKeyDownEvent(CharSequence modifierKey) {
Expand Down Expand Up @@ -683,7 +683,7 @@ public WebElement findElementByCssSelector(String using) {
}

private List<WebElement> findChildNodes(List<WebElement> allElements) {
List<WebElement> toReturn = new LinkedList<WebElement>();
List<WebElement> toReturn = new LinkedList<>();

for (WebElement current : allElements) {
DomElement candidate = ((HtmlUnitWebElement) current).element;
Expand Down Expand Up @@ -766,7 +766,7 @@ public List<WebElement> findElementsByLinkText(String linkText) {
assertElementNotStale();

String expectedText = linkText.trim();
List<? extends DomElement> htmlElements = ((HtmlElement) element).getHtmlElementsByTagName("a");
List<? extends HtmlElement> htmlElements = ((HtmlElement) element).getHtmlElementsByTagName("a");
List<WebElement> webElements = new ArrayList<>();
for (DomElement e : htmlElements) {
if (expectedText.equals(e.getTextContent().trim()) && e.getAttribute("href") != null) {
Expand Down
1 change: 1 addition & 0 deletions java/client/test/org/openqa/selenium/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ java_library(name = 'tests',
'//java/client/src/org/openqa/selenium:codecs',
'//java/client/src/org/openqa/selenium:webdriver-api',
'//java/client/src/org/openqa/selenium/ie:ie',
'//java/client/src/org/openqa/selenium/htmlunit:htmlunit',
'//java/client/src/org/openqa/selenium/io:io',
'//java/client/src/org/openqa/selenium/net:net',
'//java/client/src/org/openqa/selenium/os:os',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import org.hamcrest.Matchers;
import org.junit.Test;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.internal.Locatable;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.testing.Ignore;
Expand Down Expand Up @@ -182,14 +183,14 @@ public void testChangeEventIsFiredAppropriatelyWhenFocusIsLost() {
input.sendKeys("test");
moveFocus();
assertThat(driver.findElement(By.id("result")).getText().trim(),
Matchers.<String>either(is("focus change blur")).or(is("focus blur change")));
Matchers.either(is("focus change blur")).or(is("focus blur change")));

input.sendKeys(Keys.BACK_SPACE, "t");
moveFocus();

// I weep.
assertThat(driver.findElement(By.id("result")).getText().trim(),
Matchers.<String>either(is("focus change blur focus blur"))
Matchers.either(is("focus change blur focus blur"))
.or(is("focus blur change focus blur"))
.or(is("focus blur change focus blur change"))
.or(is("focus change blur focus change blur"))); // What Chrome does
Expand All @@ -214,6 +215,9 @@ public void testShouldBeAbleToClickIfEvenSomethingHorribleHappens() {
@Test
public void testShouldBeAbleToGetTheLocationOfAnElement() {
assumeTrue(driver instanceof JavascriptExecutor);
if (driver instanceof HtmlUnitDriver) {
assumeTrue(((HtmlUnitDriver) driver).isJavascriptEnabled());
}

driver.get(pages.javascriptPage);

Expand Down

0 comments on commit a34d7fa

Please sign in to comment.