Skip to content

Commit f8e19a4

Browse files
committed
Test waitForNavigation returns None on anchor link or navigation due to history
1 parent d825329 commit f8e19a4

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

pyppeteer/page.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,8 @@ async def waitForNavigation(self, options: dict = None, **kwargs: Any
894894
which will indirectly cause the page to navigate. In case of navigation
895895
to a different anchor or navigation due to
896896
`History API <https://developer.mozilla.org/en-US/docs/Web/API/History_API>`_
897-
usage, the
898-
navigation will return ``None``.
897+
usage, the navigation will return ``None``.
898+
899899
Consider this example:
900900
901901
.. code::

tests/test_page.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,11 @@ async def test_both_domcontentloaded_loaded(self):
614614
async def test_click_anchor_link(self):
615615
await self.page.goto(self.url + 'empty')
616616
await self.page.setContent('<a href="#foobar">foobar</a>')
617-
await asyncio.wait([
618-
self.page.click('a'),
617+
results = await asyncio.gather(
619618
self.page.waitForNavigation(),
620-
])
619+
self.page.click('a'),
620+
)
621+
self.assertIsNone(results[0])
621622
self.assertEqual(self.page.url, self.url + 'empty#foobar')
622623

623624
@sync
@@ -637,10 +638,11 @@ async def test_history_push_state(self):
637638
function pushState() { history.pushState({}, '', 'wow.html') }
638639
</script>
639640
''')
640-
await asyncio.wait([
641-
self.page.click('a'),
641+
results = await asyncio.gather(
642642
self.page.waitForNavigation(),
643-
])
643+
self.page.click('a'),
644+
)
645+
self.assertIsNone(results[0])
644646
self.assertEqual(self.page.url, self.url + 'wow.html')
645647

646648
@sync
@@ -654,10 +656,11 @@ async def test_history_replace_state(self):
654656
}
655657
</script>
656658
''')
657-
await asyncio.wait([
658-
self.page.click('a'),
659+
results = await asyncio.gather(
659660
self.page.waitForNavigation(),
660-
])
661+
self.page.click('a'),
662+
)
663+
self.assertIsNone(results[0])
661664
self.assertEqual(self.page.url, self.url + 'replaced.html')
662665

663666
@sync
@@ -674,15 +677,18 @@ async def test_dom_history_back_forward(self):
674677
</script>
675678
''')
676679
self.assertEqual(self.page.url, self.url + 'second.html')
677-
await asyncio.wait([
678-
self.page.click('a#back'),
680+
results_back = await asyncio.gather(
679681
self.page.waitForNavigation(),
680-
])
682+
self.page.click('a#back'),
683+
)
684+
self.assertIsNone(results_back[0])
681685
self.assertEqual(self.page.url, self.url + 'first.html')
682-
await asyncio.wait([
683-
self.page.click('a#forward'),
686+
687+
results_forward = await asyncio.gather(
684688
self.page.waitForNavigation(),
685-
])
689+
self.page.click('a#forward'),
690+
)
691+
self.assertIsNone(results_forward[0])
686692
self.assertEqual(self.page.url, self.url + 'second.html')
687693

688694
@sync

0 commit comments

Comments
 (0)