Skip to content

Commit

Permalink
fix #3473: browser not defined issue (#3550)
Browse files Browse the repository at this point in the history
  • Loading branch information
prudhvi22 committed Jan 6, 2023
1 parent c5d95e1 commit 3667556
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/runner/matchers/tags.js
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions 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();
});
});
18 changes: 18 additions & 0 deletions test/src/runner/testRunWithTags.js
Expand Up @@ -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');

Expand Down

0 comments on commit 3667556

Please sign in to comment.