-
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.
Add missing
isSelected
command to new Element API. (#4038)
Co-authored-by: Priyansh Garg <priyanshgarg30@gmail.com> Co-authored-by: Vaibhav Singh <singh.vaibhav2011@gmail.com>
- Loading branch information
1 parent
ae23267
commit 8462c16
Showing
4 changed files
with
156 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Determines if an element is selected. | ||
* | ||
* For more info on working with DOM elements in Nightwatch, refer to the <a href="https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html">Finding & interacting with DOM Elements</a> guide page. | ||
* | ||
* @example | ||
* describe('isSelected Demo', function() { | ||
* it('test isSelected', function(browser) { | ||
* browser.element('#search') | ||
* .isSelected() | ||
* .assert.equals(true); | ||
* }); | ||
* | ||
* it('test async isSelected', async function(browser) { | ||
* const result = await browser.element('#search').isSelected(); | ||
* browser.assert.equal(result, true); | ||
* }); | ||
* }); | ||
* | ||
* @since 3.5.0 | ||
* @method isSelected | ||
* @memberof ScopedWebElement | ||
* @instance | ||
* @syntax browser.element(selector).isSelected() | ||
* @see https://www.w3.org/TR/webdriver/#is-element-selected | ||
* @returns {ScopedValue<boolean>} | ||
*/ | ||
module.exports.command = function () { | ||
return this.runQueuedCommandScoped('isElementSelected'); | ||
}; |
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,123 @@ | ||
const assert = require('assert'); | ||
const {WebElement} = require('selenium-webdriver'); | ||
const MockServer = require('../../../../lib/mockserver.js'); | ||
const CommandGlobals = require('../../../../lib/globals/commands-w3c.js'); | ||
const common = require('../../../../common.js'); | ||
const Element = common.require('element/index.js'); | ||
|
||
describe('element().isSelected() command', function() { | ||
before(function (done) { | ||
CommandGlobals.beforeEach.call(this, done); | ||
}); | ||
|
||
after(function (done) { | ||
CommandGlobals.afterEach.call(this, done); | ||
}); | ||
|
||
it('test .element().isSelected() selected', async function() { | ||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/element/0/selected', | ||
method: 'GET', | ||
response: JSON.stringify({ | ||
value: true | ||
}) | ||
}, true); | ||
|
||
const resultPromise = this.client.api.element('#signupSection').isSelected(); | ||
assert.strictEqual(resultPromise instanceof Element, false); | ||
assert.strictEqual(typeof resultPromise.find, 'undefined'); | ||
|
||
assert.strictEqual(resultPromise instanceof Promise, false); | ||
assert.strictEqual(typeof resultPromise.then, 'function'); | ||
|
||
const result = await resultPromise; | ||
assert.strictEqual(result instanceof WebElement, false); | ||
assert.strictEqual(result, true); | ||
|
||
}); | ||
|
||
it('test .element().isSelected() not selected', async function() { | ||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/element/0/selected', | ||
method: 'GET', | ||
response: JSON.stringify({ | ||
value: false | ||
}) | ||
}, true); | ||
|
||
const resultPromise = this.client.api.element('#signupSection').isSelected(); | ||
assert.strictEqual(resultPromise instanceof Element, false); | ||
assert.strictEqual(typeof resultPromise.find, 'undefined'); | ||
|
||
assert.strictEqual(resultPromise instanceof Promise, false); | ||
assert.strictEqual(typeof resultPromise.then, 'function'); | ||
|
||
const result = await resultPromise; | ||
assert.strictEqual(result instanceof WebElement, false); | ||
assert.strictEqual(result, false); | ||
}); | ||
|
||
it('test .element().find().isSelected()', async function() { | ||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/element/1/selected', | ||
method: 'GET', | ||
response: JSON.stringify({ | ||
value: true | ||
}) | ||
}, true); | ||
|
||
const resultPromise = this.client.api.element('#signupSection').find('#helpBtn').isSelected(); | ||
assert.strictEqual(resultPromise instanceof Element, false); | ||
assert.strictEqual(typeof resultPromise.find, 'undefined'); | ||
|
||
assert.strictEqual(resultPromise instanceof Promise, false); | ||
assert.strictEqual(typeof resultPromise.then, 'function'); | ||
|
||
const result = await resultPromise; | ||
assert.strictEqual(result instanceof WebElement, false); | ||
assert.strictEqual(result, true); | ||
}); | ||
|
||
it('test .element.find().isSelected() not selected', async function() { | ||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/element/0/selected', | ||
method: 'GET', | ||
response: JSON.stringify({ | ||
value: false | ||
}) | ||
}, true); | ||
|
||
const resultPromise = this.client.api.element.find('#signupSection').isSelected(); | ||
assert.strictEqual(resultPromise instanceof Element, false); | ||
assert.strictEqual(typeof resultPromise.find, 'undefined'); | ||
|
||
assert.strictEqual(resultPromise instanceof Promise, false); | ||
assert.strictEqual(typeof resultPromise.then, 'function'); | ||
|
||
const result = await resultPromise; | ||
assert.strictEqual(result instanceof WebElement, false); | ||
assert.strictEqual(result, false); | ||
}); | ||
|
||
it('test .element().isSelected() assert', async function() { | ||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/element/0/selected', | ||
method: 'GET', | ||
response: JSON.stringify({ | ||
value: true | ||
}) | ||
}, true); | ||
|
||
const resultPromise = this.client.api.element('#signupSection').isSelected(); | ||
assert.strictEqual(resultPromise instanceof Element, false); | ||
assert.strictEqual(typeof resultPromise.find, 'undefined'); | ||
|
||
assert.strictEqual(resultPromise instanceof Promise, false); | ||
assert.strictEqual(typeof resultPromise.then, 'function'); | ||
|
||
assert.strictEqual(await resultPromise.assert.equals(true), true); | ||
assert.strictEqual(await resultPromise.assert.not.equals(false), true); | ||
}); | ||
|
||
}); | ||
|
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
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