diff --git a/.travis.yml b/.travis.yml index 4f23414..a2c991b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ env: - PROFILE=build,firefox - PROFILE=build,googlechromeheadless - PROFILE=build,firefoxheadless + - PROFILE=build,htmlunitwithjs stages: - test diff --git a/pom.xml b/pom.xml index 03ded72..8f7a6b4 100644 --- a/pom.xml +++ b/pom.xml @@ -129,6 +129,11 @@ jbrowserdriver 1.0.1 + + org.seleniumhq.selenium + htmlunit-driver + 2.35.1 + org.mockito mockito-core @@ -361,6 +366,13 @@ + + htmlunitwithjs + + htmlunitwithjs + False + + firefox diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/BrowserManagement.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/BrowserManagement.java index 21949d5..66ceec0 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/BrowserManagement.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/BrowserManagement.java @@ -38,6 +38,7 @@ import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.firefox.FirefoxProfile; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.ie.InternetExplorerOptions; import org.openqa.selenium.opera.OperaDriver; @@ -168,7 +169,9 @@ public void closeBrowser() { "| Opera | opera |\r\n" + "| Android | android |\r\n" + "| Iphone | iphone |\r\n" + - "| JBrowser | jbrowser |\r\n" + + "| JBrowser | jbrowser |\r\n" + + "| HTMLUnit | htmlunit |\r\n" + + "| HTMLUnit with Javascript | htmlunitwithjs |\r\n" + "\r\n" + "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" + "\r\n" + @@ -677,6 +680,12 @@ protected WebDriver createLocalWebDriver(String browserName, Capabilities desire } catch (Exception e) { throw new SeleniumLibraryFatalException("Creating " + browserName + " instance failed.", e); } + case "htmlunit": + return new HtmlUnitDriver(desiredCapabilities); + case "htmlunitwithjs": + HtmlUnitDriver driver = new HtmlUnitDriver(desiredCapabilities); + driver.setJavascriptEnabled(true); + return driver; default: throw new SeleniumLibraryFatalException(browserName + " is not a supported browser."); } @@ -769,6 +778,11 @@ protected Capabilities createCapabilities(String browserName, String desiredCapa case "jbrowser": desiredCapabilities = new DesiredCapabilities("jbrowser", "1", Platform.ANY); break; + case "htmlunit": + case "htmlunitwithjs": + desiredCapabilities = DesiredCapabilities.htmlUnit(); + ((DesiredCapabilities) desiredCapabilities).setBrowserName("htmlunit"); + break; default: throw new SeleniumLibraryFatalException(browserName + " is not a supported browser."); } diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/RunOnFailure.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/RunOnFailure.java index 50da8e6..0b9af9b 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/RunOnFailure.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/RunOnFailure.java @@ -81,6 +81,7 @@ public void runOnFailure() { if(runOnFailurePythonInterpreter.get().eval("EXECUTION_CONTEXTS.current").toString().equals("None")) { return; } + runningOnFailureRoutine = true; try { runOnFailurePythonInterpreter.get().exec( diff --git a/src/test/java/com/github/markusbernhardt/seleniumlibrary/keywords/BrowserManagementTest.java b/src/test/java/com/github/markusbernhardt/seleniumlibrary/keywords/BrowserManagementTest.java index 7fbffe2..b9f7e2a 100644 --- a/src/test/java/com/github/markusbernhardt/seleniumlibrary/keywords/BrowserManagementTest.java +++ b/src/test/java/com/github/markusbernhardt/seleniumlibrary/keywords/BrowserManagementTest.java @@ -62,6 +62,12 @@ public void testCreateDesiredCapabilitiesWithOnlyBrowserOptions() { assertTrue(profile.getStringPreference("network.proxy.http", "wrong") != "wrong"); } + @Test + public void testCreateDesiredCapabilitiesForHtmlUnit() { + Capabilities dc = bm.createCapabilities("htmlunitwithjs", null, ""); + assertTrue(dc.getBrowserName().equals("htmlunit")); + } + @Test public void parseChromeBrowserOptions() { ChromeOptions chromeOptions = new ChromeOptions(); diff --git a/src/test/robotframework/testsuites/UnitTests/AW3Schools.robot b/src/test/robotframework/testsuites/UnitTests/AW3Schools.robot index 01fd369..32504b6 100644 --- a/src/test/robotframework/testsuites/UnitTests/AW3Schools.robot +++ b/src/test/robotframework/testsuites/UnitTests/AW3Schools.robot @@ -1,13 +1,13 @@ *** Settings *** Suite Teardown Close All Browsers Resource ../../settings/Settings.robot +Default Tags htmlunitwith htmlunitwithjs *** Variables *** ${URL Application} http://www.w3schools.com *** Test Cases *** Select - [Tags] jbrowser Open Browser https://developer.mozilla.org/en/docs/Web/HTML/Element/select#Examples ${browser} mainbrowser Wait Until Page Contains Element xpath://select Select From List xpath://select Third Value diff --git a/src/test/robotframework/testsuites/UnitTests/ExtJS.robot b/src/test/robotframework/testsuites/UnitTests/ExtJS.robot index dded819..4cc8fa1 100644 --- a/src/test/robotframework/testsuites/UnitTests/ExtJS.robot +++ b/src/test/robotframework/testsuites/UnitTests/ExtJS.robot @@ -2,7 +2,6 @@ Suite Setup Open Page Suite Teardown Close Browser Resource ../../settings/Settings.robot -Default Tags jbrowser *** Variables *** ${URL Application} http://examples.sencha.com/extjs/6.5.0/examples/classic/ticket-app/index.html diff --git a/src/test/robotframework/testsuites/UnitTests/GetInnerElementId.robot b/src/test/robotframework/testsuites/UnitTests/GetInnerElementId.robot index 64eb575..058ab1f 100644 --- a/src/test/robotframework/testsuites/UnitTests/GetInnerElementId.robot +++ b/src/test/robotframework/testsuites/UnitTests/GetInnerElementId.robot @@ -1,6 +1,5 @@ *** Settings *** Resource ../../settings/Settings.robot -Default Tags jbrowser *** Test Cases *** Get Inner Element Id test