diff --git a/pom.xml b/pom.xml
index e6c3e3f..f923ec8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -87,6 +87,19 @@
3.12.4
test
+
+
+ io.cucumber
+ cucumber-java
+ 7.15.0
+ provided
+
+
+ io.cucumber
+ cucumber-junit-platform-engine
+ 7.15.0
+ test
+
diff --git a/src/main/java/io/percy/selenium/Environment.java b/src/main/java/io/percy/selenium/Environment.java
index b1d7d78..cf637de 100644
--- a/src/main/java/io/percy/selenium/Environment.java
+++ b/src/main/java/io/percy/selenium/Environment.java
@@ -13,15 +13,24 @@ class Environment {
private final static String SDK_VERSION = "2.1.2";
private final static String SDK_NAME = "percy-java-selenium";
+ private String clientInfoOverride;
+ private String environmentInfoOverride;
+
Environment(WebDriver driver) {
this.driver = driver;
}
public String getClientInfo() {
+ if (clientInfoOverride != null) {
+ return clientInfoOverride;
+ }
return SDK_NAME + "/" + SDK_VERSION;
}
public String getEnvironmentInfo() {
+ if (environmentInfoOverride != null) {
+ return environmentInfoOverride;
+ }
// If this is a wrapped driver, get the actual driver that this one wraps.
WebDriver innerDriver = this.driver instanceof WrapsDriver ?
((WrapsDriver) this.driver).getWrappedDriver()
@@ -33,4 +42,16 @@ public String getEnvironmentInfo() {
// We don't know this type of driver. Report its classname as environment info.
return String.format("selenium-java; %s", driverName);
}
+
+ void setClientInfo(String clientInfo) {
+ this.clientInfoOverride = clientInfo;
+ }
+
+ void setEnvironmentInfo(String environmentInfo) {
+ this.environmentInfoOverride = environmentInfo;
+ }
+
+ public static String getSdkVersion() {
+ return SDK_VERSION;
+ }
}
diff --git a/src/main/java/io/percy/selenium/Percy.java b/src/main/java/io/percy/selenium/Percy.java
index 453c4bf..aed4516 100644
--- a/src/main/java/io/percy/selenium/Percy.java
+++ b/src/main/java/io/percy/selenium/Percy.java
@@ -86,6 +86,27 @@ public Percy(WebDriver driver) {
this.env = new Environment(driver);
}
+ /**
+ * Override the client info reported to Percy.
+ * Used by framework wrappers (e.g., Cucumber) to identify themselves.
+ *
+ * @param clientInfo Client identifier (e.g., "percy-cucumber-java-selenium/2.1.2")
+ * @param environmentInfo Environment details (e.g., "cucumber-java/7.15.0; selenium-java; ChromeDriver")
+ */
+ public void setClientInfo(String clientInfo, String environmentInfo) {
+ this.env.setClientInfo(clientInfo);
+ this.env.setEnvironmentInfo(environmentInfo);
+ }
+
+ /**
+ * Get the SDK version string.
+ *
+ * @return SDK version (e.g., "2.1.2")
+ */
+ public static String getSdkVersion() {
+ return Environment.getSdkVersion();
+ }
+
/**
* Creates a region configuration based on the provided parameters.
*
diff --git a/src/main/java/io/percy/selenium/cucumber/PercySteps.java b/src/main/java/io/percy/selenium/cucumber/PercySteps.java
new file mode 100644
index 0000000..3811b33
--- /dev/null
+++ b/src/main/java/io/percy/selenium/cucumber/PercySteps.java
@@ -0,0 +1,434 @@
+package io.percy.selenium.cucumber;
+
+import io.cucumber.java.en.Given;
+import io.cucumber.java.en.When;
+import io.cucumber.java.en.Then;
+import io.percy.selenium.Percy;
+
+import org.json.JSONObject;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+
+import java.util.*;
+
+/**
+ * Cucumber step definitions for Percy visual testing with Selenium.
+ *
+ *
Provides Gherkin steps to capture Percy snapshots, screenshots (Automate),
+ * and define ignore/consider regions from Cucumber feature files.
+ *
+ * Usage in feature files:
+ *
+ * Feature: Visual Testing
+ * Scenario: Homepage visual test
+ * Given I have a Percy instance
+ * When I take a Percy snapshot named "Homepage"
+ *
+ * Scenario: Snapshot with options
+ * Given I have a Percy instance
+ * When I take a Percy snapshot named "Responsive" with widths "375,768,1280"
+ *
+ * Scenario: Ignore region
+ * Given I have a Percy instance
+ * And I create a Percy ignore region with CSS selector ".ad-banner"
+ * When I take a Percy snapshot named "No Ads" with regions
+ *
+ * Scenario: Automate screenshot
+ * Given I have a Percy instance
+ * When I take a Percy screenshot named "Login Page"
+ *
+ *
+ * Setup in step definition glue:
+ *
+ * public class Hooks {
+ * private static WebDriver driver;
+ *
+ * {@literal @}Before
+ * public void setUp() {
+ * driver = new ChromeDriver();
+ * PercySteps.setDriver(driver);
+ * }
+ *
+ * {@literal @}After
+ * public void tearDown() {
+ * if (driver != null) driver.quit();
+ * PercySteps.reset();
+ * }
+ * }
+ *
+ */
+public class PercySteps {
+
+ private static WebDriver driver;
+ private static Percy percy;
+ private static List