Skip to content
Open
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
4 changes: 2 additions & 2 deletions env/chrome/browserstack.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BROWSER = Chrome
BROWSER_VERSION = 53
BROWSER_VERSION = latest
OS = Windows
OS_VERSION = 8.1
OS_VERSION = 11
4 changes: 2 additions & 2 deletions env/default/browserstack.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BROWSER = Chrome
BROWSER_VERSION = 53
BROWSER_VERSION = latest
OS = Windows
OS_VERSION = 8.1
OS_VERSION = 11
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,17 @@
<dependency>
<groupId>com.thoughtworks.gauge</groupId>
<artifactId>gauge-java</artifactId>
<version>0.6.0</version>
<version>0.12.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.0.1</version>
<version>4.27.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
</dependencies>
</project>
51 changes: 30 additions & 21 deletions src/test/java/com/browserstack/gauge/pages/DriverFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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<String, Object> 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) {

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

@AfterSpec
public void tearDown() {
driver.close();
driver.quit();
if (driver != null) {
driver.quit();
}
}
}
Loading