Skip to content

Commit a7595ac

Browse files
Fix: Gauge runner + W3C session creation on sdk
The sdk branch could not create any BrowserStack session: - gauge-java 0.6.0 mismatched the installed Gauge runtime -> 'Failed to start gauge API: Timed out connecting to java'. Bumped to 0.12.0. - selenium-java 3.0.1 -> 4.27.0 for JDK 21+ compatibility; added explicit junit 4.13.2 (no longer transitive from Selenium 4). - DriverFactory set flat JSON-wire caps (browser/os/...) which Selenium 4 rejects with 'Illegal key values seen in w3c capabilities'. Nested BrowserStack caps under bstack:options; build name now read from BROWSERSTACK_BUILD_NAME; null-safe teardown. - env chrome/default used Chrome 53 / Win 8.1 (incompatible chromedriver). Updated to Chrome latest / Windows 11. Verified: 4 BrowserStack Automate sessions created and status=done (Chrome 148 / Windows 11). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 4db3dd1 commit a7595ac

4 files changed

Lines changed: 41 additions & 27 deletions

File tree

env/chrome/browserstack.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
BROWSER = Chrome
2-
BROWSER_VERSION = 53
2+
BROWSER_VERSION = latest
33
OS = Windows
4-
OS_VERSION = 8.1
4+
OS_VERSION = 11
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
BROWSER = Chrome
2-
BROWSER_VERSION = 53
2+
BROWSER_VERSION = latest
33
OS = Windows
4-
OS_VERSION = 8.1
4+
OS_VERSION = 11

pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,17 @@
7575
<dependency>
7676
<groupId>com.thoughtworks.gauge</groupId>
7777
<artifactId>gauge-java</artifactId>
78-
<version>0.6.0</version>
78+
<version>0.12.0</version>
7979
</dependency>
8080
<dependency>
8181
<groupId>org.seleniumhq.selenium</groupId>
8282
<artifactId>selenium-java</artifactId>
83-
<version>3.0.1</version>
83+
<version>4.27.0</version>
84+
</dependency>
85+
<dependency>
86+
<groupId>junit</groupId>
87+
<artifactId>junit</artifactId>
88+
<version>4.13.2</version>
8489
</dependency>
8590
</dependencies>
8691
</project>

src/test/java/com/browserstack/gauge/pages/DriverFactory.java

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import com.thoughtworks.gauge.AfterSpec;
44
import com.thoughtworks.gauge.BeforeSpec;
5+
import org.openqa.selenium.MutableCapabilities;
56
import org.openqa.selenium.WebDriver;
6-
import org.openqa.selenium.remote.DesiredCapabilities;
77
import org.openqa.selenium.remote.RemoteWebDriver;
88

99
import java.net.MalformedURLException;
1010
import java.net.URL;
11-
import java.util.concurrent.TimeUnit;
11+
import java.time.Duration;
12+
import java.util.HashMap;
13+
import java.util.Map;
1214

1315
public class DriverFactory {
1416
private static final String USERNAME = System.getenv("BROWSERSTACK_USERNAME");
@@ -21,34 +23,40 @@ public static WebDriver getDriver() {
2123
return driver;
2224
}
2325

26+
private static String envOr(String key, String fallback) {
27+
String value = System.getenv(key);
28+
return (value != null && !value.isEmpty()) ? value : fallback;
29+
}
30+
2431
@BeforeSpec
2532
public void setUp() {
2633
try {
27-
DesiredCapabilities caps = new DesiredCapabilities();
34+
// Selenium 4 enforces W3C. BrowserStack vendor capabilities must be
35+
// nested under the "bstack:options" map rather than set as flat keys.
36+
MutableCapabilities caps = new MutableCapabilities();
37+
Map<String, Object> bstackOptions = new HashMap<>();
2838

29-
// Capabilities from environment
30-
if(System.getenv("DEVICE") != null){
39+
if (System.getenv("DEVICE") != null) {
3140
caps.setCapability("browserName", System.getenv("BROWSERNAME"));
32-
caps.setCapability("platform", System.getenv("PLATFORM"));
33-
caps.setCapability("device", System.getenv("DEVICE"));
34-
}
35-
else {
36-
caps.setCapability("browser", System.getenv("BROWSER"));
37-
caps.setCapability("browser_version", System.getenv("BROWSER_VERSION"));
38-
39-
caps.setCapability("os", System.getenv("OS"));
40-
caps.setCapability("os_version", System.getenv("OS_VERSION"));
41+
bstackOptions.put("deviceName", System.getenv("DEVICE"));
42+
bstackOptions.put("osVersion", System.getenv("PLATFORM"));
43+
bstackOptions.put("realMobile", "true");
44+
} else {
45+
caps.setCapability("browserName", envOr("BROWSER", "Chrome"));
46+
bstackOptions.put("browserVersion", envOr("BROWSER_VERSION", "latest"));
47+
bstackOptions.put("os", envOr("OS", "Windows"));
48+
bstackOptions.put("osVersion", envOr("OS_VERSION", "11"));
4149
}
4250

43-
// Hardcoded capabilities
44-
caps.setCapability("build", "browserstack build");
45-
caps.setCapability("browserstack.debug", "true");
46-
caps.setCapability("name", "BStack Sample Gauge");
51+
bstackOptions.put("buildName", envOr("BROWSERSTACK_BUILD_NAME", "browserstack build"));
52+
bstackOptions.put("sessionName", "BStack Sample Gauge");
53+
bstackOptions.put("debug", "true");
54+
caps.setCapability("bstack:options", bstackOptions);
4755

4856
URL remoteURL = new URL(URL);
4957

5058
driver = new RemoteWebDriver(remoteURL, caps);
51-
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
59+
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
5260

5361
} catch (MalformedURLException e) {
5462

@@ -59,7 +67,8 @@ public void setUp() {
5967

6068
@AfterSpec
6169
public void tearDown() {
62-
driver.close();
63-
driver.quit();
70+
if (driver != null) {
71+
driver.quit();
72+
}
6473
}
6574
}

0 commit comments

Comments
 (0)