Skip to content

Commit 9e28910

Browse files
Check if the provided selector is an iframe
1 parent 1dca221 commit 9e28910

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

src/commands/context_setters.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ function parseWithinIFrame(parser) {
246246

247247
const code = `\
248248
${getAndSetElements(selector, 'iframe', false)}
249+
await iframe.evaluate(el => {
250+
if (el.tagName !== "IFRAME") {
251+
throw "selector \`${selector.value}\` is not an \`<iframe>\` but a \`<" + \
252+
el.tagName.toLowerCase() + ">\`";
253+
}
254+
});
249255
pages.push(iframe);`;
250256

251257
return {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
instructions = [
22
"""const iframe = await page.$(\"a\");
33
if (iframe === null) { throw '\"a\" not found'; }
4+
await iframe.evaluate(el => {
5+
if (el.tagName !== \"IFRAME\") {
6+
throw \"selector `a` is not an `<iframe>` but a `<\" + el.tagName.toLowerCase() + \">`\";
7+
}
8+
});
49
pages.push(iframe);""",
510
]
611
noPosIncrease = true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
instructions = [
22
"""const iframe = await page.$(\"a\");
33
if (iframe === null) { throw '\"a\" not found'; }
4+
await iframe.evaluate(el => {
5+
if (el.tagName !== \"IFRAME\") {
6+
throw \"selector `a` is not an `<iframe>` but a `<\" + el.tagName.toLowerCase() + \">`\";
7+
}
8+
});
49
pages.push(iframe);""",
510
]
611
noPosIncrease = true

tests/ui/within-iframe-2.goml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This test checks what happens if the selected element is not an iframe.
2+
3+
go-to: "file://" + |CURRENT_DIR| + "/" + |DOC_PATH| + "/basic.html"
4+
within-iframe: ("#the-input", block {})

tests/ui/within-iframe-2.output

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=> Starting doc-ui tests...
2+
3+
within-iframe-2... FAILED
4+
[ERROR] `tests/ui/within-iframe-2.goml` line 4: selector `#the-input` is not an `<iframe>` but a `<input>`: for command `within-iframe: ("#the-input", block {})`
5+
6+
7+
<= doc-ui tests done: 0 succeeded, 1 failed

0 commit comments

Comments
 (0)