Chromium Code Reviews| Index: tools/chrome_proxy/webdriver/common.py |
| diff --git a/tools/chrome_proxy/webdriver/common.py b/tools/chrome_proxy/webdriver/common.py |
| index d44ceabeae52136d56be5817513bf2804709bd15..c66f4afd941ee59c91a388827402870200f8f2bb 100644 |
| --- a/tools/chrome_proxy/webdriver/common.py |
| +++ b/tools/chrome_proxy/webdriver/common.py |
| @@ -219,6 +219,15 @@ class TestDriver: |
| self._driver.set_page_load_timeout(timeout) |
| self._driver.get(self._url) |
| + def GetURL(self, url, timeout=30): |
|
RyanSturm
2016/12/12 20:02:46
I'd prefer LoadURL. This seems a little backwards
Robert Ogden
2016/12/13 16:36:31
Done.
|
| + """Convenience function for SetURL() followed by LoadPage() |
| + Args: |
| + url: the URL to navigate to |
| + timeout: the time in seconds to load the page before timing out |
| + """ |
| + self.SetURL(url) |
|
RyanSturm
2016/12/12 20:02:46
For now, forcing us to use GetURL with a param eve
Robert Ogden
2016/12/13 16:36:31
Acknowledged.
|
| + self.LoadPage(timeout) |
| + |
| def ExecuteJavascript(self, script, timeout=30): |
| """Executes the given javascript in the browser's current page in an |
| anonymous function. |
| @@ -260,6 +269,29 @@ class TestDriver: |
| string_response = self.ExecuteJavascriptStatement(js_query) |
| return json.loads(string_response) |
| + def WaitForJavascriptExpression(self, expression, timeout, min_poll=0.1, |
| + max_poll=1): |
| + """Waits for the given Javascript expression to evaluate to True within the |
| + given timeout. This method polls the Javascript expression within the range |
| + of min_poll and max_poll. |
| + |
| + Args: |
| + expression: The Javascript expression to poll, as a string |
| + min_poll: The most frequently to poll as a float |
| + max_poll: The least frequently to poll as a float |
| + Returns: the result of the expression |
| + """ |
| + poll_interval = max(min(max_poll, float(timeout) / 10.0), min_poll) |
| + result = self.ExecuteJavascriptStatement(expression) |
| + total_waited_time = 0 |
| + while not result and total_waited_time < timeout: |
| + time.sleep(poll_interval) |
| + total_waited_time += poll_interval |
| + result = self.ExecuteJavascriptStatement(expression) |
| + if not result: |
| + raise Exception('%s not true after %f seconds' % (expression, timeout)) |
| + return result |
| + |
| def GetPerformanceLogs(self, method_filter=r'Network\.responseReceived'): |
| """Returns all logged Performance events from Chrome. |