Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #3473: browser not defined issue #3550

Merged
merged 2 commits into from Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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