From d276adeb7a7e5f7e2e89a4aed69392f0feae6998 Mon Sep 17 00:00:00 2001 From: Ayush Vishwwakarma Date: Fri, 5 Apr 2024 00:37:52 +0530 Subject: [PATCH 1/3] feat: added aliases for getCssProperty --- .../web-element/commands/getCssProperty.js | 2 ++ lib/api/web-element/scoped-element.js | 2 +- .../web-element/testGetCssProperty.js | 36 +++++++++++++++++++ types/tests/webElement.test-d.ts | 2 ++ types/web-element.d.ts | 4 +++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/api/web-element/commands/getCssProperty.js b/lib/api/web-element/commands/getCssProperty.js index cbdb1d83cd..15fabc5b9b 100644 --- a/lib/api/web-element/commands/getCssProperty.js +++ b/lib/api/web-element/commands/getCssProperty.js @@ -37,6 +37,8 @@ * @see https://www.w3.org/TR/webdriver#get-element-css-value * @param {string} cssProperty The CSS property to inspect. * @returns {ScopedValue} The container with a value of the css property + * @alias css + * @alias getCssValue */ module.exports.command = function(cssProperty) { return this.runQueuedCommandScoped('getElementCSSValue', cssProperty); diff --git a/lib/api/web-element/scoped-element.js b/lib/api/web-element/scoped-element.js index 1aaee5f86c..b65528f2d9 100644 --- a/lib/api/web-element/scoped-element.js +++ b/lib/api/web-element/scoped-element.js @@ -24,7 +24,7 @@ class ScopedWebElement { 'findAllByAltText': ['getAllByAltText'], 'getRect': ['getSize', 'getLocation', 'rect'], 'getProperty': ['property'], - 'getCssProperty': ['css'], + 'getCssProperty': ['css', 'getCssValue'], 'isVisible': ['isDisplayed'] }; } diff --git a/test/src/api/commands/web-element/testGetCssProperty.js b/test/src/api/commands/web-element/testGetCssProperty.js index 3a29befa2d..bf03208971 100644 --- a/test/src/api/commands/web-element/testGetCssProperty.js +++ b/test/src/api/commands/web-element/testGetCssProperty.js @@ -135,4 +135,40 @@ describe('element().getCssProperty() command', function () { assert.strictEqual(await resultPromise.assert.not.contains('150x'), '150px'); assert.strictEqual(await resultPromise.assert.not.matches(/150[a-z]{2}x/), '150px'); }); + + // Extra tests + it('test browser.element().css()', async function () { + + + const resultPromise = this.client.api.element('#signupSection').css('height'); + 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, '150px'); + + const resultValue = await resultPromise.value; + assert.strictEqual(resultValue, '150px'); + }); + + it('test browser.element().getCssValue()', async function () { + const resultPromise = this.client.api.element('#signupSection').getCssValue('height'); + 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, '150px'); + + const resultValue = await resultPromise.value; + assert.strictEqual(resultValue, '150px'); + }) ; + }); diff --git a/types/tests/webElement.test-d.ts b/types/tests/webElement.test-d.ts index ed24c4f518..4c2b8fab9a 100644 --- a/types/tests/webElement.test-d.ts +++ b/types/tests/webElement.test-d.ts @@ -152,6 +152,8 @@ describe('new element() api', function () { expectType>(elem.getAccessibleName()); expectType>(elem.getAriaRole()); expectType>(elem.getCssProperty('height')); + expectType>(elem.css('height')); + expectType>(elem.getCssValue('height')); expectType>(elem.takeScreenshot()); expectType>(elem.click()); diff --git a/types/web-element.d.ts b/types/web-element.d.ts index d8fc0c7169..9e5f65edf4 100644 --- a/types/web-element.d.ts +++ b/types/web-element.d.ts @@ -181,6 +181,10 @@ export interface ScopedElement extends Element, PromiseLike { getCssProperty(name: string): ElementValue; + css(name: string): ElementValue; + + getCssValue(name: string): ElementValue; + getValue(): ElementValue; setValue(...keys: E): Promise; From efe394532f4d59cd123efd2fa8fecfd4fc6bb4a9 Mon Sep 17 00:00:00 2001 From: Ayush Vishwwakarma Date: Wed, 17 Apr 2024 21:00:37 +0530 Subject: [PATCH 2/3] Refactored code: formatting improvements and deleted alias in jsDocs --- lib/api/web-element/commands/getCssProperty.js | 2 -- types/web-element.d.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/lib/api/web-element/commands/getCssProperty.js b/lib/api/web-element/commands/getCssProperty.js index 15fabc5b9b..cbdb1d83cd 100644 --- a/lib/api/web-element/commands/getCssProperty.js +++ b/lib/api/web-element/commands/getCssProperty.js @@ -37,8 +37,6 @@ * @see https://www.w3.org/TR/webdriver#get-element-css-value * @param {string} cssProperty The CSS property to inspect. * @returns {ScopedValue} The container with a value of the css property - * @alias css - * @alias getCssValue */ module.exports.command = function(cssProperty) { return this.runQueuedCommandScoped('getElementCSSValue', cssProperty); diff --git a/types/web-element.d.ts b/types/web-element.d.ts index 9e5f65edf4..fc3b68111c 100644 --- a/types/web-element.d.ts +++ b/types/web-element.d.ts @@ -180,9 +180,7 @@ export interface ScopedElement extends Element, PromiseLike { getAriaRole(): ElementValue; getCssProperty(name: string): ElementValue; - css(name: string): ElementValue; - getCssValue(name: string): ElementValue; getValue(): ElementValue; From 49444d06752e9a87de350695746da24eda93eb03 Mon Sep 17 00:00:00 2001 From: Ayush Vishwwakarma Date: Thu, 18 Apr 2024 16:18:14 +0530 Subject: [PATCH 3/3] Refactored Code: formatted test Cases --- .../web-element/testGetCssProperty.js | 59 ++++++++----------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/test/src/api/commands/web-element/testGetCssProperty.js b/test/src/api/commands/web-element/testGetCssProperty.js index bf03208971..fc47439939 100644 --- a/test/src/api/commands/web-element/testGetCssProperty.js +++ b/test/src/api/commands/web-element/testGetCssProperty.js @@ -63,6 +63,30 @@ describe('element().getCssProperty() command', function () { assert.strictEqual(resultValue, '150px'); }); + it('test .element().getCssValue() alias', async function() { + MockServer.addMock({ + url: '/session/13521-10219-202/element/0/css/height', + method: 'GET', + response: JSON.stringify({ + value: '150px' + }) + }, true); + + const resultPromise = this.client.api.element('#signupSection').getCssValue('height'); + 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, '150px'); + + const resultValue = await resultPromise.value; + assert.strictEqual(resultValue, '150px'); + }); + it('test .element().find().getCssProperty()', async function() { MockServer.addMock({ url: '/session/13521-10219-202/element/1/css/height', @@ -135,40 +159,5 @@ describe('element().getCssProperty() command', function () { assert.strictEqual(await resultPromise.assert.not.contains('150x'), '150px'); assert.strictEqual(await resultPromise.assert.not.matches(/150[a-z]{2}x/), '150px'); }); - - // Extra tests - it('test browser.element().css()', async function () { - - - const resultPromise = this.client.api.element('#signupSection').css('height'); - 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, '150px'); - - const resultValue = await resultPromise.value; - assert.strictEqual(resultValue, '150px'); - }); - - it('test browser.element().getCssValue()', async function () { - const resultPromise = this.client.api.element('#signupSection').getCssValue('height'); - 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, '150px'); - - const resultValue = await resultPromise.value; - assert.strictEqual(resultValue, '150px'); - }) ; });