Skip to content

Commit

Permalink
Add .accessibleName() as alias for .getAccessibleName(). (#4178)
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 authored Apr 18, 2024
1 parent 6919723 commit 88ba6c6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/api/web-element/scoped-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ScopedWebElement {
'getRect': ['getSize', 'getLocation', 'rect'],
'getProperty': ['property', 'prop'],
'getText': ['text'],
'getAccessibleName': ['accessibleName'],
'getCssProperty': ['css'],
'getAriaRole': ['ariaRole'],
'isVisible': ['isDisplayed']
Expand Down
26 changes: 26 additions & 0 deletions test/src/api/commands/web-element/testGetAccessibleName.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ describe('element().getAccessibleName() command', function () {
assert.strictEqual(resultValue, 'Signup');
});

it('test .element().accessibleName() alias', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/element/0/computedlabel',
method: 'GET',
response: JSON.stringify({
value: 'Signup'
})
}, true);

const resultPromise = this.client.api.element('#signupSection').accessibleName();
assert.strictEqual(resultPromise instanceof Element, false);
assert.strictEqual(typeof resultPromise.find, 'undefined');

assert.strictEqual(resultPromise instanceof Promise, false);
assert.strictEqual(typeof resultPromise.then, 'function');
assert.strictEqual(typeof resultPromise.value, 'object');

const result = await resultPromise;
assert.strictEqual(result instanceof WebElement, false);
assert.strictEqual(result, 'Signup');

const resultValue = await resultPromise.value;
assert.strictEqual(resultValue, 'Signup');
});

it('test .element().find().getAccessibleName()', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/element/1/computedlabel',
Expand Down Expand Up @@ -115,4 +140,5 @@ describe('element().getAccessibleName() command', function () {
assert.strictEqual(await resultPromise.assert.not.contains('Signupx'), 'Signup');
assert.strictEqual(await resultPromise.assert.not.matches(/Si[a-z]{2}upx/), 'Signup');
});

});
1 change: 1 addition & 0 deletions types/tests/webElement.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ describe('new element() api', function () {
expectType<ElementValue<ScopedElementRect>>(elem.getLocation());

expectType<ElementValue<string>>(elem.getAccessibleName());
expectType<ElementValue<string>>(elem.accessibleName());
expectType<ElementValue<string>>(elem.getAriaRole());
expectType<ElementValue<string>>(elem.ariaRole());
expectType<ElementValue<string>>(elem.getCssProperty('height'));
Expand Down
1 change: 1 addition & 0 deletions types/web-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export interface ScopedElement extends Element, PromiseLike<WebElement> {
upload(file: string): Promise<WebElement>;

getAccessibleName(): ElementValue<string>;
accessibleName(): ElementValue<string>;

getAriaRole(): ElementValue<string>;
ariaRole(): ElementValue<string>;
Expand Down

0 comments on commit 88ba6c6

Please sign in to comment.