Skip to content

Commit a34d7fa

Browse files
committed
Fix up failing htmlunitdriver test.
Also clean up some minor style issues flagged by IntelliJ.
1 parent 72c7304 commit a34d7fa

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

java/client/src/org/openqa/selenium/htmlunit/HtmlUnitAlert.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void setCredentials(Credentials credentials) {
8282
public void handleAlert(Page page, String message) {
8383
Queue<String> queue = queues.get(page);
8484
if (queue == null) {
85-
queue = new LinkedList<String>();
85+
queue = new LinkedList<>();
8686
queues.put(page, queue);
8787
}
8888
queue.add(message);

java/client/src/org/openqa/selenium/htmlunit/HtmlUnitWebElement.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void submit() {
167167
submitForm((HtmlForm) element);
168168
return;
169169
} else if ((element instanceof HtmlSubmitInput) || (element instanceof HtmlImageInput)) {
170-
((HtmlElement) element).click();
170+
element.click();
171171
return;
172172
} else if (element instanceof HtmlInput) {
173173
HtmlForm form = ((HtmlElement) element).getEnclosingForm();
@@ -263,7 +263,7 @@ public void clear() {
263263
throw new InvalidElementStateException("You may only interact with enabled elements");
264264
}
265265
htmlTextArea.setText("");
266-
} else if (element.getAttribute("contenteditable") != DomElement.ATTRIBUTE_NOT_DEFINED) {
266+
} else if (!element.getAttribute("contenteditable").equals(DomElement.ATTRIBUTE_NOT_DEFINED)) {
267267
element.setTextContent("");
268268
}
269269
}
@@ -278,7 +278,7 @@ public Boolean call() throws Exception {
278278
}
279279
});
280280

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

@@ -298,12 +298,12 @@ private void switchFocusToThisIfNeeded() {
298298
if (jsEnabled &&
299299
!oldActiveEqualsCurrent &&
300300
!isBody) {
301-
((HtmlElement) oldActiveElement.element).blur();
301+
oldActiveElement.element.blur();
302302
}
303303
} catch (StaleElementReferenceException ex) {
304304
// old element has gone, do nothing
305305
}
306-
((HtmlElement) element).focus();
306+
element.focus();
307307
}
308308

309309
void sendKeyDownEvent(CharSequence modifierKey) {
@@ -683,7 +683,7 @@ public WebElement findElementByCssSelector(String using) {
683683
}
684684

685685
private List<WebElement> findChildNodes(List<WebElement> allElements) {
686-
List<WebElement> toReturn = new LinkedList<WebElement>();
686+
List<WebElement> toReturn = new LinkedList<>();
687687

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

768768
String expectedText = linkText.trim();
769-
List<? extends DomElement> htmlElements = ((HtmlElement) element).getHtmlElementsByTagName("a");
769+
List<? extends HtmlElement> htmlElements = ((HtmlElement) element).getHtmlElementsByTagName("a");
770770
List<WebElement> webElements = new ArrayList<>();
771771
for (DomElement e : htmlElements) {
772772
if (expectedText.equals(e.getTextContent().trim()) && e.getAttribute("href") != null) {

java/client/test/org/openqa/selenium/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ java_library(name = 'tests',
8888
'//java/client/src/org/openqa/selenium:codecs',
8989
'//java/client/src/org/openqa/selenium:webdriver-api',
9090
'//java/client/src/org/openqa/selenium/ie:ie',
91+
'//java/client/src/org/openqa/selenium/htmlunit:htmlunit',
9192
'//java/client/src/org/openqa/selenium/io:io',
9293
'//java/client/src/org/openqa/selenium/net:net',
9394
'//java/client/src/org/openqa/selenium/os:os',

java/client/test/org/openqa/selenium/JavascriptEnabledDriverTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import org.hamcrest.Matchers;
3535
import org.junit.Test;
36+
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
3637
import org.openqa.selenium.internal.Locatable;
3738
import org.openqa.selenium.support.ui.ExpectedConditions;
3839
import org.openqa.selenium.testing.Ignore;
@@ -182,14 +183,14 @@ public void testChangeEventIsFiredAppropriatelyWhenFocusIsLost() {
182183
input.sendKeys("test");
183184
moveFocus();
184185
assertThat(driver.findElement(By.id("result")).getText().trim(),
185-
Matchers.<String>either(is("focus change blur")).or(is("focus blur change")));
186+
Matchers.either(is("focus change blur")).or(is("focus blur change")));
186187

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

190191
// I weep.
191192
assertThat(driver.findElement(By.id("result")).getText().trim(),
192-
Matchers.<String>either(is("focus change blur focus blur"))
193+
Matchers.either(is("focus change blur focus blur"))
193194
.or(is("focus blur change focus blur"))
194195
.or(is("focus blur change focus blur change"))
195196
.or(is("focus change blur focus change blur"))); // What Chrome does
@@ -214,6 +215,9 @@ public void testShouldBeAbleToClickIfEvenSomethingHorribleHappens() {
214215
@Test
215216
public void testShouldBeAbleToGetTheLocationOfAnElement() {
216217
assumeTrue(driver instanceof JavascriptExecutor);
218+
if (driver instanceof HtmlUnitDriver) {
219+
assumeTrue(((HtmlUnitDriver) driver).isJavascriptEnabled());
220+
}
217221

218222
driver.get(pages.javascriptPage);
219223

0 commit comments

Comments
 (0)