Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Feature request: enable flags/prefs in BrowserStack launcher #142

Open
kangyizhang opened this issue Mar 15, 2019 · 3 comments
Open

Feature request: enable flags/prefs in BrowserStack launcher #142

kangyizhang opened this issue Mar 15, 2019 · 3 comments

Comments

@kangyizhang
Copy link

Currently BowserStack launcher in karma customLaunchers can not set browser flags/prefs like other launchers whose base is 'Chrome' or 'Firefox'. Example of flags: https://github.com/karma-runner/karma-chrome-launcher#configuration

@luwes
Copy link

luwes commented Feb 16, 2020

would be great to have this feature

@Finesse
Copy link

Finesse commented Oct 12, 2020

I need this too to start browsers in incognito/private mode. This is what I've found so far. I've succeeded to make a Python code that starts incognito Chrome on Browserstack:

Python code
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from time import sleep
from datetime import datetime
import os

desired_cap = {
    "browser": "Chrome",
    "goog:chromeOptions": {
        "args": ["incognito", ],
        "w3c": False
    },
}

driver = webdriver.Remote(
    # The environment variable value must be 'http://your-username:your-password@hub-cloud.browserstack.com/wd/hub'
    command_executor=os.environ.get('BROWSERSTACK_HUB_URL'),
    desired_capabilities=desired_cap
)

print("Session: https://automate.browserstack.com/dashboard/v2/sessions/" + driver.session_id)
print("protocol w3c:" + str(driver.w3c))

driver.get("https://google.com/")
driver.quit()

I've tried to use the same capabilities in custom launchers in a Karma configuration. The capabilities have got to BrowserStack sessions (I can see them in "Input Capabilities"), but BrowserStack ignores them for some reason.

Karma configuration
// Karma configuration
// Generated on Wed Oct 07 2015 12:43:21 GMT+0530 (IST)

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',

    // hostname for local
    hostname: 'bs-local.com',

    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['qunit'],

    //plugins
    plugins: ['karma-qunit', 'karma-browserstack-launcher'],


    // list of files / patterns to load in the browser
    files: [
      'src/*.js',
      'tests/*.js'
    ],


    // list of files to exclude
    exclude: [
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress', 'BrowserStack'],


    // web server host and port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: false,

    browserStack: {
      username: process.env.BROWSERSTACK_USERNAME,
      accessKey: process.env.BROWSERSTACK_ACCESS_KEY,
      apiClientEndpoint: 'https://api.browserstack.com',
      build: String(Math.random()),
    },

    // define browsers
    customLaunchers: {
      bs_chrome_win: {
        base: 'BrowserStack',
        browser: 'Chrome',
        os: 'Windows',
        os_version: '10',
        'goog:chromeOptions': {
          args: ['incognito'],
          w3c: true,
        },
      },
      bs_chrome_mac: {
        base: 'BrowserStack',
        browser: 'Chrome',
        os: 'OS X',
        os_version: 'Catalina',
        'goog:chromeOptions': {
          args: ['incognito'],
          w3c: true,
        },
      },
      bs_firefox_win: {
        base: 'BrowserStack',
        browser: 'firefox',
        os: 'Windows',
        os_version: '10',
        'moz:firefoxOptions': {
          prefs: {
            'browser.privatebrowsing.autostart': true,
          },
        },
      },
      bs_firefox_mac: {
        base: 'BrowserStack',
        browser: 'firefox',
        os: 'OS X',
        os_version: 'Catalina',
        'moz:firefoxOptions': {
          prefs: {
            'browser.privatebrowsing.autostart': true,
          },
        },
      },
    },

    captureTimeout: 3e5,
    browserDisconnectTolerance: 0,
    browserDisconnectTimeout: 3e5,
    browserSocketTimeout: 1.2e5,
    browserNoActivityTimeout: 3e5,

    browsers: ['bs_chrome_win', 'bs_chrome_mac', 'bs_firefox_win', 'bs_firefox_mac'],
    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher

    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: true
  })
}

I've tried various other custom launcher settings, they all have started Chrome and Firefox in regular mode.

@Finesse
Copy link

Finesse commented Oct 13, 2020

This is what BrowserStack support says about passing keys to browsers from Karma:

Unfortunately, a PR to fix the runner may not work here as with the JS testing API, chromeOptions will not get honoured.

This would be a feature request with no ETA at the moment.

For every session that you initiate on Browserstack, you will be assigned a clean browser. In case you strictly need to use incognito mode, I will recommend switching to Selenium.

That being said, I have noted down your account details and will reach out to you once we have implemented the feature.

As far as I understand, this feature depends on BrowserStack and not on karma-browserstack-launcher unfortunately.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants