Skip to content

Commit

Permalink
feat: remove htmlunit
Browse files Browse the repository at this point in the history
  • Loading branch information
klieber committed Sep 14, 2020
1 parent 0f873c8 commit f8cc748
Show file tree
Hide file tree
Showing 27 changed files with 87 additions and 2,605 deletions.
2 changes: 1 addition & 1 deletion features/custom_browser.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ Feature: setting a custom browser
Given I am currently in the "jasmine-webapp-custom-browser" project
When I run "mvn clean test"
Then the build should succeed
And I should see "has Firefox/45.0 in its user agent string"
And I should see "has Firefox in its user agent string"


11 changes: 0 additions & 11 deletions features/phantomjs_driver.feature

This file was deleted.

16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<packaging>maven-plugin</packaging>

<name>jasmine-maven-plugin</name>
<description>A JavaScript unit test plugin that processes JavaScript sources and Jasmine specs, prepares test runner HTML files, executes Jasmine specs headlessly with HtmlUnit, and produces JUnit XML reports</description>
<description>A JavaScript unit test plugin that processes JavaScript sources and Jasmine specs, prepares test runner HTML files, executes Jasmine specs headlessly with Chrome, and produces JUnit XML reports</description>
<url>https://github.com/searls/jasmine-maven-plugin</url>
<licenses>
<license>
Expand Down Expand Up @@ -142,9 +142,8 @@
</ciManagement>
<properties>
<jetty.version>9.4.8.v20171121</jetty.version>
<selenium.version>3.8.1</selenium.version>
<selenium.version>3.141.59</selenium.version>
<jasmine.version>2.6.0</jasmine.version>
<htmlunit.version>2.29</htmlunit.version>
<mockito.version>3.5.10</mockito.version>
<webdrivermanager.version>4.2.0</webdrivermanager.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -264,11 +263,6 @@
<artifactId>jasmine</artifactId>
<version>${jasmine.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>${htmlunit.version}</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
Expand Down Expand Up @@ -328,6 +322,12 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

import javax.inject.Named;
Expand All @@ -48,7 +47,6 @@ public class WebDriverFactory {
private static final Map<String, Function<WebDriverConfiguration, WebDriver>> SUPPORTED_DRIVERS =
ImmutableMap.<String, Function<WebDriverConfiguration, WebDriver>>builder()
.put(ChromeDriver.class.getName(), WebDriverFactory::createChromeDriver)
.put(HtmlUnitDriver.class.getName(), WebDriverFactory::createHtmlUnitWebDriver)
.build();

public WebDriver createWebDriver(WebDriverConfiguration config) {
Expand Down Expand Up @@ -149,10 +147,6 @@ private static <E extends MutableCapabilities> E customizeCapabilities(E capabil
return capabilities;
}

private static WebDriver createHtmlUnitWebDriver(WebDriverConfiguration config) {
return new QuietHtmlUnitDriver(customizeCapabilities(DesiredCapabilities.htmlUnit(), config), config.isDebug());
}

private static WebDriver createChromeDriver(WebDriverConfiguration config) {
WebDriverManager.getInstance(ChromeDriver.class).setup();
return new ChromeDriver(customizeCapabilities(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -26,7 +26,7 @@ public class FormatsScriptTags {
public String format(Collection<String> sourceLocations) {
StringBuilder sb = new StringBuilder();
for (String location : sourceLocations) {
sb.append("<script type=\"text/javascript\" src=\"").append(location).append("\"></script>").append("\n");
sb.append("<script type=\"application/javascript\" src=\"").append(location).append("\"></script>").append("\n");
}
return sb.toString();
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/github/searls/jasmine/mojo/TestMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ public void execute() throws MojoExecutionException, MojoFailureException {
@Override
public void run(ServerConfiguration serverConfiguration,
JasmineConfiguration configuration) throws Exception {

if (!debug) {
System.setProperty("org.slf4j.simpleLogger.log.org.eclipse.jetty", "warn");
System.setProperty("org.slf4j.simpleLogger.log.io.github.bonigarcia.wdm", "warn");
System.setProperty("webdriver.chrome.silentOutput", "true");
}
ServerManager serverManager = ServerManager.newInstance();
try {
int port = serverManager.start(resourceHandlerConfigurator.createHandler(configuration));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void setHeaders(HttpServletResponse response, String resourcePath, Strin
if (resourcePath.endsWith(".css")) {
response.setContentType("text/css");
} else {
response.setContentType("text/javascript");
response.setContentType("application/javascript");
}
response.addDateHeader("EXPIRES", 0L);
response.setDateHeader(HttpHeader.LAST_MODIFIED.asString(), new Date().getTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta http-equiv="refresh" content="$autoRefreshInterval$">
$endif$
<title>Jasmine Spec Runner</title>
<script type="text/javascript">
<script type="application/javascript">
window.onerror = function(msg,url,line) {
if (document.head) {
var jserror = document.head.getAttribute('jmp_jserror') || '';
Expand All @@ -23,7 +23,7 @@
$preloadScriptTags$
</head>
<body>
<script type="text/javascript">
<script type="application/javascript">
if(window.location.href.indexOf("SpecRunner.html") !== -1) {
document.body.appendChild(document.createTextNode("Warning: Opening this HTML file directly from the file system is deprecated. You should instead try running `mvn jasmine:bdd` from the command line, and then visit `http://localhost:8234` in your browser. "))
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/jasmine-templates/SpecRunner.htmltemplate
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta http-equiv="refresh" content="$autoRefreshInterval$">
$endif$
<title>Jasmine Spec Runner</title>
<script type="text/javascript">
<script type="application/javascript">
window.onerror = function(msg,url,line) {
if (document.head) {
var jserror = document.head.getAttribute('jmp_jserror') || '';
Expand All @@ -20,13 +20,13 @@
</script>
$cssDependencies$
$javascriptDependencies$
<script type="text/javascript">
<script type="application/javascript">
window.onload = jasmine.boot;
</script>
$allScriptTags$
</head>
<body>
<script type="text/javascript">
<script type="application/javascript">
if(window.location.href.indexOf("SpecRunner.html") !== -1) {
document.body.appendChild(document.createTextNode("Warning: Opening this HTML file directly from the file system is deprecated. You should instead try running `mvn jasmine:bdd` from the command line, and then visit `http://localhost:8234` in your browser. "))
}
Expand Down
Empty file.
84 changes: 35 additions & 49 deletions src/site/markdown/webdriver-customization.md.vm
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
WebDriver Customization
=======================
The jamine-maven-plugin ships with [HtmlUnitDriver](https://code.google.com/p/selenium/wiki/HtmlUnitDriver) by default but it is also possible to change to any other [WebDriver](http://docs.seleniumhq.org/projects/webdriver/) implementation and configure it with [Capabilities](http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/Capabilities.html).
The jamine-maven-plugin ships with [ChromeDriver](https://chromedriver.chromium.org/home) configured to run in headless
mode by default. It is also possible to change to any other [WebDriver](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/WebDriver.html)
implementation and configure it with [Capabilities](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/Capabilities.html).

Changing the implementation
---------------------------
The `webDriverClassName` parameter allows you to specify the WebDriver implementation you would like to use in place of HtmlUnitDriver. The WebDriver implementation must either have a constructor that excepts no arguments or a constructor that accepts a single [Capabilities](http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/Capabilities.html) argument.
The `webDriverClassName` parameter allows you to specify the WebDriver implementation you would like to use in place of
ChromeDriver. The WebDriver implementation must either have a constructor that excepts no arguments or a constructor
that accepts a single [Capabilities](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/Capabilities.html)
argument.

Here is an example using FirefoxDriver:

Expand Down Expand Up @@ -32,15 +37,17 @@ Here is an example using FirefoxDriver:

Setting capabilities
--------------------
You can configure your WebDriver implementation using [Capabilities](http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/Capabilities.html) as a simple String, List, or a Map. The capabilities are configured using the `webDriverCapabilities` parameter and you may provide multiple capabilities.
You can configure your WebDriver implementation using [Capabilities](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/WebDriver.html)
as a simple String, List, or a Map. The capabilities are configured using the `webDriverCapabilities` parameter and you
may provide multiple capabilities.

* Capability as a String

``` xml
<webDriverCapabilities>
<capability>
<name>phantomjs.binary.path</name>
<value>/opt/phantomjs/bin/phantomjs</value>
<name>binary</name>
<value>/path/to/other/chrome/binary</value>
</capability>
</webDriverCapabilities>
```
Expand All @@ -50,10 +57,11 @@ You can configure your WebDriver implementation using [Capabilities](http://sele
``` xml
<webDriverCapabilities>
<capability>
<name>phantomjs.cli.args</name>
<name>args</name>
<list>
<value>--disk-cache=true</value>
<value>--max-disk-cache-size=256</value>
<value>--headless</value>
<value>--start-maximized</value>
<value>--user-data-dir=/path/to/your/custom/profile</value>
</list>
</capability>
</webDriverCapabilities>
Expand All @@ -72,41 +80,15 @@ You can configure your WebDriver implementation using [Capabilities](http://sele
</webDriverCapabilities>
```

You will need to consult with your WebDriver implementation to determine what capabilities are possible. If a capability can not be provided as either a String, List, or Map then it is currently not supported.
You will need to consult with your WebDriver implementation to determine what capabilities are possible. If a
capability can not be provided as either a String, List, or Map then it is currently not supported.

Lastly, we do not test every possible WebDriver implementation with every possible permutation of capabilities so it is very possible that they will not work. Feel free to file a bug if you come across such a capability that you feel should be supported.
Lastly, we do not test every possible WebDriver implementation with every possible permutation of capabilities so it
is very possible that they will not work. Feel free to file a bug if you come across such a capability that you feel
should be supported.

Examples
--------

Configuring the default HtmlUnitDriver to use a proxy:

```xml
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${currentStableVersion}<version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<webDriverCapabilities>
<capability>
<name>proxy</name>
<map>
<httpProxy>myproxyserver.com:8000</httpProxy>
</map>
</capability>
</webDriverCapabilities>
</configuration>
</plugin>
```

Configuring PhantomJSDriver with custom binary path and caching settings:
The default driver used to be HtmlUnit many versions ago. As of version `3.0`, we no longer include HtmlUnit with the
plugin. If you still need HtmlUnit then you can use it by configuring your build like this:

```xml
<plugin>
Expand All @@ -121,20 +103,24 @@ Configuring PhantomJSDriver with custom binary path and caching settings:
</execution>
</executions>
<configuration>
<webDriverClassName>org.openqa.selenium.phantomjs.PhantomJSDriver</webDriverClassName>
<webDriverClassName>org.openqa.selenium.htmlunit.HtmlUnitDriver</webDriverClassName>
<webDriverCapabilities>
<capability>
<name>phantomjs.binary.path</name>
<value>/opt/phantomjs/bin/phantomjs</value>
<name>browserName</name>
<value>htmlunit</value>
</capability>
<capability>
<name>phantomjs.cli.args</name>
<list>
<value>--disk-cache=true</value>
<value>--max-disk-cache-size=256</value>
</list>
<name>browserVersion</name>
<value>firefox</value>
</capability>
</webDriverCapabilities>
</configuration>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>2.43.1</version>
</dependency>
</dependencies>
</plugin>
```
6 changes: 3 additions & 3 deletions src/test/java/com/github/searls/jasmine/HtmlAssertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -35,7 +35,7 @@ public HtmlAssertions containsLinkTagWithSource(String src) {

public HtmlAssertions containsScriptTagWithSource(String src) {
return this
.contains("<script type=\"text/javascript\" src=\"" + src + "\"></script>")
.contains("<script type=\"application/javascript\" src=\"" + src + "\"></script>")
.describedAs("contains <script/> tag with src='" + src + "'");
}

Expand Down
Loading

0 comments on commit f8cc748

Please sign in to comment.