From e97a90cd1bba4be87351ff8b16210ce6449935aa Mon Sep 17 00:00:00 2001 From: Udit Rajput <87136581+uditrajput03@users.noreply.github.com> Date: Wed, 13 Mar 2024 15:33:59 +0530 Subject: [PATCH] Added `isDisplayed()` as alias to `isVisible()` (#4107) --- lib/api/web-element/scoped-element.js | 3 +- .../api/commands/web-element/testIsVisible.js | 54 +++++++++++++++++++ types/tests/webElement.test-d.ts | 1 + types/web-element.d.ts | 1 + 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/lib/api/web-element/scoped-element.js b/lib/api/web-element/scoped-element.js index 69cd42123f..32b1e4f404 100644 --- a/lib/api/web-element/scoped-element.js +++ b/lib/api/web-element/scoped-element.js @@ -24,7 +24,8 @@ class ScopedWebElement { 'findAllByAltText': ['getAllByAltText'], 'getRect': ['getSize', 'getLocation'], 'getProperty': ['property'], - 'getCssProperty': ['css'] + 'getCssProperty': ['css'], + 'isVisible': ['isDisplayed'] }; } diff --git a/test/src/api/commands/web-element/testIsVisible.js b/test/src/api/commands/web-element/testIsVisible.js index c1ba6c9704..ed2fddf55a 100644 --- a/test/src/api/commands/web-element/testIsVisible.js +++ b/test/src/api/commands/web-element/testIsVisible.js @@ -41,6 +41,33 @@ describe('element().isVisible() command', function() { assert.strictEqual(elementId, '0'); }); + it('test .element().isDisplayed() displayed', async function() { + let elementId; + + MockServer.addMock({ + url: '/session/13521-10219-202/execute/sync', + method: 'POST', + response: JSON.stringify({ + value: true + }), + onRequest(_, requestData) { + elementId = requestData.args[0]['element-6066-11e4-a52e-4f735466cecf']; + } + }, true); + + const resultPromise = this.client.api.element('#signupSection').isDisplayed(); + 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); + assert.strictEqual(elementId, '0'); + }); + it('test .element().isVisible() not displayed', async function() { let elementId; @@ -68,6 +95,33 @@ describe('element().isVisible() command', function() { assert.strictEqual(elementId, '0'); }); + it('test .element().isDisplayed() not displayed', async function() { + let elementId; + + MockServer.addMock({ + url: '/session/13521-10219-202/execute/sync', + method: 'POST', + response: JSON.stringify({ + value: false + }), + onRequest(_, requestData) { + elementId = requestData.args[0]['element-6066-11e4-a52e-4f735466cecf']; + } + }, true); + + const resultPromise = this.client.api.element('#signupSection').isDisplayed(); + 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); + assert.strictEqual(elementId, '0'); + }); + it('test .element().find().isVisible()', async function() { let elementId; diff --git a/types/tests/webElement.test-d.ts b/types/tests/webElement.test-d.ts index 78edaa9015..8a3172f9f4 100644 --- a/types/tests/webElement.test-d.ts +++ b/types/tests/webElement.test-d.ts @@ -142,6 +142,7 @@ describe('new element() api', function () { expectType>(elem.getValue()); expectType>(elem.isEnabled()); expectType>(elem.isVisible()); + expectType>(elem.isDisplayed()); expectType>(elem.getRect()); expectType>(elem.getSize()); diff --git a/types/web-element.d.ts b/types/web-element.d.ts index dc2f87aa24..1547fc7ea9 100644 --- a/types/web-element.d.ts +++ b/types/web-element.d.ts @@ -194,6 +194,7 @@ export interface ScopedElement extends Element, PromiseLike { isEnabled(): ElementValue; isVisible(): ElementValue; + isDisplayed(): ElementValue; } type WaitUntilOptions = {