Skip to content

Commit

Permalink
Merge branch 'alias-branch' of https://github.com/its-kunal/nightwatch
Browse files Browse the repository at this point in the history
…into alias-branch
  • Loading branch information
its-kunal committed Feb 29, 2024
2 parents afaea28 + d9a3daf commit 2408285
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/api/web-element/commands/isEnabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Determines if an element is enabled.
*
* 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('isEnabled Demo', function() {
* it('test isEnabled', function(browser) {
* browser.element('#search')
* .isEnabled()
* .assert.equals(true);
* });
*
* it('test async isEnabled', async function(browser) {
* const result = await browser.element('#search').isEnabled();
* browser.assert.equal(result, true);
* });
* });
*
* @since 3.5.0
* @method isEnabled
* @memberof ScopedWebElement
* @instance
* @syntax browser.element(selector).isEnabled()
* @see https://www.w3.org/TR/webdriver/#is-element-enabled
* @returns {ScopedValue<boolean>}
*/
module.exports.command = function () {
return this.runQueuedCommandScoped('isElementEnabled');
};
30 changes: 30 additions & 0 deletions lib/api/web-element/commands/isSelected.js
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');
};
122 changes: 122 additions & 0 deletions test/src/api/commands/web-element/testIsEnabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
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().isEnabled() command', function() {
before(function (done) {
CommandGlobals.beforeEach.call(this, done);
});

after(function (done) {
CommandGlobals.afterEach.call(this, done);
});

it('test .element().isEnabled() enabled', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/element/0/enabled',
method: 'GET',
response: JSON.stringify({
value: true
})
}, true);

const resultPromise = this.client.api.element('#signupSection').isEnabled();
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().isEnabled() not enabled', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/element/0/enabled',
method: 'GET',
response: JSON.stringify({
value: false
})
}, true);

const resultPromise = this.client.api.element('#signupSection').isEnabled();
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().isEnabled()', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/element/1/enabled',
method: 'GET',
response: JSON.stringify({
value: true
})
}, true);

const resultPromise = this.client.api.element('#signupSection').find('#helpBtn').isEnabled();
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().isEnabled() not enabled', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/element/0/enabled',
method: 'GET',
response: JSON.stringify({
value: false
})
}, true);

const resultPromise = this.client.api.element.find('#signupSection').isEnabled();
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().isEnabled() assert', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/element/0/enabled',
method: 'GET',
response: JSON.stringify({
value: true
})
}, true);

const resultPromise = this.client.api.element('#signupSection').isEnabled();
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);
});

});
123 changes: 123 additions & 0 deletions test/src/api/commands/web-element/testIsSelected.js
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);
});

});

2 changes: 2 additions & 0 deletions types/tests/webElement.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ describe('new element() api', function () {
expectType<ElementValue<string | null>>(elem.getProperty('property-name'));
expectType<ElementValue<string | null>>(elem.getAttribute('attrib-name'));
expectType<ElementValue<string | null>>(elem.getValue());
expectType<ElementValue<boolean>>(elem.isEnabled());

expectType<ElementValue<ScopedElementRect>>(elem.getRect());
expectType<ElementValue<ScopedElementRect>>(elem.getSize());
Expand All @@ -165,6 +166,7 @@ describe('new element() api', function () {
expectType<Promise<WebElement>>(elem.doubleClick());
expectType<Promise<WebElement>>(elem.rightClick());
expectType<Promise<WebElement>>(elem.waitUntil('visible', {timeout: 5000}));
expectType<ElementValue<boolean>>(elem.isSelected());
});

test('test element assertions', async function () {
Expand Down
7 changes: 7 additions & 0 deletions types/web-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ export interface ScopedElement extends Element, PromiseLike<WebElement> {
signalOrOptions: WaitUntilActions | WaitUntilOptions,
waitOptions?: WaitUntilOptions
): Promise<WebElement>;

isSelected(): ElementValue<boolean>;

waitUntil(signalOrOptions: WaitUntilActions | WaitUntilOptions, waitOptions?: WaitUntilOptions): Promise<WebElement>;

isEnabled(): ElementValue<boolean>;

}

type WaitUntilOptions = {
Expand Down

0 comments on commit 2408285

Please sign in to comment.