Commit ebfc7be6 authored by leilei's avatar leilei Committed by Commit bot

Fix the flakiness issue in Telemetry tests.

+ Implement a more stable way to check if the dialog is fully loaded before choose the sink, instead of hardcoding the waiting time.

+ Also increase the timeout for stopping session.

Review-Url: https://codereview.chromium.org/2166433003
Cr-Commit-Position: refs/heads/master@{#406756}
parent 2ff90f4a
...@@ -91,6 +91,21 @@ class CastPage(page.Page): ...@@ -91,6 +91,21 @@ class CastPage(page.Page):
self._WaitForResult(action_runner, verify_func, error_message, self._WaitForResult(action_runner, verify_func, error_message,
timeout=timeout) timeout=timeout)
def WaitUntilDialogLoaded(self, action_runner, tab):
"""Waits until dialog is fully loaded."""
self._WaitForResult(
action_runner,
lambda: tab.EvaluateJavaScript(
'!!window.document.getElementById('
'"media-router-container") &&'
'window.document.getElementById('
'"media-router-container").sinksToShow_ &&'
'window.document.getElementById('
'"media-router-container").sinksToShow_.length'),
'The dialog is not fully loaded within 15s.',
timeout=15)
def _WaitForResult(self, action_runner, verify_func, error_message, def _WaitForResult(self, action_runner, verify_func, error_message,
timeout=5): timeout=5):
"""Waits until the function finishes or timeout.""" """Waits until the function finishes or timeout."""
......
...@@ -92,11 +92,10 @@ class CastFlingingPage(media_router_page.CastPage): ...@@ -92,11 +92,10 @@ class CastFlingingPage(media_router_page.CastPage):
lambda: len(action_runner.tab.browser.tabs) >= 2, lambda: len(action_runner.tab.browser.tabs) >= 2,
'MR dialog never showed up.') 'MR dialog never showed up.')
# Wait for 2s to make sure the dialog is fully loaded.
action_runner.Wait(2)
for tab in action_runner.tab.browser.tabs: for tab in action_runner.tab.browser.tabs:
# Choose sink # Choose sink
if tab.url == 'chrome://media-router/': if tab.url == 'chrome://media-router/':
self.WaitUntilDialogLoaded(action_runner, tab)
self.ChooseSink(tab, sink_name) self.ChooseSink(tab, sink_name)
self._WaitForResult( self._WaitForResult(
...@@ -121,7 +120,8 @@ class CastFlingingPage(media_router_page.CastPage): ...@@ -121,7 +120,8 @@ class CastFlingingPage(media_router_page.CastPage):
action_runner, action_runner,
'stopSession();', 'stopSession();',
lambda: not action_runner.EvaluateJavaScript('currentSession'), lambda: not action_runner.EvaluateJavaScript('currentSession'),
'Failed to stop session') 'Failed to stop session',
timeout=30)
class CastMirroringPage(media_router_page.CastPage): class CastMirroringPage(media_router_page.CastPage):
...@@ -147,11 +147,10 @@ class CastMirroringPage(media_router_page.CastPage): ...@@ -147,11 +147,10 @@ class CastMirroringPage(media_router_page.CastPage):
lambda: len(action_runner.tab.browser.tabs) >= 2, lambda: len(action_runner.tab.browser.tabs) >= 2,
'MR dialog never showed up.') 'MR dialog never showed up.')
# Wait for 2s to make sure the dialog is fully loaded.
action_runner.Wait(2)
for tab in action_runner.tab.browser.tabs: for tab in action_runner.tab.browser.tabs:
# Choose sink # Choose sink
if tab.url == 'chrome://media-router/': if tab.url == 'chrome://media-router/':
self.WaitUntilDialogLoaded(action_runner, tab)
self.ChooseSink(tab, sink_name) self.ChooseSink(tab, sink_name)
# Wait for 5s to make sure the route is created. # Wait for 5s to make sure the route is created.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment