Skip to content

Commit

Permalink
Add .getCssValue() as alias for .getCssProperty(). (#4168)
Browse files Browse the repository at this point in the history

Co-authored-by: Priyansh Garg <priyanshgarg30@gmail.com>
  • Loading branch information
Ayush-Vish and garg3133 committed Apr 18, 2024
1 parent fcaabc1 commit 0b3cfb1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/api/web-element/scoped-element.js
Expand Up @@ -27,7 +27,7 @@ class ScopedWebElement {
'getText': ['text'],
'getTagName': ['tagName'],
'getAccessibleName': ['accessibleName'],
'getCssProperty': ['css'],
'getCssProperty': ['css', 'getCssValue'],
'getAriaRole': ['ariaRole'],
'isVisible': ['isDisplayed']
};
Expand Down
25 changes: 25 additions & 0 deletions test/src/api/commands/web-element/testGetCssProperty.js
Expand Up @@ -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',
Expand Down Expand Up @@ -135,4 +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');
});

});
2 changes: 2 additions & 0 deletions types/tests/webElement.test-d.ts
Expand Up @@ -167,6 +167,8 @@ describe('new element() api', function () {
expectType<ElementValue<string>>(elem.getAriaRole());
expectType<ElementValue<string>>(elem.ariaRole());
expectType<ElementValue<string>>(elem.getCssProperty('height'));
expectType<ElementValue<string>>(elem.css('height'));
expectType<ElementValue<string>>(elem.getCssValue('height'));
expectType<ElementValue<string>>(elem.takeScreenshot());

expectType<Promise<WebElement>>(elem.click());
Expand Down
2 changes: 2 additions & 0 deletions types/web-element.d.ts
Expand Up @@ -188,6 +188,8 @@ export interface ScopedElement extends Element, PromiseLike<WebElement> {
ariaRole(): ElementValue<string>;

getCssProperty(name: string): ElementValue<string>;
css(name: string): ElementValue<string>;
getCssValue(name: string): ElementValue<string>;

getValue(): ElementValue<string | null>;

Expand Down

0 comments on commit 0b3cfb1

Please sign in to comment.