2

I've this setup in which I can use Nightwatch with mocha style

tests.js:

var nightwatch = require('nightwatch');
var config = require('./nightwatch.json');

describe('Github', function () {

    //var client = nightwatch.initClient(config.test_settings.default);
    var client = nightwatch.initClient(config);

    var browser = client.api();

    this.timeout(99999999);

    before(function () {
        browser.perform(function () {
            console.log('beforeAll')
        });

    });

    beforeEach(function (done) {
        browser.perform(function () {
            console.log('beforeEach')
        });

        client.start(done);
    });


    it('Demo test GitHub', function (done) {
        browser
            .url('https://github.com/nightwatchjs/nightwatch')
            .waitForElementVisible('body', 5000)
            .assert.title('GitHub - nightwatchjs/nightwatch: Automated testing and continous integration framework based on node.js and selenium webdriver');

        client.start(done);
    }); 
});

Which I execute as follows

$> ./node_modules/.bin/mocha ./tests.js

This works as long as I start the selenium-standalone myself. But what if I want to run my tests on Browserstack. Inside my nightwatch.json I can define "selenium" settings

{
    "src_folders": ["tests"],

    "selenium": {
        "start_process": false,
        "host": "hub-cloud.browserstack.com",
        "port": 80
    },

    "test_settings": {
        "default": {
            "desiredCapabilities": {
                 "browserstack.user": "my-username",
                 "browserstack.key": "my-access-key",
                 "browserstack.debug": true,
                 "browser": "IE",
                 "resolution": "1024x768",
                 "project": "nightwatch",
                 "build": "mocha"
            }
        }
   }
}

but that seems to be ignored. So the question is, considering the situation described above, how can I connect to a remote selenium server ?

Jeanluca Scaljeri
  • 26,343
  • 56
  • 205
  • 333
  • Referring to BrowserStack's sample code 'https://github.com/browserstack/nightwatch-browserstack/blob/master/conf/single.conf.js', it seems that you do not need "cli_args". Could you try dropping the "cli_args" key and add appropriate desiredCapabilities as shared in their sample code? – Mukesh Tiwari Feb 06 '17 at 18:26
  • I've update my post and basically copied all settings from [single.conf.js](https://github.com/browserstack/nightwatch-browserstack/blob/master/conf/single.conf.js) But still it tries to connect to a local running selenium-standalone hub – Jeanluca Scaljeri Feb 06 '17 at 20:31
  • Although I'm a step further, I get the feeling this is going the wrong way. Anyway after reading some of the Nightwatch code I figured out that you have to set `seleniumHost` and `seleniumPort` at the root level of the JSON. Furthermore, the selenium-hub url seems to work better if it has this format:`https://username:accesskey@hub-cloud.browserstack.com/wd/hub`. But now I get errors like: `"before each" hook: Uncaught Error: Uncaught, unspecified "error" event. ([object Object])` – Jeanluca Scaljeri Feb 06 '17 at 21:25

0 Answers0