bug 1492499: webdriver: poll for document.hidden; r=automatedtester

For the time being we need to poll for document.hidden to become
true because certain driver implementations, such as geckodriver,
occasionally does not wait until the DOM property is propagated to
the child process.

Depends on D8408

Differential Revision: https://phabricator.services.mozilla.com/D8409

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andreas Tolfsen 2018-10-11 16:44:20 +00:00
Родитель e520fe6c58
Коммит 56f70d08e0
5 изменённых файлов: 32 добавлений и 33 удалений

Просмотреть файл

@ -1,5 +1,5 @@
from tests.support.asserts import assert_error, assert_success from tests.support.asserts import assert_error, assert_success
from tests.support.helpers import is_fullscreen from tests.support.helpers import document_hidden, is_fullscreen
def maximize(session): def maximize(session):
@ -23,7 +23,7 @@ def test_fully_exit_fullscreen(session):
def test_restore_the_window(session): def test_restore_the_window(session):
session.window.minimize() session.window.minimize()
assert session.execute_script("return document.hidden") is True assert document_hidden(session)
response = maximize(session) response = maximize(session)
assert_success(response) assert_success(response)

Просмотреть файл

@ -1,5 +1,7 @@
# META: timeout=long
from tests.support.asserts import assert_error, assert_success from tests.support.asserts import assert_error, assert_success
from tests.support.helpers import is_fullscreen from tests.support.helpers import document_hidden, is_fullscreen
def minimize(session): def minimize(session):
@ -7,10 +9,6 @@ def minimize(session):
"POST", "session/{session_id}/window/minimize".format(**vars(session))) "POST", "session/{session_id}/window/minimize".format(**vars(session)))
def is_minimized(session):
return session.execute_script("return document.hidden")
def test_no_browsing_context(session, closed_window): def test_no_browsing_context(session, closed_window):
response = minimize(session) response = minimize(session)
assert_error(response, "no such window") assert_error(response, "no such window")
@ -23,19 +21,19 @@ def test_fully_exit_fullscreen(session):
response = minimize(session) response = minimize(session)
assert_success(response) assert_success(response)
assert not is_fullscreen(session) assert not is_fullscreen(session)
assert is_minimized(session) assert document_hidden(session)
def test_minimize(session): def test_minimize(session):
assert not is_minimized(session) assert not document_hidden(session)
response = minimize(session) response = minimize(session)
assert_success(response) assert_success(response)
assert is_minimized(session) assert document_hidden(session)
def test_payload(session): def test_payload(session):
assert not is_minimized(session) assert not document_hidden(session)
response = minimize(session) response = minimize(session)
value = assert_success(response) value = assert_success(response)
@ -51,16 +49,16 @@ def test_payload(session):
assert isinstance(value["x"], int) assert isinstance(value["x"], int)
assert isinstance(value["y"], int) assert isinstance(value["y"], int)
assert is_minimized(session) assert document_hidden(session)
def test_minimize_twice_is_idempotent(session): def test_minimize_twice_is_idempotent(session):
assert not is_minimized(session) assert not document_hidden(session)
first_response = minimize(session) first_response = minimize(session)
assert_success(first_response) assert_success(first_response)
assert is_minimized(session) assert document_hidden(session)
second_response = minimize(session) second_response = minimize(session)
assert_success(second_response) assert_success(second_response)
assert is_minimized(session) assert document_hidden(session)

Просмотреть файл

@ -3,6 +3,7 @@
import pytest import pytest
from tests.support.asserts import assert_dialog_handled, assert_error, assert_success from tests.support.asserts import assert_dialog_handled, assert_error, assert_success
from tests.support.helpers import document_hidden
def minimize(session): def minimize(session):
@ -10,23 +11,17 @@ def minimize(session):
"POST", "session/{session_id}/window/minimize".format(**vars(session))) "POST", "session/{session_id}/window/minimize".format(**vars(session)))
def is_minimized(session):
return session.execute_script("return document.hidden")
@pytest.fixture @pytest.fixture
def check_user_prompt_closed_without_exception(session, create_dialog): def check_user_prompt_closed_without_exception(session, create_dialog):
def check_user_prompt_closed_without_exception(dialog_type, retval): def check_user_prompt_closed_without_exception(dialog_type, retval):
assert not is_minimized(session) assert not document_hidden(session)
create_dialog(dialog_type, text=dialog_type) create_dialog(dialog_type, text=dialog_type)
response = minimize(session) response = minimize(session)
assert_success(response) assert_success(response)
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval) assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
assert document_hidden(session)
assert is_minimized(session)
return check_user_prompt_closed_without_exception return check_user_prompt_closed_without_exception
@ -34,16 +29,14 @@ def check_user_prompt_closed_without_exception(session, create_dialog):
@pytest.fixture @pytest.fixture
def check_user_prompt_closed_with_exception(session, create_dialog): def check_user_prompt_closed_with_exception(session, create_dialog):
def check_user_prompt_closed_with_exception(dialog_type, retval): def check_user_prompt_closed_with_exception(dialog_type, retval):
assert not is_minimized(session) assert not document_hidden(session)
create_dialog(dialog_type, text=dialog_type) create_dialog(dialog_type, text=dialog_type)
response = minimize(session) response = minimize(session)
assert_error(response, "unexpected alert open") assert_error(response, "unexpected alert open")
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval) assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
assert not document_hidden(session)
assert not is_minimized(session)
return check_user_prompt_closed_with_exception return check_user_prompt_closed_with_exception
@ -51,8 +44,7 @@ def check_user_prompt_closed_with_exception(session, create_dialog):
@pytest.fixture @pytest.fixture
def check_user_prompt_not_closed_but_exception(session, create_dialog): def check_user_prompt_not_closed_but_exception(session, create_dialog):
def check_user_prompt_not_closed_but_exception(dialog_type): def check_user_prompt_not_closed_but_exception(dialog_type):
assert not is_minimized(session) assert not document_hidden(session)
create_dialog(dialog_type, text=dialog_type) create_dialog(dialog_type, text=dialog_type)
response = minimize(session) response = minimize(session)
@ -61,7 +53,7 @@ def check_user_prompt_not_closed_but_exception(session, create_dialog):
assert session.alert.text == dialog_type assert session.alert.text == dialog_type
session.alert.dismiss() session.alert.dismiss()
assert not is_minimized(session) assert not document_hidden(session)
return check_user_prompt_not_closed_but_exception return check_user_prompt_not_closed_but_exception

Просмотреть файл

@ -5,7 +5,7 @@ import pytest
from webdriver.transport import Response from webdriver.transport import Response
from tests.support.asserts import assert_error, assert_success from tests.support.asserts import assert_error, assert_success
from tests.support.helpers import is_fullscreen from tests.support.helpers import document_hidden, is_fullscreen
def set_window_rect(session, rect): def set_window_rect(session, rect):
@ -144,14 +144,14 @@ def test_fully_exit_fullscreen(session):
def test_restore_from_minimized(session): def test_restore_from_minimized(session):
session.window.minimize() session.window.minimize()
assert session.execute_script("return document.hidden") is True assert document_hidden(session)
response = set_window_rect(session, {"width": 450, "height": 450}) response = set_window_rect(session, {"width": 450, "height": 450})
value = assert_success(response) value = assert_success(response)
assert value["width"] == 450 assert value["width"] == 450
assert value["height"] == 450 assert value["height"] == 450
assert session.execute_script("return document.hidden") is False assert not document_hidden(session)
def test_restore_from_maximized(session): def test_restore_from_maximized(session):

Просмотреть файл

@ -5,6 +5,8 @@ import sys
import webdriver import webdriver
from tests.support import defaults from tests.support import defaults
from tests.support.sync import Poll
def ignore_exceptions(f): def ignore_exceptions(f):
def inner(*args, **kwargs): def inner(*args, **kwargs):
@ -119,6 +121,13 @@ def is_element_in_viewport(session, element):
""", args=(element,)) """, args=(element,))
def document_hidden(session):
"""Polls for the document to become hidden."""
def hidden(session):
return session.execute_script("return document.hidden")
return Poll(session, timeout=3, raises=None).until(hidden)
def is_fullscreen(session): def is_fullscreen(session):
# At the time of writing, WebKit does not conform to the # At the time of writing, WebKit does not conform to the
# Fullscreen API specification. # Fullscreen API specification.