зеркало из https://github.com/mozilla/gecko-dev.git
bug 1546303: webdriver: add WPT tests for properties in evaluated scripts; r=whimboo
This adds a basic set of tests for interacting with various kinds of DOM properties from the WebDriver commands Execute Script and Execute Async Script. Differential Revision: https://phabricator.services.mozilla.com/D28453 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
cf526c8480
Коммит
091ef4438c
|
@ -0,0 +1,71 @@
|
|||
from tests.support.asserts import assert_same_element, assert_success
|
||||
from tests.support.inline import inline
|
||||
|
||||
|
||||
def execute_async_script(session, script, args=None):
|
||||
if args is None:
|
||||
args = []
|
||||
body = {"script": script, "args": args}
|
||||
return session.transport.send(
|
||||
"POST", "/session/{session_id}/execute/async".format(**vars(session)),
|
||||
body)
|
||||
|
||||
|
||||
def test_content_attribute(session):
|
||||
session.url = inline("<input value=foobar>")
|
||||
response = execute_async_script(session, """
|
||||
const [resolve] = arguments;
|
||||
const input = document.querySelector("input");
|
||||
resolve(input.value);
|
||||
""")
|
||||
assert_success(response, "foobar")
|
||||
|
||||
|
||||
def test_idl_attribute(session):
|
||||
session.url = inline("""
|
||||
<input>
|
||||
<script>
|
||||
const input = document.querySelector("input");
|
||||
input.value = "foobar";
|
||||
</script>
|
||||
""")
|
||||
response = execute_async_script(session, """
|
||||
const [resolve] = arguments;
|
||||
const input = document.querySelector("input");
|
||||
resolve(input.value);
|
||||
""")
|
||||
assert_success(response, "foobar")
|
||||
|
||||
|
||||
def test_idl_attribute_element(session):
|
||||
session.url = inline("""
|
||||
<p>foo
|
||||
<p>bar
|
||||
|
||||
<script>
|
||||
const [foo, bar] = document.querySelectorAll("p");
|
||||
foo.bar = bar;
|
||||
</script>
|
||||
""")
|
||||
_foo, bar = session.find.css("p")
|
||||
response = execute_async_script(session, """
|
||||
const [resolve] = arguments;
|
||||
const foo = document.querySelector("p");
|
||||
resolve(foo.bar);
|
||||
""")
|
||||
value = assert_success(response)
|
||||
assert_same_element(session, bar, value)
|
||||
|
||||
|
||||
def test_script_defining_property(session):
|
||||
session.url = inline("<input>")
|
||||
session.execute_script("""
|
||||
const input = document.querySelector("input");
|
||||
input.foobar = "foobar";
|
||||
""")
|
||||
response = execute_async_script(session, """
|
||||
const [resolve] = arguments;
|
||||
const input = document.querySelector("input");
|
||||
resolve(input.foobar);
|
||||
""")
|
||||
assert_success(response, "foobar")
|
|
@ -0,0 +1,67 @@
|
|||
from tests.support.asserts import assert_same_element, assert_success
|
||||
from tests.support.inline import inline
|
||||
|
||||
|
||||
def execute_script(session, script, args=None):
|
||||
if args is None:
|
||||
args = []
|
||||
body = {"script": script, "args": args}
|
||||
return session.transport.send(
|
||||
"POST", "/session/{session_id}/execute/sync".format(**vars(session)),
|
||||
body)
|
||||
|
||||
|
||||
def test_content_attribute(session):
|
||||
session.url = inline("<input value=foobar>")
|
||||
response = execute_script(session, """
|
||||
const input = document.querySelector("input");
|
||||
return input.value;
|
||||
""")
|
||||
assert_success(response, "foobar")
|
||||
|
||||
|
||||
def test_idl_attribute(session):
|
||||
session.url = inline("""
|
||||
<input>
|
||||
<script>
|
||||
const input = document.querySelector("input");
|
||||
input.value = "foobar";
|
||||
</script>
|
||||
""")
|
||||
response = execute_script(session, """
|
||||
const input = document.querySelector("input");
|
||||
return input.value;
|
||||
""")
|
||||
assert_success(response, "foobar")
|
||||
|
||||
|
||||
def test_idl_attribute_element(session):
|
||||
session.url = inline("""
|
||||
<p>foo
|
||||
<p>bar
|
||||
|
||||
<script>
|
||||
const [foo, bar] = document.querySelectorAll("p");
|
||||
foo.bar = bar;
|
||||
</script>
|
||||
""")
|
||||
_foo, bar = session.find.css("p")
|
||||
response = execute_script(session, """
|
||||
const foo = document.querySelector("p");
|
||||
return foo.bar;
|
||||
""")
|
||||
value = assert_success(response)
|
||||
assert_same_element(session, bar, value)
|
||||
|
||||
|
||||
def test_script_defining_property(session):
|
||||
session.url = inline("<input>")
|
||||
execute_script(session, """
|
||||
const input = document.querySelector("input");
|
||||
input.foobar = "foobar";
|
||||
""")
|
||||
response = execute_script(session, """
|
||||
const input = document.querySelector("input");
|
||||
return input.foobar;
|
||||
""")
|
||||
assert_success(response, "foobar")
|
Загрузка…
Ссылка в новой задаче