diff --git a/RELEASING.md b/RELEASING.md index d4e433f..b49c75f 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -96,7 +96,7 @@ Follow the prompts to provide new version numbers and tags. To make a new release, edit the version number in pom.xml to be the version number that you want, then run: ```bash -$ mvn clean deploy +$ export GPG_TTY=$(tty) && mvn clean deploy ``` This will create a release candidate, and upload it to the staging servers for Maven Central. diff --git a/pom.xml b/pom.xml index 5baafb4..9156a04 100644 --- a/pom.xml +++ b/pom.xml @@ -95,7 +95,7 @@ maven-compiler-plugin 3.8.0 - 11 + 8 diff --git a/src/main/java/io/percy/selenium/Environment.java b/src/main/java/io/percy/selenium/Environment.java index 2fb9e35..7402c98 100644 --- a/src/main/java/io/percy/selenium/Environment.java +++ b/src/main/java/io/percy/selenium/Environment.java @@ -6,7 +6,9 @@ import java.io.InputStreamReader; import org.openqa.selenium.Capabilities; +import org.openqa.selenium.HasCapabilities; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WrapsDriver; import org.openqa.selenium.remote.RemoteWebDriver; /** @@ -64,10 +66,21 @@ private String getClientInfo() { } private String getEnvironmentInfo() { - Capabilities cap = ((RemoteWebDriver) this.driver).getCapabilities(); - String os = cap.getPlatform().toString(); - String browserName = cap.getBrowserName().toLowerCase(); - String version = cap.getVersion().toString(); - return String.format("selenium-java; %s; %s/%s", os, browserName, version); + // If this is a wrapped driver, get the actual driver that this one wraps. + WebDriver innerDriver = this.driver instanceof WrapsDriver ? + ((WrapsDriver) this.driver).getWrappedDriver() + : this.driver; + + // If this is a driver with Capabilities, use those to report on our environment info. + if (innerDriver instanceof HasCapabilities) { + Capabilities cap = ((HasCapabilities) this.driver).getCapabilities(); + String os = cap.getPlatform().toString(); + String browserName = cap.getBrowserName().toLowerCase(); + String version = cap.getVersion().toString(); + return String.format("selenium-java; %s; %s/%s", os, browserName, version); + } + + // We don't know this type of driver. Report its classname as environment info. + return String.format("selenium-java; unknownDriver; %", innerDriver.getClass().getName()); } } diff --git a/src/main/java/io/percy/selenium/Percy.java b/src/main/java/io/percy/selenium/Percy.java index 7939b51..fd517d5 100644 --- a/src/main/java/io/percy/selenium/Percy.java +++ b/src/main/java/io/percy/selenium/Percy.java @@ -1,5 +1,6 @@ package io.percy.selenium; +import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -56,7 +57,10 @@ public Percy(WebDriver driver) { @Nullable private String loadPercyAgentJs() { try { - return new String(getClass().getClassLoader().getResourceAsStream(AGENTJS_FILE).readAllBytes()); + InputStream stream = getClass().getClassLoader().getResourceAsStream(AGENTJS_FILE); + byte[] agentBytes = new byte[stream.available()]; + stream.read(agentBytes); + return new String(agentBytes); } catch (Exception e) { LOGGER.log(Level.WARNING, "Something went wrong trying to load {}. Snapshotting will not work.", AGENTJS_FILE); @@ -68,6 +72,7 @@ private String loadPercyAgentJs() { * Take a snapshot and upload it to Percy. * * @param name The human-readable name of the snapshot. Should be unique. + * */ public void snapshot(String name) { snapshot(name, null, null); @@ -80,7 +85,7 @@ public void snapshot(String name) { * @param widths The browser widths at which you want to take the snapshot. In * pixels. */ - public void snapshot(String name, @Nullable List widths) { + public void snapshot(String name, List widths) { snapshot(name, widths, null); } @@ -92,7 +97,7 @@ public void snapshot(String name, @Nullable List widths) { * In pixels. * @param minHeight The minimum height of the resulting snapshot. In pixels. */ - public void snapshot(String name, @Nullable List widths, @Nullable Integer minHeight) { + public void snapshot(String name, @Nullable List widths, Integer minHeight) { if (percyAgentJs == null) { // This would happen if we couldn't load percy-agent.js in the constructor. LOGGER.log(Level.WARNING, "percy-agent.js is not available. Snapshotting is disabled.");