Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webdriver]: add checks for execute_script tests recognising promises #13781

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions webdriver/tests/execute_script/promise.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import pytest

from tests.support.asserts import assert_dialog_handled, assert_error, assert_success


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(
session_id=session.session_id),
body)


def test_promise_resolve(session):
response = execute_script(session, """
return Promise.resolve('foobar');
""")
assert_success(response, "foobar")


def test_promise_resolve_delayed(session):
response = execute_script(session, """
return new Promise(
(resolve) => setTimeout(
andreastt marked this conversation as resolved.
Show resolved Hide resolved
andreastt marked this conversation as resolved.
Show resolved Hide resolved
() => resolve('foobar'),
50
)
);
""")
assert_success(response, "foobar")


def test_promise_reject(session):
response = execute_script(session, """
return Promise.reject(new Error('my error'));
""")
assert_error(response, "unknown error")
christian-bromann marked this conversation as resolved.
Show resolved Hide resolved
assert response.body["value"]["message"] == "Error: my error"
christian-bromann marked this conversation as resolved.
Show resolved Hide resolved


def test_promise_reject_delayed(session):
response = execute_script(session, """
return new Promise(
(resolve, reject) => setTimeout(
() => reject(new Error('my error')),
50
)
);
""")
assert_error(response, "unknown error")
assert response.body["value"]["message"] == "Error: my error"
christian-bromann marked this conversation as resolved.
Show resolved Hide resolved


def test_promise_resolve_timeout(session):
session.timeouts.script = .1
response = execute_script(session, """
return new Promise(
(resolve) => setTimeout(
() => resolve('success'),
christian-bromann marked this conversation as resolved.
Show resolved Hide resolved
1000
)
);
""")
assert_error(response, "timeout error")


def test_promise_reject_timeout(session):
session.timeouts.script = .1
response = execute_script(session, """
return new Promise(
(resolve, reject) => setTimeout(
() => reject(new Error('my error')),
andreastt marked this conversation as resolved.
Show resolved Hide resolved
1000
)
);
""")
assert_error(response, "timeout error")