Skip to content

Commit 71fb31f

Browse files
asashourlukeis
authored andcommitted
HtmlUnitDriver: add .getBrowserVersion()
.getBrowserVersion() is helpful to know what is the currently simulated browser. This commit also changes TestUtilities.isFirefox() , .isInternetExplorer() and .isChrome() to return true if the underlying HtmlUnit BrowserVersion is FF/IE/Chrome. Signed-off-by: Luke Inman-Semerau <[email protected]>
1 parent 788f40c commit 71fb31f

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

Diff for: java/client/src/org/openqa/selenium/htmlunit/HtmlUnitDriver.java

+8
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ private WebClient createWebClient(BrowserVersion version) {
324324
return modifyWebClient(client);
325325
}
326326

327+
/**
328+
* Get the simulated {@code BrowserVersion}.
329+
* @return the used {@code BrowserVersion}
330+
*/
331+
public BrowserVersion getBrowserVersion() {
332+
return webClient.getBrowserVersion();
333+
}
334+
327335
/**
328336
* Create the underlying WebClient, but don't set any fields on it.
329337
*

Diff for: java/client/test/org/openqa/selenium/SvgDocumentTest.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,23 @@
1717

1818
package org.openqa.selenium;
1919

20-
import org.junit.Test;
21-
import org.openqa.selenium.testing.Ignore;
22-
import org.openqa.selenium.testing.JUnit4TestBase;
23-
import org.openqa.selenium.testing.NotYetImplemented;
24-
2520
import static org.junit.Assert.assertEquals;
2621
import static org.junit.Assume.assumeFalse;
2722
import static org.openqa.selenium.testing.Ignore.Driver.CHROME;
28-
import static org.openqa.selenium.testing.Ignore.Driver.HTMLUNIT;
2923
import static org.openqa.selenium.testing.Ignore.Driver.SAFARI;
3024
import static org.openqa.selenium.testing.TestUtilities.getFirefoxVersion;
3125
import static org.openqa.selenium.testing.TestUtilities.isFirefox;
3226
import static org.openqa.selenium.testing.TestUtilities.isOldIe;
3327

28+
import org.junit.Test;
29+
import org.openqa.selenium.testing.Ignore;
30+
import org.openqa.selenium.testing.JUnit4TestBase;
31+
3432
@Ignore(value = SAFARI,
3533
reason = "Safari: SafariDriver cannot manipulate SVG documents")
3634
public class SvgDocumentTest extends JUnit4TestBase {
3735

3836
@Test
39-
@NotYetImplemented(HTMLUNIT)
4037
@Ignore(value = CHROME, reason = "chromedriver needs to update atoms for latest SVG support")
4138
public void testClickOnSvgElement() {
4239
assumeFalse("IE version < 9 doesn't support SVG", isOldIe(driver));
@@ -51,7 +48,6 @@ public void testClickOnSvgElement() {
5148
}
5249

5350
@Test
54-
@NotYetImplemented(HTMLUNIT)
5551
public void testExecuteScriptInSvgDocument() {
5652
assumeFalse("IE version < 9 doesn't support SVG", isOldIe(driver));
5753

Diff for: java/client/test/org/openqa/selenium/WindowSwitchingTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static org.openqa.selenium.WaitingConditions.windowHandleCountToBe;
3030
import static org.openqa.selenium.WaitingConditions.windowHandleCountToBeGreaterThan;
3131
import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;
32+
import static org.openqa.selenium.testing.Ignore.Driver.HTMLUNIT;
3233
import static org.openqa.selenium.testing.Ignore.Driver.IE;
3334
import static org.openqa.selenium.testing.Ignore.Driver.MARIONETTE;
3435
import static org.openqa.selenium.testing.Ignore.Driver.REMOTE;
@@ -40,6 +41,7 @@
4041
import org.openqa.selenium.testing.Ignore;
4142
import org.openqa.selenium.testing.JUnit4TestBase;
4243
import org.openqa.selenium.testing.JavascriptEnabled;
44+
import org.openqa.selenium.testing.NotYetImplemented;
4345
import org.openqa.selenium.testing.TestUtilities;
4446
import org.openqa.selenium.testing.drivers.Browser;
4547

@@ -201,6 +203,7 @@ public void testShouldBeAbleToIterateOverAllOpenWindows() {
201203
@JavascriptEnabled
202204
@Test
203205
@Ignore(MARIONETTE)
206+
@NotYetImplemented(HTMLUNIT)
204207
public void testClickingOnAButtonThatClosesAnOpenWindowDoesNotCauseTheBrowserToHang()
205208
throws Exception {
206209
assumeFalse(Browser.detect() == Browser.opera &&
@@ -241,6 +244,7 @@ public void testClickingOnAButtonThatClosesAnOpenWindowDoesNotCauseTheBrowserToH
241244
@JavascriptEnabled
242245
@Test
243246
@Ignore(MARIONETTE)
247+
@NotYetImplemented(HTMLUNIT)
244248
public void testCanCallGetWindowHandlesAfterClosingAWindow() throws Exception {
245249
assumeFalse(Browser.detect() == Browser.opera &&
246250
TestUtilities.getEffectivePlatform().is(Platform.WINDOWS));

Diff for: java/client/test/org/openqa/selenium/testing/TestUtilities.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public static boolean isNativeEventsEnabled(WebDriver driver) {
3838
}
3939

4040
public static String getUserAgent(WebDriver driver) {
41+
if (driver instanceof HtmlUnitDriver) {
42+
return ((HtmlUnitDriver) driver).getBrowserVersion().getUserAgent();
43+
}
4144
try {
4245
return (String) ((JavascriptExecutor) driver).executeScript(
4346
"return navigator.userAgent;");
@@ -52,14 +55,12 @@ public static String getUserAgent(WebDriver driver) {
5255
}
5356

5457
public static boolean isFirefox(WebDriver driver) {
55-
return !(driver instanceof HtmlUnitDriver)
56-
&& getUserAgent(driver).contains("Firefox");
58+
return getUserAgent(driver).contains("Firefox");
5759
}
5860

5961
public static boolean isInternetExplorer(WebDriver driver) {
6062
String userAgent = getUserAgent(driver);
61-
return !(driver instanceof HtmlUnitDriver)
62-
&& (userAgent.contains("MSIE") || userAgent.contains("Trident"));
63+
return userAgent.contains("MSIE") || userAgent.contains("Trident");
6364
}
6465

6566
public static boolean isIe6(WebDriver driver) {
@@ -76,6 +77,10 @@ public static boolean isOldIe(WebDriver driver) {
7677
if (!isInternetExplorer(driver)) {
7778
return false;
7879
}
80+
if (driver instanceof HtmlUnitDriver) {
81+
String applicationVersion = ((HtmlUnitDriver) driver).getBrowserVersion().getApplicationVersion();
82+
return Double.parseDouble(applicationVersion.split(" ")[0]) < 5;
83+
}
7984
try {
8085
String jsToExecute = "return parseInt(window.navigator.appVersion.split(' ')[0]);";
8186
// IE9 is trident version 5. IE9 is the start of new IE.
@@ -101,8 +106,7 @@ public static boolean isFirefox9(WebDriver driver) {
101106
}
102107

103108
public static boolean isChrome(WebDriver driver) {
104-
return !(driver instanceof HtmlUnitDriver)
105-
&& getUserAgent(driver).contains("Chrome");
109+
return getUserAgent(driver).contains("Chrome");
106110
}
107111

108112
public static boolean isOldChromedriver(WebDriver driver) {

0 commit comments

Comments
 (0)