summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authormarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-18 21:37:32 +0000
committermarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-18 21:37:32 +0000
commit083a842dd60f47f3f1171cf067da65f2a0d6e911 (patch)
treea822f42e270301fe6cbe0266b618d10e18a5eb87 /tools
parent6e6c3f64277cf6cbdfa028dd3ce14a540c91d316 (diff)
downloadchromium_src-083a842dd60f47f3f1171cf067da65f2a0d6e911.zip
chromium_src-083a842dd60f47f3f1171cf067da65f2a0d6e911.tar.gz
chromium_src-083a842dd60f47f3f1171cf067da65f2a0d6e911.tar.bz2
Telemetry: more robust waiting after clicks and page loads.
When running the memory benchmark against the reference build, sometimes links were not found, but giving the page more time fixed the issue. BUG=158323 NOTRY=true Review URL: https://codereview.chromium.org/11565032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173786 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/page_sets/top_25.json110
-rw-r--r--tools/telemetry/telemetry/click_element_interaction.py28
-rw-r--r--tools/telemetry/telemetry/page.py27
-rw-r--r--tools/telemetry/telemetry/page_runner.py12
-rw-r--r--tools/telemetry/telemetry/util.py22
5 files changed, 128 insertions, 71 deletions
diff --git a/tools/perf/page_sets/top_25.json b/tools/perf/page_sets/top_25.json
index 4d6e48e..23b6d6b 100644
--- a/tools/perf/page_sets/top_25.json
+++ b/tools/perf/page_sets/top_25.json
@@ -9,6 +9,7 @@
"scrolling": {
"action": "scrolling_interaction"
},
+ "wait_for_element_with_text": "Next",
"stress_memory": {
"action": "compound_interaction",
"actions": [
@@ -18,7 +19,8 @@
{
"action": "click_element_interaction",
"text": "Next",
- "wait_for_href_change": true
+ "wait_for_href_change": true,
+ "wait_for_element_with_text": "Next"
},
{
"action": "scrolling_interaction"
@@ -26,7 +28,8 @@
{
"action": "click_element_interaction",
"text": "Next",
- "wait_for_href_change": true
+ "wait_for_href_change": true,
+ "wait_for_element_with_text": "Next"
},
{
"action": "scrolling_interaction"
@@ -34,7 +37,8 @@
{
"action": "click_element_interaction",
"text": "Next",
- "wait_for_href_change": true
+ "wait_for_href_change": true,
+ "wait_for_element_with_text": "Previous"
},
{
"action": "scrolling_interaction"
@@ -42,7 +46,8 @@
{
"action": "click_element_interaction",
"text": "Previous",
- "wait_for_href_change": true
+ "wait_for_href_change": true,
+ "wait_for_element_with_text": "Previous"
},
{
"action": "scrolling_interaction"
@@ -50,7 +55,8 @@
{
"action": "click_element_interaction",
"text": "Previous",
- "wait_for_href_change": true
+ "wait_for_href_change": true,
+ "wait_for_element_with_text": "Previous"
},
{
"action": "scrolling_interaction"
@@ -58,7 +64,8 @@
{
"action": "click_element_interaction",
"text": "Previous",
- "wait_for_href_change": true
+ "wait_for_href_change": true,
+ "wait_for_element_with_text": "Images"
},
{
"action": "scrolling_interaction"
@@ -66,7 +73,8 @@
{
"action": "click_element_interaction",
"text": "Images",
- "wait_for_href_change": true
+ "wait_for_href_change": true,
+ "wait_for_element_with_text": "Images"
}
]
}
@@ -100,6 +108,7 @@
"url": "https://www.google.com/calendar/",
"why": "productivity, top google properties",
"credentials": "google",
+ "wait_for_element_with_selector": "div[class~=\"navForward\"]",
"scrolling": {
"action": "scrolling_interaction",
"scrollable_element_function": "function(callback) { callback(document.getElementById('scrolltimedeventswk')); }"
@@ -110,42 +119,50 @@
{
"action": "click_element_interaction",
"selector": "div[class~=\"navForward\"]",
- "wait_for_seconds": 0.1
+ "wait_for_seconds": 2,
+ "wait_for_element_with_selector": "div[class~=\"navForward\"]"
},
{
"action": "click_element_interaction",
"selector": "div[class~=\"navForward\"]",
- "wait_for_seconds": 0.1
+ "wait_for_seconds": 2,
+ "wait_for_element_with_selector": "div[class~=\"navForward\"]"
},
{
"action": "click_element_interaction",
"selector": "div[class~=\"navForward\"]",
- "wait_for_seconds": 0.1
+ "wait_for_seconds": 2,
+ "wait_for_element_with_selector": "div[class~=\"navForward\"]"
},
{
"action": "click_element_interaction",
"selector": "div[class~=\"navForward\"]",
- "wait_for_seconds": 0.1
+ "wait_for_seconds": 2,
+ "wait_for_element_with_selector": "div[class~=\"navBack\"]"
},
{
"action": "click_element_interaction",
"selector": "div[class~=\"navBack\"]",
- "wait_for_seconds": 0.1
+ "wait_for_seconds": 2,
+ "wait_for_element_with_selector": "div[class~=\"navBack\"]"
},
{
"action": "click_element_interaction",
"selector": "div[class~=\"navBack\"]",
- "wait_for_seconds": 0.1
+ "wait_for_seconds": 2,
+ "wait_for_element_with_selector": "div[class~=\"navBack\"]"
},
{
"action": "click_element_interaction",
"selector": "div[class~=\"navBack\"]",
- "wait_for_seconds": 0.1
+ "wait_for_seconds": 2,
+ "wait_for_element_with_selector": "div[class~=\"navBack\"]"
},
{
"action": "click_element_interaction",
"selector": "div[class~=\"navBack\"]",
- "wait_for_seconds": 0.1
+ "wait_for_seconds": 2,
+ "wait_for_element_with_selector": "div[class~=\"navBack\"]"
}
]
}
@@ -175,6 +192,7 @@
"url": "https://plus.google.com/110031535020051778989/posts",
"why": "social; top google property; Public profile; infinite scrolls",
"credentials": "google",
+ "wait_for_element_with_text": "Home",
"scrolling": {
"action": "scrolling_interaction",
"scroll_is_infinite": true
@@ -185,32 +203,32 @@
{
"action": "click_element_interaction",
"text": "Home",
- "wait_for_navigate": true
+ "wait_seconds": 2,
+ "wait_for_element_with_text": "Profile"
},
{
"action": "click_element_interaction",
"text": "Profile",
- "wait_for_navigate": true
+ "wait_seconds": 2,
+ "wait_for_element_with_text": "Explore"
},
{
"action": "click_element_interaction",
"text": "Explore",
- "wait_for_navigate": true
+ "wait_seconds": 2,
+ "wait_for_element_with_text": "Events"
},
{
"action": "click_element_interaction",
"text": "Events",
- "wait_for_navigate": true
- },
- {
- "action": "click_element_interaction",
- "text": "Photos",
- "wait_for_navigate": true
+ "wait_seconds": 2,
+ "wait_for_element_with_text": "Circles"
},
{
"action": "click_element_interaction",
"text": "Circles",
- "wait_for_navigate": true
+ "wait_seconds": 2,
+ "wait_for_element_with_text": "Home"
}
]
}
@@ -227,6 +245,7 @@
"name": "Blogger",
"url": "http://googlewebmastercentral.blogspot.com/",
"why": "#11 (Alexa global), google property; some blogger layouts have infinite scroll but more interesting",
+ "wait_for_element_with_text": "accessibility",
"scrolling": {
"action": "scrolling_interaction"
},
@@ -236,7 +255,8 @@
{
"action": "click_element_interaction",
"text": "accessibility",
- "wait_for_navigate": true
+ "wait_for_navigate": true,
+ "wait_for_element_with_text": "advanced"
},
{
"action": "scrolling_interaction"
@@ -244,7 +264,8 @@
{
"action": "click_element_interaction",
"text": "advanced",
- "wait_for_navigate": true
+ "wait_for_navigate": true,
+ "wait_for_element_with_text": "beginner"
},
{
"action": "scrolling_interaction"
@@ -252,7 +273,8 @@
{
"action": "click_element_interaction",
"text": "beginner",
- "wait_for_navigate": true
+ "wait_for_navigate": true,
+ "wait_for_element_with_text": "Home"
},
{
"action": "scrolling_interaction"
@@ -260,7 +282,8 @@
{
"action": "click_element_interaction",
"text": "Home",
- "wait_for_navigate": true
+ "wait_for_navigate": true,
+ "wait_for_element_with_text": "Home"
}
]
}
@@ -269,6 +292,7 @@
"name": "Wordpress",
"url": "http://en.blog.wordpress.com/2012/09/04/freshly-pressed-editors-picks-for-august-2012/",
"why": "#18 (Alexa global), Picked an interesting post",
+ "wait_for_element_with_selector": "a[href=\"http://en.blog.wordpress.com/2012/08/30/new-themes-able-and-sight/\"]",
"scrolling": {
"action": "scrolling_interaction"
},
@@ -281,7 +305,8 @@
{
"action": "click_element_interaction",
"selector": "a[href=\"http://en.blog.wordpress.com/2012/08/30/new-themes-able-and-sight/\"]",
- "wait_for_navigate": true
+ "wait_for_navigate": true,
+ "wait_for_element_with_text": "Features"
},
{
"action": "scrolling_interaction"
@@ -289,7 +314,8 @@
{
"action": "click_element_interaction",
"text": "Features",
- "wait_for_navigate": true
+ "wait_for_navigate": true,
+ "wait_for_element_with_text": "News"
},
{
"action": "scrolling_interaction"
@@ -297,7 +323,8 @@
{
"action": "click_element_interaction",
"text": "News",
- "wait_for_navigate": true
+ "wait_for_navigate": true,
+ "wait_for_element_with_text": "News"
},
{
"action": "scrolling_interaction"
@@ -310,6 +337,7 @@
"url": "http://www.facebook.com/barackobama",
"why": "top social,Public profile",
"credentials": "facebook",
+ "wait_for_element_with_text": "About",
"scrolling": {
"action": "scrolling_interaction",
"scroll_is_infinite": true
@@ -320,32 +348,38 @@
{
"action": "click_element_interaction",
"text": "About",
- "wait_for_navigate": true
+ "wait_for_navigate": true,
+ "wait_for_element_with_text": "The Audacity of Hope"
},
{
"action": "click_element_interaction",
"text": "The Audacity of Hope",
- "wait_for_navigate": true
+ "wait_for_navigate": true,
+ "wait_for_element_with_text": "Back to Barack Obama's Timeline"
},
{
"action": "click_element_interaction",
"text": "Back to Barack Obama's Timeline",
- "wait_for_navigate": true
+ "wait_for_navigate": true,
+ "wait_for_element_with_text": "About"
},
{
"action": "click_element_interaction",
"text": "About",
- "wait_for_navigate": true
+ "wait_for_navigate": true,
+ "wait_for_element_with_text": "Elected to U.S. Senate"
},
{
"action": "click_element_interaction",
"text": "Elected to U.S. Senate",
- "wait_for_navigate": true
+ "wait_for_navigate": true,
+ "wait_for_element_with_text": "Home"
},
{
"action": "click_element_interaction",
"text": "Home",
- "wait_for_navigate": true
+ "wait_for_navigate": true,
+ "wait_for_element_with_text": "Home"
}
]
}
diff --git a/tools/telemetry/telemetry/click_element_interaction.py b/tools/telemetry/telemetry/click_element_interaction.py
index 44d1a51..8c1b5ca 100644
--- a/tools/telemetry/telemetry/click_element_interaction.py
+++ b/tools/telemetry/telemetry/click_element_interaction.py
@@ -1,9 +1,8 @@
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import time
-
from telemetry import inspector_runtime
+from telemetry import page as page_module
from telemetry import page_interaction
from telemetry import util
@@ -22,21 +21,10 @@ class ClickElementInteraction(page_interaction.PageInteraction):
raise page_interaction.PageInteractionFailed(
'Cannot find element with selector ' + self.selector)
else:
- click_element = """
- function clickElement(element, text) {
- if (element.innerHTML == text) {
- element.click();
- return true;
- }
- for (var i in element.childNodes) {
- if (clickElement(element.childNodes[i], text))
- return true;
- }
- return false;
- }"""
- tab.runtime.Execute(click_element)
- code = 'clickElement(document, "' + self.text + '");'
- if not tab.runtime.Evaluate(code):
+ callback_code = 'function(element) { element.click(); }'
+ try:
+ util.FindElementAndPerformAction(tab, self.text, callback_code)
+ except inspector_runtime.EvaluateException:
raise page_interaction.PageInteractionFailed(
'Cannot find element with text ' + self.text)
@@ -47,10 +35,8 @@ class ClickElementInteraction(page_interaction.PageInteraction):
DoClick()
util.WaitFor(lambda: tab.runtime.Evaluate(
'document.location.href') != old_url, 60)
- elif hasattr(self, 'wait_seconds'):
- time.sleep(self.wait_seconds)
- DoClick()
else:
DoClick()
- tab.WaitForDocumentReadyStateToBeComplete()
+ page_module.Page.WaitForPageToLoad(self, tab, 60)
+ tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
diff --git a/tools/telemetry/telemetry/page.py b/tools/telemetry/telemetry/page.py
index 0be70dc..08b634d 100644
--- a/tools/telemetry/telemetry/page.py
+++ b/tools/telemetry/telemetry/page.py
@@ -3,8 +3,11 @@
# found in the LICENSE file.
import os
import re
+import time
import urlparse
+from telemetry import util
+
class Page(object):
def __init__(self, url, attributes=None, base_dir=None):
parsed_url = urlparse.urlparse(url)
@@ -18,7 +21,6 @@ class Page(object):
self.base_dir = base_dir
self.credentials = None
self.wait_time_after_navigate = 2
- self.wait_for_javascript_expression = None
if attributes:
for k, v in attributes.iteritems():
@@ -58,3 +60,26 @@ class Page(object):
def __str__(self):
return self.url
+
+ def WaitToLoad(self, tab, timeout, poll_interval=0.1):
+ Page.WaitForPageToLoad(self, tab, timeout, poll_interval)
+
+ @staticmethod
+ def WaitForPageToLoad(obj, tab, timeout, poll_interval=0.1):
+ """Waits for various wait conditions present in obj."""
+ if hasattr(obj, 'wait_seconds'):
+ time.sleep(obj.wait_seconds)
+ if hasattr(obj, 'wait_for_element_with_text'):
+ callback_code = 'function(element) { return element != null; }'
+ util.WaitFor(
+ lambda: util.FindElementAndPerformAction(
+ tab, obj.wait_for_element_with_text, callback_code),
+ timeout, poll_interval)
+ if hasattr(obj, 'wait_for_element_with_selector'):
+ util.WaitFor(lambda: tab.runtime.Evaluate(
+ 'document.querySelector(\'' + obj.wait_for_element_with_selector +
+ '\') != null'), timeout, poll_interval)
+ if hasattr(obj, 'wait_for_javascript_expression'):
+ util.WaitFor(
+ lambda: tab.runtime.Evaluate(obj.wait_for_javascript_expression),
+ timeout, poll_interval)
diff --git a/tools/telemetry/telemetry/page_runner.py b/tools/telemetry/telemetry/page_runner.py
index c19d74a..fc799cf 100644
--- a/tools/telemetry/telemetry/page_runner.py
+++ b/tools/telemetry/telemetry/page_runner.py
@@ -202,14 +202,6 @@ http://goto/read-src-internal, or create a new archive using record_wpr.
def Close(self):
pass
- @staticmethod
- def WaitForPageToLoad(expression, tab):
- def IsPageLoaded():
- return tab.runtime.Evaluate(expression)
-
- # Wait until the form is submitted and the page completes loading.
- util.WaitFor(IsPageLoaded, 60)
-
def _SetupBrowser(self, state, test, possible_browser, credentials_path,
archive_path):
assert not state.tab
@@ -276,9 +268,7 @@ http://goto/read-src-internal, or create a new archive using record_wpr.
# Wait for unpredictable redirects.
if page.wait_time_after_navigate:
time.sleep(page.wait_time_after_navigate)
- if page.wait_for_javascript_expression is not None:
- self.WaitForPageToLoad(page.wait_for_javascript_expression, tab)
-
+ page.WaitToLoad(tab, 60)
tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
return True
diff --git a/tools/telemetry/telemetry/util.py b/tools/telemetry/telemetry/util.py
index 3d6f2d2..cd8e420 100644
--- a/tools/telemetry/telemetry/util.py
+++ b/tools/telemetry/telemetry/util.py
@@ -30,3 +30,25 @@ def WaitFor(condition,
raise TimeoutException('Timed out while waiting %ds for %s.' %
(timeout, condition_string))
time.sleep(poll_interval)
+
+def FindElementAndPerformAction(tab, text, callback_code):
+ """JavaScript snippet for finding an element with a given text on a page."""
+ code = """
+ (function() {
+ var callback_function = """ + callback_code + """;
+ function _findElement(element, text) {
+ if (element.innerHTML == text) {
+ callback_function
+ return element;
+ }
+ for (var i in element.childNodes) {
+ var found = _findElement(element.childNodes[i], text);
+ if (found)
+ return found;
+ }
+ return null;
+ }
+ var _element = _findElement(document, \"""" + text + """\");
+ return callback_function(_element);
+ })();"""
+ return tab.runtime.Evaluate(code)