diff --git a/lib/runner/matchers/tags.js b/lib/runner/matchers/tags.js index 53a045616a..3556614a48 100644 --- a/lib/runner/matchers/tags.js +++ b/lib/runner/matchers/tags.js @@ -44,6 +44,15 @@ class TagsMatcher { const context = new Context({modulePath, settings}); context.setReloadModuleCache(); + + // Defining global browser object to make it available before nightwatch client created. + // To avoid errors like browser is not defined if testsuits has tags + Object.defineProperty(global, 'browser', { + configurable: true, + get: function() { + return {}; + } + }); try { if (this.usingMocha) { diff --git a/test/sampletests/tagswithbrowserobject/sample.js b/test/sampletests/tagswithbrowserobject/sample.js new file mode 100644 index 0000000000..018ead8bf0 --- /dev/null +++ b/test/sampletests/tagswithbrowserobject/sample.js @@ -0,0 +1,10 @@ +describe('Sample test with tags and global browser object', function() { + const globals = browser.globals; + this.tags = ['browser']; + it('demoTagTest', function(browser) { + browser + .url('http://localhost') + .assert.elementPresent('#weblogin') + .end(); + }); +}); \ No newline at end of file diff --git a/test/src/runner/testRunWithTags.js b/test/src/runner/testRunWithTags.js index c48a8951b9..fe222d8cb6 100644 --- a/test/src/runner/testRunWithTags.js +++ b/test/src/runner/testRunWithTags.js @@ -31,6 +31,24 @@ describe('testRunWithTags', function() { }); }); + it('testRunner with tags', function() { + const testsPath = path.join(__dirname, '../../sampletests'); + + return runTests({ + _source: [testsPath], + tag: ['browser'] + }, settings({ + output: false, + disable_typescript: true, + globals: { + reporter(results) { + assert.strictEqual(Object.keys(results.modules).length, 1); + assert.ok('demoTagTest' in results.modules[`tagswithbrowserobject${path.sep}sample`].completed); + } + } + })); + }); + it('testRunWithTags', function() { let testsPath = path.join(__dirname, '../../sampletests');