Skip to content

Commit

Permalink
feat: support RemoteWebDriver
Browse files Browse the repository at this point in the history
Example usage:

```xml
<plugin>
  <groupId>com.github.searls</groupId>
  <artifactId>jasmine-maven-plugin</artifactId>
  <version>${jasmine-maven-plugin.version}</version>
  <executions>
    <execution>
      <goals>
        <goal>test</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <serverHostname>${accessibleHostname}</serverHostname>
    <webDriverClassName>org.openqa.selenium.remote.RemoteWebDriver</webDriverClassName>
    <webDriverCapabilities>
      <webDriverCapability>
        <name>browserName</name>
        <value>chrome</value>
      </webDriverCapability>
      <webDriverCapability>
        <name>goog:chromeOptions</name>
        <value implementation="org.openqa.selenium.chrome.ChromeOptions">
          <headless>true</headless>
        </value>
      </webDriverCapability>
    </webDriverCapabilities>
    <!-- If your remote server is not running at http://localhost:4444/wd/hub then you can use this parameter to configure the right location -->
    <!-- <remoteWebDriverUrl>http://localhost:4444/wd/hub</remoteWebDriverUrl> -->
  </configuration>
</plugin>
```

closes #234
closes #235
closes #349
  • Loading branch information
klieber committed Sep 16, 2020
1 parent 9ac60fb commit e288396
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import com.github.searls.jasmine.mojo.Capability;
import org.immutables.value.Value;

import java.net.URL;
import java.util.List;

@Value.Immutable
public interface WebDriverConfiguration {
String getWebDriverClassName();
List<Capability> getWebDriverCapabilities();
URL getRemoteWebDriverUrl();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import javax.inject.Named;
import java.lang.reflect.Constructor;
Expand All @@ -47,6 +48,7 @@ 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(RemoteWebDriver.class.getName(), WebDriverFactory::createRemoteWebDriver)
.build();

public WebDriver createWebDriver(WebDriverConfiguration config) {
Expand Down Expand Up @@ -157,4 +159,8 @@ private static WebDriver createChromeDriver(WebDriverConfiguration config) {
config
));
}

private static WebDriver createRemoteWebDriver(WebDriverConfiguration config) {
return new RemoteWebDriver(config.getRemoteWebDriverUrl(), getCapabilities(config.getWebDriverCapabilities()));
}
}
13 changes: 12 additions & 1 deletion src/main/java/com/github/searls/jasmine/mojo/TestMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.net.URL;
import java.util.Collections;
import java.util.List;

Expand All @@ -67,13 +68,14 @@ public class TestMojo extends AbstractJasmineMojo {
* <li>org.openqa.selenium.htmlunit.HtmlUnitDriver</li>
* <li>org.openqa.selenium.firefox.FirefoxDriver</li>
* <li>org.openqa.selenium.ie.InternetExplorerDriver</li>
* <li>org.openqa.selenium.remote.RemoteWebDriver</li>
* </ul>
* <br>
* See the webDriverCapabilities property for configuring driver specific properties.
*
* @since 1.1.0
*/
@Parameter(defaultValue = "org.openqa.selenium.chrome.ChromeDriver")
@Parameter(property = "jasmine.webDriverClassName", defaultValue = "org.openqa.selenium.chrome.ChromeDriver")
private String webDriverClassName = ChromeDriver.class.getName();

/**
Expand Down Expand Up @@ -109,6 +111,14 @@ public class TestMojo extends AbstractJasmineMojo {
@Parameter
private List<Capability> webDriverCapabilities = Collections.emptyList();

/**
* <p>The URL to your RemoteWebDriver server. This is only relevant if you are using the RemoteWebDriver.</p>
*
* @since 3.0
*/
@Parameter(property = "jasmine.remoteWebDriverUrl", defaultValue = "http://localhost:4444/wd/hub")
private URL remoteWebDriverUrl = null;

/**
* <p>Determines the format that jasmine:test will print to console.</p>
* <p>Valid options:</p>
Expand Down Expand Up @@ -265,6 +275,7 @@ private WebDriverConfiguration getWebDriverConfiguration() {
return ImmutableWebDriverConfiguration.builder()
.webDriverCapabilities(webDriverCapabilities)
.webDriverClassName(webDriverClassName)
.remoteWebDriverUrl(remoteWebDriverUrl)
.build();
}

Expand Down

0 comments on commit e288396

Please sign in to comment.