Skip to content

Commit 89c1d74

Browse files
neha-sanseclaude
andauthored
Add Cucumber step definitions for Percy visual testing (#309)
* Add Cucumber step definitions for Percy visual testing Add PercySteps class providing Gherkin step definitions for: - Percy Snapshot (DOM): widths, min height, percy CSS, scope, layout mode, JavaScript, labels, test case, responsive capture - Percy Screenshot (Automate): with options and regions - Create Percy Region: ignore/consider/intelliignore by CSS, XPath, bounding box, with diff sensitivity and padding - Data table support for arbitrary options Cucumber dependency is provided scope - users bring their own version. Includes unit tests for all step definitions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Report Cucumber environment info in Percy build metadata - Add setClientInfo/setEnvironmentInfo to Percy and Environment classes - PercySteps sets client to "percy-cucumber-java-selenium/<version>" and environment to "cucumber-java/<version>; selenium-java" - Add Percy.getSdkVersion() public static method Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Add parity with Robot Framework: missing region and snapshot steps - Add ignore/consider region with padding - Add consider region with XPath (+ diff sensitivity) - Add intelliignore region with XPath - Add snapshot steps: Shadow DOM disabled, responsive capture, sync - Add scopeOptions parsing in buildOptions helper Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Add snapshot and screenshot tests for Cucumber PercySteps The existing tests only covered lifecycle and region creation but never invoked percy.snapshot() or percy.screenshot(). This adds tests for every @when step method using a mocked Percy instance injected via reflection, verifying that each Cucumber step correctly delegates to the Percy SDK with the right name and options. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4bda7d4 commit 89c1d74

5 files changed

Lines changed: 954 additions & 0 deletions

File tree

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@
8787
<version>3.12.4</version>
8888
<scope>test</scope>
8989
</dependency>
90+
<!-- Cucumber (optional - for BDD step definitions) -->
91+
<dependency>
92+
<groupId>io.cucumber</groupId>
93+
<artifactId>cucumber-java</artifactId>
94+
<version>7.15.0</version>
95+
<scope>provided</scope>
96+
</dependency>
97+
<dependency>
98+
<groupId>io.cucumber</groupId>
99+
<artifactId>cucumber-junit-platform-engine</artifactId>
100+
<version>7.15.0</version>
101+
<scope>test</scope>
102+
</dependency>
90103

91104
</dependencies>
92105

src/main/java/io/percy/selenium/Environment.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,24 @@ class Environment {
1313
private final static String SDK_VERSION = "2.1.2";
1414
private final static String SDK_NAME = "percy-java-selenium";
1515

16+
private String clientInfoOverride;
17+
private String environmentInfoOverride;
18+
1619
Environment(WebDriver driver) {
1720
this.driver = driver;
1821
}
1922

2023
public String getClientInfo() {
24+
if (clientInfoOverride != null) {
25+
return clientInfoOverride;
26+
}
2127
return SDK_NAME + "/" + SDK_VERSION;
2228
}
2329

2430
public String getEnvironmentInfo() {
31+
if (environmentInfoOverride != null) {
32+
return environmentInfoOverride;
33+
}
2534
// If this is a wrapped driver, get the actual driver that this one wraps.
2635
WebDriver innerDriver = this.driver instanceof WrapsDriver ?
2736
((WrapsDriver) this.driver).getWrappedDriver()
@@ -33,4 +42,16 @@ public String getEnvironmentInfo() {
3342
// We don't know this type of driver. Report its classname as environment info.
3443
return String.format("selenium-java; %s", driverName);
3544
}
45+
46+
void setClientInfo(String clientInfo) {
47+
this.clientInfoOverride = clientInfo;
48+
}
49+
50+
void setEnvironmentInfo(String environmentInfo) {
51+
this.environmentInfoOverride = environmentInfo;
52+
}
53+
54+
public static String getSdkVersion() {
55+
return SDK_VERSION;
56+
}
3657
}

src/main/java/io/percy/selenium/Percy.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,27 @@ public Percy(WebDriver driver) {
8686
this.env = new Environment(driver);
8787
}
8888

89+
/**
90+
* Override the client info reported to Percy.
91+
* Used by framework wrappers (e.g., Cucumber) to identify themselves.
92+
*
93+
* @param clientInfo Client identifier (e.g., "percy-cucumber-java-selenium/2.1.2")
94+
* @param environmentInfo Environment details (e.g., "cucumber-java/7.15.0; selenium-java; ChromeDriver")
95+
*/
96+
public void setClientInfo(String clientInfo, String environmentInfo) {
97+
this.env.setClientInfo(clientInfo);
98+
this.env.setEnvironmentInfo(environmentInfo);
99+
}
100+
101+
/**
102+
* Get the SDK version string.
103+
*
104+
* @return SDK version (e.g., "2.1.2")
105+
*/
106+
public static String getSdkVersion() {
107+
return Environment.getSdkVersion();
108+
}
109+
89110
/**
90111
* Creates a region configuration based on the provided parameters.
91112
*

0 commit comments

Comments
 (0)