Protractor: WebDriverError: Authorization required when using browserstack after upgrading to 4.x

Created on 10 Aug 2016  Â·  9Comments  Â·  Source: angular/protractor

Bug report

  • Node Version: 6.3.1
  • Protractor Version: 4.0.3
  • Browser(s): chrome
  • Operating System and Version OSX 10.11.4
  • Your protractor configuration file
exports.config = {
  framework: 'jasmine2',
  seleniumAddress: 'http://hub-cloud.browserstack.com/wd/hub',
  browserstackUser: '<insert username>',
  browserstackKey: '<insert api key>'
};
  • A relevant example test

Doesn't really matter as protractor never gets to run the test anyway, but this will do:

browser.ignoreSynchronization = true;

describe('test', function() {
  it('should open google', function() {
    browser.get('https://google.com');
      browser.getTitle();
  });
});
  • Output from running the test
➜  functional-tests git:(upgrade-protractor) ✗ node_modules/.bin/protractor resources/configs/debug-config.js --troubleshoot --specs tests/google-spec.js
[14:42:57] I/hosted - Using the selenium server at http://hub-cloud.browserstack.com/wd/hub
[14:42:57] I/launcher - Running 1 instances of WebDriver
[14:42:57] E/launcher - Authorization required
[14:42:57] E/launcher - WebDriverError: Authorization required
    at WebDriverError (/Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/selenium-webdriver/lib/error.js:27:5)
        at parseHttpResponse (/Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/selenium-webdriver/http/index.js:554:11)
        at client_.send.then.response (/Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/selenium-webdriver/http/index.js:472:11)
            at ManagedPromise.invokeCallback_ (/Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/selenium-webdriver/lib/promise.js:1379:14)
            at TaskQueue.execute_ (/Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/selenium-webdriver/lib/promise.js:2913:14)
                at TaskQueue.executeNext_ (/Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/selenium-webdriver/lib/promise.js:2896:21)
                at asyncRun (/Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/selenium-webdriver/lib/promise.js:2820:25)
                    at /Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/selenium-webdriver/lib/promise.js:639:7
                    at process._tickCallback (internal/process/next_tick.js:103:7)
                    From: Task: WebDriver.createSession()
                        at Function.createSession (/Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/selenium-webdriver/lib/webdriver.js:329:24)
                        at Builder.build (/Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/selenium-webdriver/builder.js:458:24)
                            at Hosted.DriverProvider.getNewDriver (/Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/protractor/built/driverProviders/driverProvider.js:37:33)
                            at Runner.createBrowser (/Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/protractor/built/runner.js:187:43)
                                at /Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/protractor/built/runner.js:261:30
                                at _fulfilled (/Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/q/q.js:834:54)
                                    at self.promiseDispatch.done (/Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/q/q.js:863:30)
                                    at Promise.promise.promiseDispatch (/Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/q/q.js:796:13)
                                        at /Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/q/q.js:556:49
                                        at runSingle (/Users/testower/Developer/kahoot/mobitroll-kahoot/functional-tests/node_modules/q/q.js:137:13)
                                        [14:42:57] E/launcher - Process exited with error code 199
  • Steps to reproduce the bug
protractor config.js --specs test-spec.js
untriaged needs more info enhancement

Most helpful comment

Could someone please give an example of a protractor config that works? I've tried adding the browserstack.key and browserstack.user to base protractor.config, but that still gives me the unauthorized exception. A sample would be amazing and greatly appreciated.

All 9 comments

The issue seems to be that you can't give the seleniumAddress in the config when using browserstack with protractor@4. This makes it impossible to give the username and key via the capabilities object as recommended by browserstack, but has to be given in the config.

In summary: I used to be able to give the username and api key for browserstack on the command line. I can't see that's any longer possible. This is quite crucial to maintain the secrecy of the key.

You can use environment variables for the BrowserStack credentials

Yes, I just realized that from browsing through the test code in the protractor repository. I really think this should be mentioned in breaking changes though.

  1. If you are using a seleniumAddress in the config, browserstack will not run based on how loading the driver provider works. https://github.com/angular/protractor/blob/master/lib/runner.ts#L93. This is also similar to 3.2 prior to switching over to TypeScript https://github.com/angular/protractor/blob/3.2.0/lib/runner.js#L91.

    Enhancement: Because configurations only loads a single driver provider we should warn the user if there are other fields that are potentially being ignored. In the case above: we launched with the selenium address and also warn that there are browserstack variables.

  2. After removing seleniumAddress from your config, you should be able to use the --browserstackUser and --browserstackKey. This should work.

Could someone please give an example of a protractor config that works? I've tried adding the browserstack.key and browserstack.user to base protractor.config, but that still gives me the unauthorized exception. A sample would be amazing and greatly appreciated.

Hi,

I got this error this morning and I still can not find a feasible solution

@johnnyezzell @djom20 Example configs can be found here: https://github.com/browserstack/protractor-browserstack/tree/master/conf

The problem that I had was that I still had the seleniumAddress param in my conf file when it's not needed with the browserstack-local dependency (see package.json in above repo). Also, I originally had browserstack.user and browserstack.key in the capabilities block when they should have been outside the block (as per the linked examples above). Just don't forget to update this line exports.bs_local.start({'key': exports.config['browserstackKey'] }, function(error) and make sure it matches what's in your exports.config block.

Sorry for the almost 1 year respond, but this was troubling me as well for a few days and I had to give me results in, hopefully, a fix.

Was this page helpful?
0 / 5 - 0 ratings