Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit 54dae8b

Browse files
committed
Added HTMLUnit support back
Fixes #79 Prevented running 'Run Keyword on failure' again, if given keyword fails
1 parent 831945f commit 54dae8b

File tree

8 files changed

+36
-4
lines changed

8 files changed

+36
-4
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ env:
88
- PROFILE=build,firefox
99
- PROFILE=build,googlechromeheadless
1010
- PROFILE=build,firefoxheadless
11+
- PROFILE=build,htmlunitwithjs
1112

1213
stages:
1314
- test

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@
129129
<artifactId>jbrowserdriver</artifactId>
130130
<version>1.0.1</version>
131131
</dependency>
132+
<dependency>
133+
<groupId>org.seleniumhq.selenium</groupId>
134+
<artifactId>htmlunit-driver</artifactId>
135+
<version>2.35.1</version>
136+
</dependency>
132137
<dependency>
133138
<groupId>org.mockito</groupId>
134139
<artifactId>mockito-core</artifactId>
@@ -361,6 +366,13 @@
361366
</plugins>
362367
</build>
363368
</profile>
369+
<profile>
370+
<id>htmlunitwithjs</id>
371+
<properties>
372+
<browser>htmlunitwithjs</browser>
373+
<downloadWebDriver>False</downloadWebDriver>
374+
</properties>
375+
</profile>
364376
<profile>
365377
<id>firefox</id>
366378
<properties>

src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/BrowserManagement.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.openqa.selenium.firefox.FirefoxDriver;
3939
import org.openqa.selenium.firefox.FirefoxOptions;
4040
import org.openqa.selenium.firefox.FirefoxProfile;
41+
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
4142
import org.openqa.selenium.ie.InternetExplorerDriver;
4243
import org.openqa.selenium.ie.InternetExplorerOptions;
4344
import org.openqa.selenium.opera.OperaDriver;
@@ -168,7 +169,9 @@ public void closeBrowser() {
168169
"| Opera | opera |\r\n" +
169170
"| Android | android |\r\n" +
170171
"| Iphone | iphone |\r\n" +
171-
"| JBrowser | jbrowser |\r\n" +
172+
"| JBrowser | jbrowser |\r\n" +
173+
"| HTMLUnit | htmlunit |\r\n" +
174+
"| HTMLUnit with Javascript | htmlunitwithjs |\r\n" +
172175
"\r\n" +
173176
"To be able to actually use one of these browsers, you need to have a matching Selenium browser driver available. See the [https://github.com/Hi-Fi/robotframework-seleniumlibrary-java#browser-drivers|project documentation] for more details.\r\n" +
174177
"\r\n" +
@@ -677,6 +680,12 @@ protected WebDriver createLocalWebDriver(String browserName, Capabilities desire
677680
} catch (Exception e) {
678681
throw new SeleniumLibraryFatalException("Creating " + browserName + " instance failed.", e);
679682
}
683+
case "htmlunit":
684+
return new HtmlUnitDriver(desiredCapabilities);
685+
case "htmlunitwithjs":
686+
HtmlUnitDriver driver = new HtmlUnitDriver(desiredCapabilities);
687+
driver.setJavascriptEnabled(true);
688+
return driver;
680689
default:
681690
throw new SeleniumLibraryFatalException(browserName + " is not a supported browser.");
682691
}
@@ -769,6 +778,11 @@ protected Capabilities createCapabilities(String browserName, String desiredCapa
769778
case "jbrowser":
770779
desiredCapabilities = new DesiredCapabilities("jbrowser", "1", Platform.ANY);
771780
break;
781+
case "htmlunit":
782+
case "htmlunitwithjs":
783+
desiredCapabilities = DesiredCapabilities.htmlUnit();
784+
((DesiredCapabilities) desiredCapabilities).setBrowserName("htmlunit");
785+
break;
772786
default:
773787
throw new SeleniumLibraryFatalException(browserName + " is not a supported browser.");
774788
}

src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/RunOnFailure.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void runOnFailure() {
8181
if(runOnFailurePythonInterpreter.get().eval("EXECUTION_CONTEXTS.current").toString().equals("None")) {
8282
return;
8383
}
84+
runningOnFailureRoutine = true;
8485

8586
try {
8687
runOnFailurePythonInterpreter.get().exec(

src/test/java/com/github/markusbernhardt/seleniumlibrary/keywords/BrowserManagementTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public void testCreateDesiredCapabilitiesWithOnlyBrowserOptions() {
6262
assertTrue(profile.getStringPreference("network.proxy.http", "wrong") != "wrong");
6363
}
6464

65+
@Test
66+
public void testCreateDesiredCapabilitiesForHtmlUnit() {
67+
Capabilities dc = bm.createCapabilities("htmlunitwithjs", null, "");
68+
assertTrue(dc.getBrowserName().equals("htmlunit"));
69+
}
70+
6571
@Test
6672
public void parseChromeBrowserOptions() {
6773
ChromeOptions chromeOptions = new ChromeOptions();

src/test/robotframework/testsuites/UnitTests/AW3Schools.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
*** Settings ***
22
Suite Teardown Close All Browsers
33
Resource ../../settings/Settings.robot
4+
Default Tags htmlunitwith htmlunitwithjs
45

56
*** Variables ***
67
${URL Application} http://www.w3schools.com
78

89
*** Test Cases ***
910
Select
10-
[Tags] jbrowser
1111
Open Browser https://developer.mozilla.org/en/docs/Web/HTML/Element/select#Examples ${browser} mainbrowser
1212
Wait Until Page Contains Element xpath://select
1313
Select From List xpath://select Third Value

src/test/robotframework/testsuites/UnitTests/ExtJS.robot

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Suite Setup Open Page
33
Suite Teardown Close Browser
44
Resource ../../settings/Settings.robot
5-
Default Tags jbrowser
65

76
*** Variables ***
87
${URL Application} http://examples.sencha.com/extjs/6.5.0/examples/classic/ticket-app/index.html

src/test/robotframework/testsuites/UnitTests/GetInnerElementId.robot

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
*** Settings ***
22
Resource ../../settings/Settings.robot
3-
Default Tags jbrowser
43

54
*** Test Cases ***
65
Get Inner Element Id test

0 commit comments

Comments
 (0)