I am attempting to setup some tests using BrowserStack Automate + TestNG. I have followed the documentation here. I used the SDK and thus am using browserstack.yml for config; i.e.
buildName: xxx
projectName: xxx
framework: testng
platforms:
- deviceName: iPhone 14
osVersion: 16
browserName: ios
- os: Windows
osVersion: 11
browserName: Chrome
browserVersion: 103.0
- os: Windows
osVersion: 10
browserName: Firefox
browserVersion: 102.0
parallelsPerPlatform: 1
debug: true
networkLogs: false
consoleLogs: warnings
This works fine for simple tests. However, I am needing to set some browser specific capabilities, specifically to disable Geolocation pop-ups. I saw Browserstack provided some documentation on the topic here; however, this does not show how to use it with the SDK/.yml config file.
I attempted to merge the capabilities as follows, but not luck:
/*
* This Java source file was generated by the Gradle 'init' task.
*/
public class BaseTest {
public WebDriver driver;
@BeforeMethod(alwaysRun = true)
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
driver = new RemoteWebDriver(new URL("https://hub.browserstack.com/wd/hub"), new MutableCapabilities());
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
Map<String, Object> profile = new HashMap<String, Object>();
Map<String, Object> contentSettings = new HashMap<String, Object>();
contentSettings.put("geolocation", 2);
profile.put("managed_default_content_settings", contentSettings);
prefs.put("profile", profile);
options.setExperimentalOption("prefs", prefs);
var caps = new MutableCapabilities();
caps.setCapability(ChromeOptions.CAPABILITY, options);
((RemoteWebDriver) driver).getCapabilities().merge(caps);
}
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception {
driver.quit();
}
}
The geolocation prompt still appears and there is no indication that the Chrome capability has been set when reviewing the build in Browserstack.