diff --git a/env/chrome/browserstack.properties b/env/chrome/browserstack.properties
index 1580dc2..8e0cbc6 100644
--- a/env/chrome/browserstack.properties
+++ b/env/chrome/browserstack.properties
@@ -1,4 +1,4 @@
BROWSER = Chrome
-BROWSER_VERSION = 53
+BROWSER_VERSION = latest
OS = Windows
-OS_VERSION = 8.1
+OS_VERSION = 11
diff --git a/env/default/browserstack.properties b/env/default/browserstack.properties
index 1580dc2..8e0cbc6 100644
--- a/env/default/browserstack.properties
+++ b/env/default/browserstack.properties
@@ -1,4 +1,4 @@
BROWSER = Chrome
-BROWSER_VERSION = 53
+BROWSER_VERSION = latest
OS = Windows
-OS_VERSION = 8.1
+OS_VERSION = 11
diff --git a/pom.xml b/pom.xml
index e068a88..bdaea04 100644
--- a/pom.xml
+++ b/pom.xml
@@ -75,12 +75,17 @@
com.thoughtworks.gauge
gauge-java
- 0.6.0
+ 0.12.0
org.seleniumhq.selenium
selenium-java
- 3.0.1
+ 4.27.0
+
+
+ junit
+ junit
+ 4.13.2
diff --git a/src/test/java/com/browserstack/gauge/pages/DriverFactory.java b/src/test/java/com/browserstack/gauge/pages/DriverFactory.java
index 7ccfb0a..ff3c9bd 100644
--- a/src/test/java/com/browserstack/gauge/pages/DriverFactory.java
+++ b/src/test/java/com/browserstack/gauge/pages/DriverFactory.java
@@ -2,13 +2,15 @@
import com.thoughtworks.gauge.AfterSpec;
import com.thoughtworks.gauge.BeforeSpec;
+import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.WebDriver;
-import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.concurrent.TimeUnit;
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
public class DriverFactory {
private static final String USERNAME = System.getenv("BROWSERSTACK_USERNAME");
@@ -21,34 +23,40 @@ public static WebDriver getDriver() {
return driver;
}
+ private static String envOr(String key, String fallback) {
+ String value = System.getenv(key);
+ return (value != null && !value.isEmpty()) ? value : fallback;
+ }
+
@BeforeSpec
public void setUp() {
try {
- DesiredCapabilities caps = new DesiredCapabilities();
+ // Selenium 4 enforces W3C. BrowserStack vendor capabilities must be
+ // nested under the "bstack:options" map rather than set as flat keys.
+ MutableCapabilities caps = new MutableCapabilities();
+ Map bstackOptions = new HashMap<>();
- // Capabilities from environment
- if(System.getenv("DEVICE") != null){
+ if (System.getenv("DEVICE") != null) {
caps.setCapability("browserName", System.getenv("BROWSERNAME"));
- caps.setCapability("platform", System.getenv("PLATFORM"));
- caps.setCapability("device", System.getenv("DEVICE"));
- }
- else {
- caps.setCapability("browser", System.getenv("BROWSER"));
- caps.setCapability("browser_version", System.getenv("BROWSER_VERSION"));
-
- caps.setCapability("os", System.getenv("OS"));
- caps.setCapability("os_version", System.getenv("OS_VERSION"));
+ bstackOptions.put("deviceName", System.getenv("DEVICE"));
+ bstackOptions.put("osVersion", System.getenv("PLATFORM"));
+ bstackOptions.put("realMobile", "true");
+ } else {
+ caps.setCapability("browserName", envOr("BROWSER", "Chrome"));
+ bstackOptions.put("browserVersion", envOr("BROWSER_VERSION", "latest"));
+ bstackOptions.put("os", envOr("OS", "Windows"));
+ bstackOptions.put("osVersion", envOr("OS_VERSION", "11"));
}
- // Hardcoded capabilities
- caps.setCapability("build", "browserstack build");
- caps.setCapability("browserstack.debug", "true");
- caps.setCapability("name", "BStack Sample Gauge");
+ bstackOptions.put("buildName", envOr("BROWSERSTACK_BUILD_NAME", "browserstack build"));
+ bstackOptions.put("sessionName", "BStack Sample Gauge");
+ bstackOptions.put("debug", "true");
+ caps.setCapability("bstack:options", bstackOptions);
URL remoteURL = new URL(URL);
driver = new RemoteWebDriver(remoteURL, caps);
- driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
+ driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
} catch (MalformedURLException e) {
@@ -59,7 +67,8 @@ public void setUp() {
@AfterSpec
public void tearDown() {
- driver.close();
- driver.quit();
+ if (driver != null) {
+ driver.quit();
+ }
}
}