Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional commands for new Element API #4261

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/api/web-element/commands/getComputedLabel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.command = function () {
return this.runQueuedCommand('getElementComputedLabel');
};
3 changes: 3 additions & 0 deletions lib/api/web-element/commands/getComputedRole.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.command = function () {
return this.runQueuedCommand('getElementComputedRole');
};
3 changes: 3 additions & 0 deletions lib/api/web-element/commands/isActive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.command = function () {
return this.runQueuedCommandScoped('isElementActive');
};
4 changes: 1 addition & 3 deletions lib/api/web-element/scoped-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ class ScopedWebElement {
this.webElement = promise;
} else {
this.webElement = new WebElementPromise(this.driver, this.then(async (element) => {
await promise;

return element;
return await promise;
garg3133 marked this conversation as resolved.
Show resolved Hide resolved
}));
}

Expand Down
4 changes: 4 additions & 0 deletions lib/transport/selenium-webdriver/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class TransportActions {
promise = Array.isArray(args) ? mapping.apply(this.MethodMappings, args) : mapping.call(this.MethodMappings, args);
}

if (promise.resolveEarly){
promise = await promise;
}

if (!(promise instanceof Promise)) {
const opts = {};

Expand Down
34 changes: 34 additions & 0 deletions lib/transport/selenium-webdriver/method-mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,40 @@ module.exports = class MethodMappings {
};
},


getElementComputedRole(webElementOrId) {
const promise = (async () => {
const id = await webElementOrId.getId();

return `/element/${id}/computedrole`;
})();
promise.resolveEarly = true;

return promise;
},

getElementComputedLabel(webElementOrId) {
const promise = (async () => {
const id = await webElementOrId.getId();

return `/element/${id}/computedlabel`;
})();
promise.resolveEarly = true;

return promise;
},

async isElementActive(webElementOrId) {
const element = this.getWebElement(webElementOrId);

const isActive = await this.driver.executeScript(`
const el = arguments[0];
return el === document.activeElement;
`, element);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use this endpoint to get the active element?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this actually returns the active element, so we won't be able to get the element here to check if the element is that element only.


return isActive;
},

async setElementProperty(webElementOrId, name, value) {
const element = this.getWebElement(webElementOrId);

Expand Down
6 changes: 6 additions & 0 deletions types/web-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ export interface ScopedElement extends Element, PromiseLike<WebElement> {

isVisible(): ElementValue<boolean>;
isDisplayed(): ElementValue<boolean>;

isActive(): ElementValue<boolean>;

getComputedLabel(): ElementValue<string>;

getComputedRole(): ElementValue<string>;
}

type WaitUntilOptions = {
Expand Down
Loading