Bug 1751954 - [marionette] Improve tests for PageLoadStrategy "none" in test_navigation.py. r=webdriver-reviewers,jgraham

By using an URL that is delaying any response by a certain
amount of time it is easier to check for the PageLoadStrategy
"none" as when we only have a lazily loaded resource where
the element to wait for might immediately be available.

Differential Revision: https://phabricator.services.mozilla.com/D137112
This commit is contained in:
Henrik Skupin 2022-01-28 20:29:10 +00:00
Родитель 0c3fecd629
Коммит 0ec2163f51
1 изменённых файлов: 39 добавлений и 23 удалений

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

@ -47,10 +47,6 @@ class BaseNavigationTestCase(WindowManagerMixin, MarionetteTestCase):
"navigation_pushstate.html"
)
self.test_page_remote = self.marionette.absolute_url("test.html")
self.test_page_slow_coop = self.marionette.absolute_url("slow-coop")
self.test_page_slow_resource = self.marionette.absolute_url(
"slow_resource.html"
)
if self.marionette.session_capabilities["platformName"] == "mac":
self.mod_key = Keys.META
@ -848,6 +844,23 @@ class TestTLSNavigation(BaseNavigationTestCase):
class TestPageLoadStrategy(BaseNavigationTestCase):
def setUp(self):
super(TestPageLoadStrategy, self).setUp()
# Test page that delays the response and as such the document to be
# loaded. It is used for testing the page load strategy "none".
self.test_page_slow = self.marionette.absolute_url("slow")
# Similar to "slow" but additionally triggers a cross group navigation
# which triggers a replacement of the top-level browsing context.
self.test_page_slow_coop = self.marionette.absolute_url("slow-coop")
# Test page that contains a slow loading <img> element which delays the
# "load" but not the "DOMContentLoaded" event.
self.test_page_slow_resource = self.marionette.absolute_url(
"slow_resource.html"
)
def tearDown(self):
self.marionette.delete_session()
self.marionette.start_session()
@ -860,30 +873,33 @@ class TestPageLoadStrategy(BaseNavigationTestCase):
# Navigate will return immediately. As such wait for the target URL to
# be the current location, and the element to exist.
self.marionette.navigate(self.test_page_slow_resource)
Wait(self.marionette, timeout=self.marionette.timeout.page_load).until(
lambda _: self.marionette.get_url() == self.test_page_slow_resource,
message="Target page has not been loaded",
)
Wait(self.marionette, ignored_exceptions=errors.NoSuchElementException).until(
lambda _: self.marionette.find_element(By.ID, "slow")
)
self.marionette.navigate(self.test_page_slow)
with self.assertRaises(errors.NoSuchElementException):
self.marionette.find_element(By.ID, "delay")
Wait(
self.marionette,
ignored_exceptions=errors.NoSuchElementException,
timeout=self.marionette.timeout.page_load,
).until(lambda _: self.marionette.find_element(By.ID, "delay"))
self.assertEqual(self.marionette.get_url(), self.test_page_slow)
def test_none_with_new_session_waits_for_page_loaded(self):
self.marionette.delete_session()
self.marionette.start_session({"pageLoadStrategy": "none"})
# Navigate will return immediately.
self.marionette.navigate(self.test_page_slow_resource)
self.marionette.navigate(self.test_page_slow)
# Make sure that when creating a new session right away it waits
# until the page has been finished loading.
self.marionette.delete_session()
self.marionette.start_session()
self.assertEqual(self.test_page_slow_resource, self.marionette.get_url())
self.assertEqual("complete", self.ready_state)
self.marionette.find_element(By.ID, "slow")
self.assertEqual(self.marionette.get_url(), self.test_page_slow)
self.assertEqual(self.ready_state, "complete")
self.marionette.find_element(By.ID, "delay")
def test_none_with_new_session_waits_for_page_loaded_remoteness_change(self):
self.marionette.delete_session()
@ -897,8 +913,8 @@ class TestPageLoadStrategy(BaseNavigationTestCase):
self.marionette.delete_session()
self.marionette.start_session()
self.assertEqual(self.test_page_slow_coop, self.marionette.get_url())
self.assertEqual("complete", self.ready_state)
self.assertEqual(self.marionette.get_url(), self.test_page_slow_coop)
self.assertEqual(self.ready_state, "complete")
self.marionette.find_element(By.ID, "delay")
def test_eager(self):
@ -906,8 +922,8 @@ class TestPageLoadStrategy(BaseNavigationTestCase):
self.marionette.start_session({"pageLoadStrategy": "eager"})
self.marionette.navigate(self.test_page_slow_resource)
self.assertEqual("interactive", self.ready_state)
self.assertEqual(self.test_page_slow_resource, self.marionette.get_url())
self.assertEqual(self.ready_state, "interactive")
self.assertEqual(self.marionette.get_url(), self.test_page_slow_resource)
self.marionette.find_element(By.ID, "slow")
def test_normal(self):
@ -915,8 +931,8 @@ class TestPageLoadStrategy(BaseNavigationTestCase):
self.marionette.start_session({"pageLoadStrategy": "normal"})
self.marionette.navigate(self.test_page_slow_resource)
self.assertEqual(self.test_page_slow_resource, self.marionette.get_url())
self.assertEqual("complete", self.ready_state)
self.assertEqual(self.marionette.get_url(), self.test_page_slow_resource)
self.assertEqual(self.ready_state, "complete")
self.marionette.find_element(By.ID, "slow")
def test_strategy_after_remoteness_change(self):
@ -931,4 +947,4 @@ class TestPageLoadStrategy(BaseNavigationTestCase):
self.marionette.navigate("about:robots")
self.assertFalse(self.is_remote_tab, "Tab has remoteness flag set")
self.marionette.navigate(self.test_page_slow_resource)
self.assertEqual("interactive", self.ready_state)
self.assertEqual(self.ready_state, "interactive")