Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
<release>8</release>
</configuration>
</plugin>
<plugin>
Expand Down
23 changes: 18 additions & 5 deletions src/main/java/io/percy/selenium/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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());
}
}
11 changes: 8 additions & 3 deletions src/main/java/io/percy/selenium/Percy.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.percy.selenium;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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<Integer> widths) {
public void snapshot(String name, List<Integer> widths) {
snapshot(name, widths, null);
}

Expand All @@ -92,7 +97,7 @@ public void snapshot(String name, @Nullable List<Integer> widths) {
* In pixels.
* @param minHeight The minimum height of the resulting snapshot. In pixels.
*/
public void snapshot(String name, @Nullable List<Integer> widths, @Nullable Integer minHeight) {
public void snapshot(String name, @Nullable List<Integer> 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.");
Expand Down