Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing isVisible command in new Element API #4039

Merged
merged 22 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e9eb01c
Added missing isVisible command in new Element API
subhajit20 Feb 22, 2024
d672dde
Added missing isVisible command in new Element API
subhajit20 Feb 22, 2024
73b21ac
Added return type as scopedvalue and removed unwanted changes
subhajit20 Feb 23, 2024
76c985d
Added test for isVisible command
subhajit20 Feb 23, 2024
28fffd5
Added js doc for the command and changed types
subhajit20 Feb 23, 2024
8b8cc77
Added test for visible command
subhajit20 Feb 23, 2024
4b78d85
Added visible command inside command folder
subhajit20 Feb 23, 2024
4d1e0e3
Tested visible command and added test for command
subhajit20 Feb 24, 2024
8273e71
Added a failed test and added since 3.5.0
subhajit20 Feb 26, 2024
b752715
Added successfull and failed test
subhajit20 Feb 26, 2024
0f55dad
Made minor changes on JSDoc and test file
subhajit20 Feb 29, 2024
16e73d6
Removed test
subhajit20 Mar 1, 2024
923c598
Resolving conflicts
subhajit20 Mar 1, 2024
6a15db0
Merge branch 'main' into issue/4037
subhajit20 Mar 1, 2024
fd57d2c
Resolving merge conflicts
subhajit20 Mar 1, 2024
ce6ad30
Added minor formatting changes
subhajit20 Mar 1, 2024
339f65a
Added spaces on 34 and 84 n0 line of ts test file
subhajit20 Mar 1, 2024
91139ca
Added test for isVisisble command
subhajit20 Mar 1, 2024
fe359cf
Added minor changes inside test file of visible command
subhajit20 Mar 1, 2024
634abfd
Fixed test and added aliases of visible command
subhajit20 Mar 2, 2024
0d9352e
Added specification of visible command
subhajit20 Mar 2, 2024
522954b
Fix tests and some refactors.
garg3133 Mar 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/api/web-element/commands/isVisible.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Returns the visible text for the element.
subhajit20 marked this conversation as resolved.
Show resolved Hide resolved
*
* 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('isVisible Demo', function() {
* it('test isVisible', function(browser) {
* browser.element('#search').isVisible().assert.equals(true);
* });
*
* it('test async isVisible', async function(browser) {
* const result = await browser.element('#search').isVisible();
* browser.assert.equal(result, true);
* });
* });
*
* @since 3.5.0
* @method isVisible
* @memberof ScopedWebElement
* @instance
* @syntax browser.element(selector).isVisible()
* @see https://www.w3.org/TR/webdriver/#element-displayedness
* @returns {ScopedValue<boolean>}
*/
module.exports.command = function() {
return this.runQueuedCommandScoped('isElementDisplayed');
};
58 changes: 58 additions & 0 deletions test/src/api/commands/web-element/testIsVisible.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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().isVisible() command', function() {
subhajit20 marked this conversation as resolved.
Show resolved Hide resolved
before(function(done) {
CommandGlobals.beforeEach.call(this, done);
});

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

it('test .element().isVisible() Visible', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/element/0/Visible',
subhajit20 marked this conversation as resolved.
Show resolved Hide resolved
method: 'GET',
response: JSON.stringify({
value: true
})
}, true);

this.client.api.element('#search').isVisible(function(result) {
this.assert.equal(result.value, true);
});
subhajit20 marked this conversation as resolved.
Show resolved Hide resolved
});

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

this.client.api.element('#search').isVisible(function(result) {
this.assert.equal(result.value, true);
});
});

it('test .element().find().isVisible() not visible', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/element/0/displayed',
method: 'GET',
response: JSON.stringify({
value: false
})
}, true);

this.client.api.element('#signupSection').find('#helpBtn').isVisible(function(result) {
this.assert.equal(result.value, true);
});
});
});
3 changes: 2 additions & 1 deletion types/tests/webElement.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ describe('new element() api', function () {
expectType<ElementValue<string | null>>(elem.getAttribute('attrib-name'));
expectType<ElementValue<string | null>>(elem.getValue());
expectType<ElementValue<boolean>>(elem.isEnabled());
expectType<ElementValue<boolean>>(elem.isVisible());

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

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

isEnabled(): ElementValue<boolean>;

isVisible(): ElementValue<boolean>
}

type WaitUntilOptions = {
Expand Down
Loading