Skip to content

Commit

Permalink
Add getComputedLabel() and getComputedRole() alias commands. (#4296)
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 authored Nov 10, 2024
1 parent 0cf0f58 commit 99637d8
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/api/web-element/commands/getAccessibleName.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
* @method getAccessibleName
* @memberof ScopedWebElement
* @instance
* @syntax browser.element(selector).getAccessibleName()
* @syntax browser.element.find(selector).getAccessibleName()
* @syntax browser.element.find(selector).getComputedLabel()
* @link /#get-computed-label
* @returns {ScopedValue<string>} A container with accessible name of an element.
* @alias getComputedLabel
*/
module.exports.command = function() {
return this.runQueuedCommandScoped('getElementAccessibleName');
Expand Down
4 changes: 3 additions & 1 deletion lib/api/web-element/commands/getAriaRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
* @method getAriaRole
* @memberof ScopedWebElement
* @instance
* @syntax browser.element(selector).getAriaRole()
* @syntax browser.element.find(selector).getAriaRole()
* @syntax browser.element.find(selector).getComputedRole()
* @link /#get-computed-role
* @returns {ScopedValue<string>} The container with computed WAI-ARIA role of an element.
* @alias getComputedRole
*/
module.exports.command = function() {
return this.runQueuedCommandScoped('getElementAriaRole');
Expand Down
4 changes: 2 additions & 2 deletions lib/api/web-element/scoped-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class ScopedWebElement {
'getProperty': ['property', 'prop'],
'getText': ['text'],
'getTagName': ['tagName'],
'getAccessibleName': ['accessibleName'],
'getAccessibleName': ['accessibleName', 'getComputedLabel'],
'getCssProperty': ['css', 'getCssValue'],
'getAriaRole': ['ariaRole'],
'getAriaRole': ['ariaRole', 'getComputedRole'],
'isVisible': ['isDisplayed']
};
}
Expand Down
25 changes: 25 additions & 0 deletions test/src/api/commands/web-element/testGetAccessibleName.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@ describe('element().getAccessibleName() command', function () {
assert.strictEqual(resultValue, 'Signup');
});

it('test .element().getComputedLabel() 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').getComputedLabel();
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
26 changes: 25 additions & 1 deletion test/src/api/commands/web-element/testGetAriaRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('element().getAriaRole() command', function () {
assert.strictEqual(resultValue, 'signupSection');
});

it('test .element().ariaRole()', async function() {
it('test .element().ariaRole() alias', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/element/0/computedrole',
method: 'GET',
Expand All @@ -62,6 +62,30 @@ describe('element().getAriaRole() command', function () {
assert.strictEqual(resultValue, 'signupSection');
});

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

const resultPromise = this.client.api.element('#signupSection').getComputedRole();
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, 'signupSection');

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

it('test .element().find().getAriaRole()', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/element/1/computedrole',
Expand Down
2 changes: 2 additions & 0 deletions types/tests/webElement.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ describe('new element() api', function () {

expectType<ElementValue<string>>(elem.getAccessibleName());
expectType<ElementValue<string>>(elem.accessibleName());
expectType<ElementValue<string>>(elem.getComputedLabel());
expectType<ElementValue<string>>(elem.getAriaRole());
expectType<ElementValue<string>>(elem.ariaRole());
expectType<ElementValue<string>>(elem.getComputedRole());
expectType<ElementValue<string>>(elem.getCssProperty('height'));
expectType<ElementValue<string>>(elem.css('height'));
expectType<ElementValue<string>>(elem.getCssValue('height'));
Expand Down
2 changes: 2 additions & 0 deletions types/web-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,11 @@ export interface ScopedElement extends Element, PromiseLike<WebElement> {

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

getAriaRole(): ElementValue<string>;
ariaRole(): ElementValue<string>;
getComputedRole(): ElementValue<string>;

getCssProperty(name: string): ElementValue<string>;
css(name: string): ElementValue<string>;
Expand Down

0 comments on commit 99637d8

Please sign in to comment.