java - Setting browser specific capabilities using Browserstack SDK - Stack Overflow

Using the Browserstack SDK i want to run Java Selenium Tests on Browsers : Chrome, Edge and Safari in B

Using the Browserstack SDK i want to run Java Selenium Tests on Browsers : Chrome, Edge and Safari in Browserstack cloud ; however i need to set Browser specific capabilities :

For example,

ChromeOptions args :-

--enable-extension-activity-log-testing

--enable-unsafe-extension-debugging

--trusted-download-sources

--start-maximized

--ignore-certificate-errors

--disable-popup-blocking

--incognito

--enable-download-warning-improvements

--window-size=1920,900

EdgeOptions args :-

--start-maximized

--headless=new

This is the Browserstack SDK YAML configuration available capabilities file : Browserstack SDK capabilities and configuration YAML gist :

"In case both the browserstack.yml file and the test script define capabilities, which ones are prioritized? If you have capabilities declared in both the browserstack.yml file and in test scripts, the SDK merges these capabilities. However, if you have similar capabilities mentioned in both these locations, the capabilities in the browserstack.yml file take precedence."

This is how the RemoteWebDriver is configured in the browserstack SDK Sample project :

    @BeforeMethod(alwaysRun = true)
    public void setUp() throws Exception {
    MutableCapabilities capabilities = new MutableCapabilities();
    HashMap<String, String> bstackOptions = new HashMap<>();
    bstackOptions.put("source", "selenide:sample-master:v1.2");
    capabilities.setCapability("bstack:options", bstackOptions);
    driver = new RemoteWebDriver(new URL(String.format("https://%s:%s@hub- 
    cloud.browserstack/wd/hub", userName, accessKey)), capabilities);
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    WebDriverRunner.setWebDriver(driver);
}

This is the Browserstack Sample project YAML file:

I understand i could do something like the following for the chrome options :

    @BeforeMethod(alwaysRun = true)
    public void setUp() throws Exception {
    MutableCapabilities capabilities = new MutableCapabilities();
    HashMap<String, String> bstackOptions = new HashMap<>();
    bstackOptions.put("source", "selenide:sample-master:v1.2");
    capabilities.setCapability("bstack:options", bstackOptions);
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--headless=new");
    options.addArguments("window-size=1400,800");
    options.addArguments("disable-gpu");
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    driver = new RemoteWebDriver(new 
    URL(String.format("https://%s:%s@hub- 
    cloud.browserstack/wd/hub", userName, accessKey)), 
    capabilities);
}

(a) But would the capabilities be merged to the Chrome capabilities existing in the browserstack SDK YAML file (and it didn't work )

(b) Would this change break the other browserstack Edge and Safari sessions tied to the RemoteWebDriver

*Note this is a similar question to this question which didn't seem to answer the question: Setting language for Remotewebdriver - BrowserStack endpoint

Using the Browserstack SDK i want to run Java Selenium Tests on Browsers : Chrome, Edge and Safari in Browserstack cloud ; however i need to set Browser specific capabilities :

For example,

ChromeOptions args :-

--enable-extension-activity-log-testing

--enable-unsafe-extension-debugging

--trusted-download-sources

--start-maximized

--ignore-certificate-errors

--disable-popup-blocking

--incognito

--enable-download-warning-improvements

--window-size=1920,900

EdgeOptions args :-

--start-maximized

--headless=new

This is the Browserstack SDK YAML configuration available capabilities file : Browserstack SDK capabilities and configuration YAML gist :

https://gist.github/prateeksabs/0532c79795463d5806234a320880d911

https://www.browserstack/docs/automate/selenium/sdk-faqs/generic/capability-priority

"In case both the browserstack.yml file and the test script define capabilities, which ones are prioritized? If you have capabilities declared in both the browserstack.yml file and in test scripts, the SDK merges these capabilities. However, if you have similar capabilities mentioned in both these locations, the capabilities in the browserstack.yml file take precedence."

This is how the RemoteWebDriver is configured in the browserstack SDK Sample project :

https://www.browserstack/docs/automate/selenium/getting-started/java/selenide

    @BeforeMethod(alwaysRun = true)
    public void setUp() throws Exception {
    MutableCapabilities capabilities = new MutableCapabilities();
    HashMap<String, String> bstackOptions = new HashMap<>();
    bstackOptions.put("source", "selenide:sample-master:v1.2");
    capabilities.setCapability("bstack:options", bstackOptions);
    driver = new RemoteWebDriver(new URL(String.format("https://%s:%s@hub- 
    cloud.browserstack/wd/hub", userName, accessKey)), capabilities);
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    WebDriverRunner.setWebDriver(driver);
}

This is the Browserstack Sample project YAML file:

https://gist.github/prateeksabs/0532c79795463d5806234a320880d911

I understand i could do something like the following for the chrome options :

    @BeforeMethod(alwaysRun = true)
    public void setUp() throws Exception {
    MutableCapabilities capabilities = new MutableCapabilities();
    HashMap<String, String> bstackOptions = new HashMap<>();
    bstackOptions.put("source", "selenide:sample-master:v1.2");
    capabilities.setCapability("bstack:options", bstackOptions);
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--headless=new");
    options.addArguments("window-size=1400,800");
    options.addArguments("disable-gpu");
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    driver = new RemoteWebDriver(new 
    URL(String.format("https://%s:%s@hub- 
    cloud.browserstack/wd/hub", userName, accessKey)), 
    capabilities);
}

(a) But would the capabilities be merged to the Chrome capabilities existing in the browserstack SDK YAML file (and it didn't work )

(b) Would this change break the other browserstack Edge and Safari sessions tied to the RemoteWebDriver

*Note this is a similar question to this question which didn't seem to answer the question: Setting language for Remotewebdriver - BrowserStack endpoint

Share Improve this question edited Feb 5 at 3:10 Krishnan Mahadevan 14.7k6 gold badges38 silver badges70 bronze badges asked Feb 2 at 20:43 MarkMark 231 silver badge6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The capabilities defined as part of the browserstack.yml file will take precedence when executing with the BrowserStack's SDK.

We can define the browser specific arguments in the yml file itself for each browsers. For example,

platforms:
- os: OS X
  osVersion: Big Sur
  browserName: Chrome
  browserVersion: latest
  chromeOptions: 
    args: 
    - incognito
    - --start-maximized

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745257391a4619038.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信