From 56608ecdd66b2ca22b1d5c6af82a70102c4d8e87 Mon Sep 17 00:00:00 2001 From: Ayush Vishwwakarma Date: Sun, 7 Apr 2024 19:44:15 +0530 Subject: [PATCH 1/3] Added prop and property as an alias for getProperty --- lib/api/web-element/commands/getProperty.js | 2 + lib/api/web-element/scoped-element.js | 2 +- .../commands/web-element/testGetProperty.js | 49 +++++++++++++++++++ types/tests/webElement.test-d.ts | 2 + types/web-element.d.ts | 4 ++ 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/lib/api/web-element/commands/getProperty.js b/lib/api/web-element/commands/getProperty.js index 934f7b158d..e41ab8d378 100644 --- a/lib/api/web-element/commands/getProperty.js +++ b/lib/api/web-element/commands/getProperty.js @@ -39,6 +39,8 @@ * @syntax browser.element(selector).getProperty(name) * @see https://www.w3.org/TR/webdriver#get-element-property * @returns {ScopedValue} + * @alias prop + * @alias property */ module.exports.command = function(name) { return this.runQueuedCommandScoped('getElementProperty', name); diff --git a/lib/api/web-element/scoped-element.js b/lib/api/web-element/scoped-element.js index 1aaee5f86c..472551eaad 100644 --- a/lib/api/web-element/scoped-element.js +++ b/lib/api/web-element/scoped-element.js @@ -23,7 +23,7 @@ class ScopedWebElement { 'findAllByPlaceholderText': ['getAllByPlaceholderText'], 'findAllByAltText': ['getAllByAltText'], 'getRect': ['getSize', 'getLocation', 'rect'], - 'getProperty': ['property'], + 'getProperty': ['property', 'prop'], 'getCssProperty': ['css'], 'isVisible': ['isDisplayed'] }; diff --git a/test/src/api/commands/web-element/testGetProperty.js b/test/src/api/commands/web-element/testGetProperty.js index b68b8c3dbe..7aa423786e 100644 --- a/test/src/api/commands/web-element/testGetProperty.js +++ b/test/src/api/commands/web-element/testGetProperty.js @@ -109,4 +109,53 @@ describe('element().getProperty() command', function () { const resultValue = await resultPromise.value; assert.deepStrictEqual(resultValue, ['.signup']); }); + + it('test .element.find().prop()', async function() { + MockServer.addMock({ + url: '/session/13521-10219-202/element/0/property/classList', + method: 'GET', + response: JSON.stringify({ + value: ['.signup'] + }) + }, true); + + const resultPromise = this.client.api.element.find('#signupSection').prop('classList'); + 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.deepStrictEqual(result, ['.signup']); + + const resultValue = await resultPromise.value; + assert.deepStrictEqual(resultValue, ['.signup']); + }); + + it('test .element().find().property()', async function(){ + MockServer.addMock({ + url: '/session/13521-10219-202/element/1/property/classList', + method: 'GET', + response: JSON.stringify({ + value: ['.btn'] + }) + }, true); + + const resultPromise = this.client.api.element('#signupSection').find('#helpBtn').property('classList'); + 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.deepStrictEqual(result, ['.btn']); + + const resultValue = await resultPromise.value; + assert.deepStrictEqual(resultValue, ['.btn']); + }); + }); diff --git a/types/tests/webElement.test-d.ts b/types/tests/webElement.test-d.ts index ed24c4f518..68a3ff6119 100644 --- a/types/tests/webElement.test-d.ts +++ b/types/tests/webElement.test-d.ts @@ -138,6 +138,8 @@ describe('new element() api', function () { expectType>(elem.getText()); expectType>(elem.getProperty('property-name')); + expectType>(elem.prop('property-name')); + expectType>(elem.property('property-name')); expectType>(elem.getAttribute('attrib-name')); expectType>(elem.getValue()); expectType>(elem.isEnabled()); diff --git a/types/web-element.d.ts b/types/web-element.d.ts index d8fc0c7169..ab11fc5695 100644 --- a/types/web-element.d.ts +++ b/types/web-element.d.ts @@ -159,6 +159,10 @@ export interface ScopedElement extends Element, PromiseLike { getProperty(name: string): ElementValue; + prop(name: string): ElementValue; + + property(name: string): ElementValue; + setProperty(name: string, value: unknown): Promise; getAttribute(name: string): ElementValue; From 6ede6b9710fbf0798ad58ffa9fcd697ec4629ae8 Mon Sep 17 00:00:00 2001 From: Ayush Vishwwakarma Date: Wed, 17 Apr 2024 19:16:46 +0530 Subject: [PATCH 2/3] Refactored code: formatting improvements and deleted alias in jsDocs --- lib/api/web-element/commands/getProperty.js | 2 - .../commands/web-element/testGetProperty.js | 54 ++++++------------- types/web-element.d.ts | 2 - 3 files changed, 15 insertions(+), 43 deletions(-) diff --git a/lib/api/web-element/commands/getProperty.js b/lib/api/web-element/commands/getProperty.js index e41ab8d378..934f7b158d 100644 --- a/lib/api/web-element/commands/getProperty.js +++ b/lib/api/web-element/commands/getProperty.js @@ -39,8 +39,6 @@ * @syntax browser.element(selector).getProperty(name) * @see https://www.w3.org/TR/webdriver#get-element-property * @returns {ScopedValue} - * @alias prop - * @alias property */ module.exports.command = function(name) { return this.runQueuedCommandScoped('getElementProperty', name); diff --git a/test/src/api/commands/web-element/testGetProperty.js b/test/src/api/commands/web-element/testGetProperty.js index 7aa423786e..f48205e396 100644 --- a/test/src/api/commands/web-element/testGetProperty.js +++ b/test/src/api/commands/web-element/testGetProperty.js @@ -62,31 +62,7 @@ describe('element().getProperty() command', function () { assert.deepStrictEqual(resultValue, ['.signup']); }); - it('test .element().find().getProperty()', async function() { - MockServer.addMock({ - url: '/session/13521-10219-202/element/1/property/classList', - method: 'GET', - response: JSON.stringify({ - value: ['.btn'] - }) - }, true); - - const resultPromise = this.client.api.element('#signupSection').find('#helpBtn').getProperty('classList'); - 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.deepStrictEqual(result, ['.btn']); - - const resultValue = await resultPromise.value; - assert.deepStrictEqual(resultValue, ['.btn']); - }); - - it('test .element.find().getProperty()', async function() { + it('test .element.find().prop()', async function() { MockServer.addMock({ url: '/session/13521-10219-202/element/0/property/classList', method: 'GET', @@ -95,7 +71,7 @@ describe('element().getProperty() command', function () { }) }, true); - const resultPromise = this.client.api.element.find('#signupSection').getProperty('classList'); + const resultPromise = this.client.api.element.find('#signupSection').prop('classList'); assert.strictEqual(resultPromise instanceof Element, false); assert.strictEqual(typeof resultPromise.find, 'undefined'); @@ -109,17 +85,17 @@ describe('element().getProperty() command', function () { const resultValue = await resultPromise.value; assert.deepStrictEqual(resultValue, ['.signup']); }); - - it('test .element.find().prop()', async function() { + + it('test .element().find().getProperty()', async function() { MockServer.addMock({ - url: '/session/13521-10219-202/element/0/property/classList', + url: '/session/13521-10219-202/element/1/property/classList', method: 'GET', response: JSON.stringify({ - value: ['.signup'] + value: ['.btn'] }) }, true); - const resultPromise = this.client.api.element.find('#signupSection').prop('classList'); + const resultPromise = this.client.api.element('#signupSection').find('#helpBtn').getProperty('classList'); assert.strictEqual(resultPromise instanceof Element, false); assert.strictEqual(typeof resultPromise.find, 'undefined'); @@ -128,22 +104,22 @@ describe('element().getProperty() command', function () { const result = await resultPromise; assert.strictEqual(result instanceof WebElement, false); - assert.deepStrictEqual(result, ['.signup']); + assert.deepStrictEqual(result, ['.btn']); const resultValue = await resultPromise.value; - assert.deepStrictEqual(resultValue, ['.signup']); + assert.deepStrictEqual(resultValue, ['.btn']); }); - it('test .element().find().property()', async function(){ + it('test .element.find().getProperty()', async function() { MockServer.addMock({ - url: '/session/13521-10219-202/element/1/property/classList', + url: '/session/13521-10219-202/element/0/property/classList', method: 'GET', response: JSON.stringify({ - value: ['.btn'] + value: ['.signup'] }) }, true); - const resultPromise = this.client.api.element('#signupSection').find('#helpBtn').property('classList'); + const resultPromise = this.client.api.element.find('#signupSection').getProperty('classList'); assert.strictEqual(resultPromise instanceof Element, false); assert.strictEqual(typeof resultPromise.find, 'undefined'); @@ -152,10 +128,10 @@ describe('element().getProperty() command', function () { const result = await resultPromise; assert.strictEqual(result instanceof WebElement, false); - assert.deepStrictEqual(result, ['.btn']); + assert.deepStrictEqual(result, ['.signup']); const resultValue = await resultPromise.value; - assert.deepStrictEqual(resultValue, ['.btn']); + assert.deepStrictEqual(resultValue, ['.signup']); }); }); diff --git a/types/web-element.d.ts b/types/web-element.d.ts index ab11fc5695..cd4d45e3f7 100644 --- a/types/web-element.d.ts +++ b/types/web-element.d.ts @@ -158,9 +158,7 @@ export interface ScopedElement extends Element, PromiseLike { submit(): Promise; getProperty(name: string): ElementValue; - prop(name: string): ElementValue; - property(name: string): ElementValue; setProperty(name: string, value: unknown): Promise; From 9afa6238579751a2a52a13e911bf950793267d5f Mon Sep 17 00:00:00 2001 From: Priyansh Garg Date: Wed, 17 Apr 2024 20:34:00 +0530 Subject: [PATCH 3/3] Small fix in test. --- test/src/api/commands/web-element/testGetProperty.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/src/api/commands/web-element/testGetProperty.js b/test/src/api/commands/web-element/testGetProperty.js index f48205e396..58dca8697c 100644 --- a/test/src/api/commands/web-element/testGetProperty.js +++ b/test/src/api/commands/web-element/testGetProperty.js @@ -62,7 +62,7 @@ describe('element().getProperty() command', function () { assert.deepStrictEqual(resultValue, ['.signup']); }); - it('test .element.find().prop()', async function() { + it('test .element().prop() alias', async function() { MockServer.addMock({ url: '/session/13521-10219-202/element/0/property/classList', method: 'GET', @@ -71,7 +71,7 @@ describe('element().getProperty() command', function () { }) }, true); - const resultPromise = this.client.api.element.find('#signupSection').prop('classList'); + const resultPromise = this.client.api.element('#signupSection').prop('classList'); assert.strictEqual(resultPromise instanceof Element, false); assert.strictEqual(typeof resultPromise.find, 'undefined');