Skip to content

Commit b4e273a

Browse files
authored
Add rect() as alias for getRect() command. (#4128)
1 parent 8839519 commit b4e273a

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

lib/api/web-element/commands/getRect.js

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
* @syntax browser.element(selector).getRect()
3030
* @see https://www.w3.org/TR/webdriver#dfn-get-element-rect
3131
* @returns {ScopedValue<{ width: number, height: number }>}
32+
* @alias getSize
33+
* @alias getLocation
3234
*/
3335
module.exports.command = function() {
3436
return this.runQueuedCommandScoped('getElementRect');

lib/api/web-element/scoped-element.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ScopedWebElement {
2222
'findAllByRole': ['getAllByRole'],
2323
'findAllByPlaceholderText': ['getAllByPlaceholderText'],
2424
'findAllByAltText': ['getAllByAltText'],
25-
'getRect': ['getSize', 'getLocation'],
25+
'getRect': ['getSize', 'getLocation', 'rect'],
2626
'getProperty': ['property'],
2727
'getCssProperty': ['css'],
2828
'isVisible': ['isDisplayed']

test/src/api/commands/web-element/testGetRect.js

+25
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,30 @@ describe('element().getRect() command', function () {
3838
assert.deepStrictEqual(resultValue, {height: 34, width: 443, x: 356, y: 381.5});
3939
});
4040

41+
it('test .element().rect()', async function() {
42+
MockServer.addMock({
43+
url: '/session/13521-10219-202/element/0/rect',
44+
method: 'GET',
45+
response: JSON.stringify({
46+
value: {height: 34, width: 443, x: 356, y: 381.5}
47+
})
48+
}, true);
49+
50+
const resultPromise = this.client.api.element('#signupSection').rect();
51+
assert.strictEqual(resultPromise instanceof Element, false);
52+
assert.strictEqual(typeof resultPromise.find, 'undefined');
53+
54+
assert.strictEqual(resultPromise instanceof Promise, false);
55+
assert.strictEqual(typeof resultPromise.then, 'function');
56+
57+
const result = await resultPromise;
58+
assert.strictEqual(result instanceof WebElement, false);
59+
assert.deepStrictEqual(result, {height: 34, width: 443, x: 356, y: 381.5});
60+
61+
const resultValue = await resultPromise.value;
62+
assert.deepStrictEqual(resultValue, {height: 34, width: 443, x: 356, y: 381.5});
63+
});
64+
4165
it('test .element().getSize()', async function() {
4266
MockServer.addMock({
4367
url: '/session/13521-10219-202/element/0/rect',
@@ -133,4 +157,5 @@ describe('element().getRect() command', function () {
133157
const resultValue = await resultPromise.value;
134158
assert.deepStrictEqual(resultValue, {height: 34, width: 443, x: 356, y: 381.5});
135159
});
160+
136161
});

types/tests/webElement.test-d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ describe('new element() api', function () {
145145
expectType<ElementValue<boolean>>(elem.isDisplayed());
146146

147147
expectType<ElementValue<ScopedElementRect>>(elem.getRect());
148+
expectType<ElementValue<ScopedElementRect>>(elem.rect());
148149
expectType<ElementValue<ScopedElementRect>>(elem.getSize());
150+
expectType<ElementValue<ScopedElementRect>>(elem.getLocation());
149151

150152
expectType<ElementValue<string>>(elem.getAccessibleName());
151153
expectType<ElementValue<string>>(elem.getAriaRole());

types/web-element.d.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ export interface ScopedElement extends Element, PromiseLike<WebElement> {
139139

140140
getRect(): ElementValue<ScopedElementRect>;
141141

142+
rect(): ElementValue<ScopedElementRect>;
143+
144+
getSize(): ElementValue<ScopedElementRect>;
145+
146+
getLocation(): ElementValue<ScopedElementRect>;
147+
142148
getTagName(): ElementValue<string>;
143149

144150
getText(): ElementValue<string>;
@@ -175,8 +181,6 @@ export interface ScopedElement extends Element, PromiseLike<WebElement> {
175181

176182
getCssProperty(name: string): ElementValue<string>;
177183

178-
getSize(): ElementValue<ScopedElementRect>;
179-
180184
getValue(): ElementValue<string | null>;
181185

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

0 commit comments

Comments
 (0)