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 rect() as alias for getRect() command. #4128

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions lib/api/web-element/commands/getRect.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @syntax browser.element(selector).getRect()
* @see https://www.w3.org/TR/webdriver#dfn-get-element-rect
* @returns {ScopedValue<{ width: number, height: number }>}
* @alias rect
garg3133 marked this conversation as resolved.
Show resolved Hide resolved
*/
module.exports.command = function() {
return this.runQueuedCommandScoped('getElementRect');
Expand Down
2 changes: 1 addition & 1 deletion lib/api/web-element/scoped-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ScopedWebElement {
'findAllByRole': ['getAllByRole'],
'findAllByPlaceholderText': ['getAllByPlaceholderText'],
'findAllByAltText': ['getAllByAltText'],
'getRect': ['getSize', 'getLocation'],
'getRect': ['getSize', 'getLocation', 'rect'],
'getProperty': ['property'],
'getCssProperty': ['css'],
'isVisible': ['isDisplayed']
Expand Down
24 changes: 24 additions & 0 deletions test/src/api/commands/web-element/testGetRect.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,28 @@ describe('element().getRect() command', function () {
const resultValue = await resultPromise.value;
assert.deepStrictEqual(resultValue, {height: 34, width: 443, x: 356, y: 381.5});
});

it('test .element().rect()', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/element/0/rect',
method: 'GET',
response: JSON.stringify({
value: {height: 34, width: 443, x: 356, y: 381.5}
})
}, true);
garg3133 marked this conversation as resolved.
Show resolved Hide resolved

const resultPromise = this.client.api.element('#signupSection').rect();
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, {height: 34, width: 443, x: 356, y: 381.5});

const resultValue = await resultPromise.value;
assert.deepStrictEqual(resultValue, {height: 34, width: 443, x: 356, y: 381.5});
});
});
1 change: 1 addition & 0 deletions types/tests/webElement.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ describe('new element() api', function () {

expectType<ElementValue<ScopedElementRect>>(elem.getRect());
expectType<ElementValue<ScopedElementRect>>(elem.getSize());
expectType<ElementValue<ScopedElementRect>>(elem.rect());
garg3133 marked this conversation as resolved.
Show resolved Hide resolved

expectType<ElementValue<string>>(elem.getAccessibleName());
expectType<ElementValue<string>>(elem.getAriaRole());
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 @@ -177,6 +177,8 @@ export interface ScopedElement extends Element, PromiseLike<WebElement> {

getSize(): ElementValue<ScopedElementRect>;

rect(): ElementValue<ScopedElementRect>;
garg3133 marked this conversation as resolved.
Show resolved Hide resolved

getValue(): ElementValue<string | null>;

setValue<E extends readonly unknown[]>(...keys: E): Promise<WebElement>;
Expand Down
Loading