Skip to content

Commit

Permalink
fix#3473: browser not defined issue
Browse files Browse the repository at this point in the history
  • Loading branch information
prudhvi22 committed Jan 5, 2023
1 parent c5d95e1 commit 34b9165
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
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
1 change: 1 addition & 0 deletions snpashot.html
@@ -0,0 +1 @@
<!DOCTYPE html><html class="no-js" lang=""><head><base href="https://nightwatchjs.org"> <meta charset="utf-8"> <title></title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta property="og:title" content=""> <meta property="og:type" content=""> <meta property="og:url" content=""> <meta property="og:image" content=""> <link rel="manifest" href="site.webmanifest"> <link rel="apple-touch-icon" href="icon.png"> <link rel="stylesheet" href="css/normalize.css"> <link rel="stylesheet" href="css/main.css"> <meta name="theme-color" content="#fafafa"></head><body> <p>Hello world! This is HTML5 Boilerplate.</p> </body></html>
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();
});
});
1 change: 0 additions & 1 deletion test/sampletests/trace/sample.js
@@ -1,5 +1,4 @@
describe('Sample test with traceable commands', function() {

before(browser => {
browser
.navigateTo('http://localhost');
Expand Down
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 34b9165

Please sign in to comment.