-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
isActive()
command to new Element API (#4261)
Co-authored-by: Priyansh Garg <[email protected]>
- Loading branch information
1 parent
7c14434
commit 0cf0f58
Showing
5 changed files
with
172 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 currently active/focused in the DOM. | ||
* | ||
* 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('isActive Demo', function() { | ||
* it('test isActive', function(browser) { | ||
* browser.element('#search') | ||
* .isActive() | ||
* .assert.equals(true); | ||
* }); | ||
* | ||
* it('test async isActive', async function(browser) { | ||
* const result = await browser.element('#search').isActive(); | ||
* browser.assert.equal(result, true); | ||
* }); | ||
* }); | ||
* | ||
* @since 3.9.0 | ||
* @method isActive | ||
* @memberof ScopedWebElement | ||
* @instance | ||
* @syntax browser.element.find(selector).isActive() | ||
* @link /#get-active-element | ||
* @returns {ScopedValue<boolean>} | ||
*/ | ||
module.exports.command = function () { | ||
return this.runQueuedCommandScoped('isElementActive'); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
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().isActive() command', function() { | ||
before(function (done) { | ||
CommandGlobals.beforeEach.call(this, done); | ||
}); | ||
|
||
after(function (done) { | ||
CommandGlobals.afterEach.call(this, done); | ||
}); | ||
|
||
it('test .element().isActive() active', async function() { | ||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/element/active', | ||
method: 'GET', | ||
response: JSON.stringify({ | ||
value: { | ||
'element-6066-11e4-a52e-4f735466cecf': '0' | ||
} | ||
}) | ||
}, true); | ||
|
||
const resultPromise = this.client.api.element('#signupSection').isActive(); | ||
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().isActive() not active', async function() { | ||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/element/active', | ||
method: 'GET', | ||
response: JSON.stringify({ | ||
value: { | ||
'element-6066-11e4-a52e-4f735466cecf': 'random-elem' | ||
} | ||
}) | ||
}, true); | ||
|
||
const resultPromise = this.client.api.element('#signupSection').isActive(); | ||
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().isActive()', async function() { | ||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/element/active', | ||
method: 'GET', | ||
response: JSON.stringify({ | ||
value: { | ||
'element-6066-11e4-a52e-4f735466cecf': '1' | ||
} | ||
}) | ||
}, true); | ||
|
||
const resultPromise = this.client.api.element('#signupSection').find('#helpBtn').isActive(); | ||
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().isActive() not active', async function() { | ||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/element/active', | ||
method: 'GET', | ||
response: JSON.stringify({ | ||
value: { | ||
'element-6066-11e4-a52e-4f735466cecf': 'random-elem' | ||
} | ||
}) | ||
}, true); | ||
|
||
const resultPromise = this.client.api.element.find('#signupSection').isActive(); | ||
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().isActive() assert', async function() { | ||
MockServer.addMock({ | ||
url: '/session/13521-10219-202/element/active', | ||
method: 'GET', | ||
response: JSON.stringify({ | ||
value: { | ||
'element-6066-11e4-a52e-4f735466cecf': '0' | ||
} | ||
}) | ||
}, true); | ||
|
||
const resultPromise = this.client.api.element('#signupSection').isActive(); | ||
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