Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Unified Diff: tools/chrome_proxy/webdriver/common.py

Issue 2560243002: Add GetURL() and WaitForJSExpression() functions (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/chrome_proxy/webdriver/simple_smoke.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « no previous file | tools/chrome_proxy/webdriver/simple_smoke.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698