1

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.

KellyM
  • 2,472
  • 6
  • 46
  • 90
  • The IP Geolocation capability is an Enterprise-only feature. Can you confirm your account is Enterprise? – A P Oct 27 '22 at 01:35
  • @AshwaniPathak - thanks for the response, but this question is not about setting IP Geolocation; it is about setting browser specific capabilities when using the Browserstack SDK. Dismissing the Geolocation prompt was just one use case. – KellyM Oct 27 '22 at 12:20
  • Raise it with the BrowserStack Support for debugging. – A P Oct 28 '22 at 01:37

0 Answers0