-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restrict
suppressNotFoundErrors
to NoSuchElementError
in new Elem…
… API. (#4294) Co-authored-by: Priyansh Garg <[email protected]>
- Loading branch information
1 parent
1d6e122
commit 2f9fcf8
Showing
3 changed files
with
186 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test/sampletests/webelement/findWithSuppressNotFoundErrors.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
describe('test', function () { | ||
test('test find with suppressNotFoundErrors', async (browser) => { | ||
browser.element.find({ | ||
selector: browser.globals.selector, | ||
suppressNotFoundErrors: browser.globals.suppressNotFoundErrors | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const MockServer = require('../../../../lib/mockserver.js'); | ||
const Mocks = require('../../../../lib/command-mocks.js'); | ||
const CommandGlobals = require('../../../../lib/globals/commands-w3c.js'); | ||
const common = require('../../../../common.js'); | ||
const NightwatchClient = common.require('index.js'); | ||
const {settings} = common; | ||
|
||
describe('element().isPresent() command', function() { | ||
before(function (done) { | ||
CommandGlobals.beforeEach.call(this, done); | ||
|
||
}); | ||
|
||
after(function (done) { | ||
CommandGlobals.afterEach.call(this, done); | ||
}); | ||
|
||
it('test .element.find(suppressNotFoundErrors: true) suppresses NoSuchElementError', async function() { | ||
Mocks.createNewW3CSession(); | ||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/elements', | ||
method: 'POST', | ||
postdata: JSON.stringify({using: 'css selector', value: '#wrong'}), | ||
response: JSON.stringify({ | ||
value: [] | ||
}) | ||
}); | ||
|
||
let globalReporterCalled = false; | ||
|
||
const globals = { | ||
reporter(results) { | ||
globalReporterCalled = true; | ||
if (Object.prototype.hasOwnProperty.call(results, 'lastError')) { | ||
assert.notStrictEqual(results.lastError.name, 'NoSuchElementError'); | ||
} | ||
}, | ||
waitForConditionTimeout: 100, | ||
selector: '#wrong', | ||
suppressNotFoundErrors: true | ||
}; | ||
const testsPath = [ | ||
path.join(__dirname, '../../../../sampletests/webelement/findWithSuppressNotFoundErrors.js') | ||
]; | ||
|
||
await NightwatchClient.runTests(testsPath, settings({ | ||
globals, | ||
output_folder: 'output', | ||
selenium_host: null | ||
})); | ||
|
||
assert.strictEqual(globalReporterCalled, true); | ||
}); | ||
|
||
it('test .element.find(suppressNotFoundErrors: false) does not suppress NoSuchElementError', async function() { | ||
Mocks.createNewW3CSession(); | ||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/elements', | ||
method: 'POST', | ||
postdata: JSON.stringify({using: 'css selector', value: '#wrong'}), | ||
response: JSON.stringify({ | ||
value: [] | ||
}) | ||
}); | ||
|
||
let globalReporterCalled = false; | ||
|
||
const globals = { | ||
reporter(results) { | ||
globalReporterCalled = true; | ||
assert.strictEqual(results.lastError.name, 'NoSuchElementError'); | ||
}, | ||
waitForConditionTimeout: 100, | ||
selector: '#wrong', | ||
suppressNotFoundErrors: false | ||
}; | ||
const testsPath = [ | ||
path.join(__dirname, '../../../../sampletests/webelement/findWithSuppressNotFoundErrors.js') | ||
]; | ||
|
||
await NightwatchClient.runTests(testsPath, settings({ | ||
globals, | ||
output_folder: 'output', | ||
selenium_host: null | ||
})); | ||
|
||
assert.strictEqual(globalReporterCalled, true); | ||
}); | ||
|
||
it('test .element.find(suppressNotFoundErrors: true) does not suppress other errors', async function() { | ||
Mocks.createNewW3CSession(); | ||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/elements', | ||
method: 'POST', | ||
postdata: JSON.stringify({using: 'css selector', value: '@wrong'}), | ||
response: { | ||
value: { | ||
error: 'invalid selector', | ||
message: 'invalid selector', | ||
stacktrace: '' | ||
} | ||
}, | ||
statusCode: 400 | ||
}); | ||
|
||
let globalReporterCalled = false; | ||
|
||
const globals = { | ||
reporter(results) { | ||
globalReporterCalled = true; | ||
assert.strictEqual(results.lastError.name, 'InvalidSelectorError'); | ||
}, | ||
waitForConditionTimeout: 100, | ||
selector: '@wrong', | ||
suppressNotFoundErrors: true | ||
}; | ||
const testsPath = [ | ||
path.join(__dirname, '../../../../sampletests/webelement/findWithSuppressNotFoundErrors.js') | ||
]; | ||
|
||
await NightwatchClient.runTests(testsPath, settings({ | ||
globals, | ||
output_folder: 'output', | ||
selenium_host: null | ||
})); | ||
|
||
assert.strictEqual(globalReporterCalled, true); | ||
}); | ||
|
||
it('test .element.find(suppressNotFoundErrors: false) does not suppress other errors', async function() { | ||
Mocks.createNewW3CSession(); | ||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/elements', | ||
method: 'POST', | ||
postdata: JSON.stringify({using: 'css selector', value: '@wrong'}), | ||
response: { | ||
value: { | ||
error: 'invalid selector', | ||
message: 'invalid selector', | ||
stacktrace: '' | ||
} | ||
}, | ||
statusCode: 400 | ||
}); | ||
|
||
let globalReporterCalled = false; | ||
|
||
const globals = { | ||
reporter(results) { | ||
globalReporterCalled = true; | ||
assert.strictEqual(results.lastError.name, 'InvalidSelectorError'); | ||
}, | ||
waitForConditionTimeout: 100, | ||
selector: '@wrong', | ||
suppressNotFoundErrors: false | ||
}; | ||
const testsPath = [ | ||
path.join(__dirname, '../../../../sampletests/webelement/findWithSuppressNotFoundErrors.js') | ||
]; | ||
|
||
await NightwatchClient.runTests(testsPath, settings({ | ||
globals, | ||
output_folder: 'output', | ||
selenium_host: null | ||
})); | ||
|
||
assert.strictEqual(globalReporterCalled, true); | ||
}); | ||
}); |