chore: implement partial ElementHandle.prototype.boundingBox (#10660)

This commit is contained in:
jrandolf 2023-08-01 15:07:48 +02:00 committed by GitHub
parent 7de91f16b4
commit 04369db145
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 1 deletions

View File

@ -19,6 +19,7 @@ import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js';
import {
AutofillData,
ElementHandle as BaseElementHandle,
BoundingBox,
ClickOptions,
} from '../../api/ElementHandle.js';
import {KeyPressOptions, KeyboardTypeOptions} from '../../api/Input.js';
@ -85,6 +86,28 @@ export class ElementHandle<
});
}
override async boundingBox(): Promise<BoundingBox | null> {
if (this.frame.parentFrame()) {
throw new Error(
'Elements within nested iframes are currently not supported.'
);
}
const box = await this.frame.isolatedRealm().evaluate(element => {
const rect = (element as unknown as Element).getBoundingClientRect();
if (!rect.left && !rect.top && !rect.width && !rect.height) {
// TODO(jrandolf): Detect if the element is truly not visible.
return null;
}
return {
x: rect.left,
y: rect.top,
width: rect.width,
height: rect.height,
};
}, this);
return box;
}
// ///////////////////
// // Input methods //
// ///////////////////

View File

@ -545,6 +545,30 @@
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[elementhandle.spec] ElementHandle specs ElementHandle.boundingBox should force a layout",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[elementhandle.spec] ElementHandle specs ElementHandle.boundingBox should return null for invisible elements",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[elementhandle.spec] ElementHandle specs ElementHandle.boundingBox should work",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[elementhandle.spec] ElementHandle specs ElementHandle.boundingBox should work with SVG nodes",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[elementhandle.spec] ElementHandle specs ElementHandle.click should not work for TextNodes",
"platforms": ["darwin", "linux", "win32"],
@ -947,6 +971,12 @@
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[mouse.spec] Mouse should resize the textarea",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[mouse.spec] Mouse should trigger hover state",
"platforms": ["darwin", "linux", "win32"],
@ -1859,6 +1889,12 @@
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[elementhandle.spec] ElementHandle specs ElementHandle.boundingBox should force a layout",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[elementhandle.spec] ElementHandle specs ElementHandle.boundingBox should handle nested frames",
"platforms": ["darwin", "linux", "win32"],
@ -1877,6 +1913,12 @@
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL", "PASS"]
},
{
"testIdPattern": "[elementhandle.spec] ElementHandle specs ElementHandle.boundingBox should work",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[elementhandle.spec] ElementHandle specs ElementHandle.boxModel should return null for invisible elements",
"platforms": ["darwin", "linux", "win32"],
@ -2471,6 +2513,12 @@
"parameters": ["cdp", "firefox"],
"expectations": ["SKIP"]
},
{
"testIdPattern": "[mouse.spec] Mouse should resize the textarea",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[mouse.spec] Mouse should select the text with mouse",
"platforms": ["win32"],

View File

@ -170,9 +170,10 @@ export function getExpectationUpdates(
// If an error occurs during a hook
// the error not have a file associated with it
if (!failure.file) {
console.error('Hook failed:', failure.err);
addEntry({
expectation: {
testIdPattern: 'Hook failed!',
testIdPattern: failure.fullTitle,
platforms: context.platforms,
parameters: context.parameters,
expectations: [],