-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make testdriver click/send_keys/actions work in more browsing contexts (
#25550) This is a slightly hacky change to allow testdriver actions to work in more browsing contexts. The basic idea is that when we want to run an action in a different borsing context, we pass wptrunner a context list like [window_id, frame_id...], and use that to select the correct browsing context just for the duration of the action, before switching back. There are a number of limitations with the current patch, some more serious than others: * So far this is only implmented for testdriver commands that take an explicit element. Other commands could be modified to also allow passing in an explicit context. * It must be possible to get a window reference and set the name property (see below). This means this approach only works for windows that are same origin with the test window. * WebDriver implementations don't generally support returning a window object from script, so we can't return a window handle directly. Instead we either use the existing window.name property or add a window.name when we try to start the action. Then in wptrunner we do a linear search of all windows to find the one with the appropriate name. We have to use window.name rather than writing a custom property into the window global because the way marionette sandboxes js we aren't able to read the global property. However despite these limitations this makes the feature considerably more versatile than it was previously. Co-authored-by: Robert Ma <[email protected]>
- Loading branch information
Showing
14 changed files
with
288 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!doctype html> | ||
<button id="button">Button</button> | ||
<div id="log">FAIL</div> | ||
<script> | ||
document.getElementById("button").addEventListener("click", () => | ||
document.getElementById("log").textContent = "PASS"); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>TestDriver click on a document in an iframe</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
|
||
<iframe src="click_child.html"></iframe> | ||
|
||
<script> | ||
setup({single_test: true}); | ||
addEventListener("load", () => { | ||
let child = frames[0]; | ||
let button = child.document.getElementById("button"); | ||
test_driver | ||
.click(button) | ||
.then(() => { | ||
assert_equals(child.document.getElementById("log").textContent, "PASS"); | ||
done(); | ||
}) | ||
.catch(() => assert_unreached("click failed")); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>TestDriver click method with multiple windows and nested iframe</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
|
||
<iframe src="about:blank"></iframe> | ||
|
||
<script> | ||
setup({single_test: true}); | ||
|
||
window.open("about:blank") | ||
var child = window.open("click_outer_child.html") | ||
window.open("about:blank") | ||
|
||
addEventListener("load",() => { | ||
child.addEventListener("load", () => { | ||
let doc = child.frames[2].document; | ||
let button = doc.getElementById("button"); | ||
test_driver | ||
.click(button) | ||
.then(() => { | ||
assert_equals(doc.getElementById("log").textContent, "PASS"); | ||
done(); | ||
}) | ||
.catch(() => assert_unreached("click failed")); | ||
}); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!doctype html> | ||
<iframe src="about:blank"></iframe> | ||
<iframe src="about:blank"></iframe> | ||
<iframe src="click_child.html"></iframe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>TestDriver click method in window</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
|
||
<script> | ||
setup({single_test: true}); | ||
addEventListener("load", () => { | ||
let child = window.open("click_child.html"); | ||
child.addEventListener("load", () => { | ||
let button = child.document.getElementById("button"); | ||
test_driver | ||
.click(button) | ||
.then(() => { | ||
assert_equals(child.document.getElementById("log").textContent, "PASS"); | ||
done(); | ||
}) | ||
.catch(() => assert_unreached("click failed")); | ||
}); | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.