forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtop_7_stress.py
324 lines (266 loc) · 11.9 KB
/
top_7_stress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# Copyright 2014 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.
from telemetry.page import page as page_module
from telemetry.page import page_set as page_set_module
def _GetCurrentLocation(action_runner):
return action_runner.EvaluateJavaScript('document.location.href')
def _WaitForLocationChange(action_runner, old_href):
action_runner.WaitForJavaScriptCondition(
'document.location.href != "%s"' % old_href)
class Top7StressPage(page_module.Page):
def __init__(self, url, page_set, name=''):
super(Top7StressPage, self).__init__(
url=url, page_set=page_set, name=name,
credentials_path = 'data/credentials.json')
self.user_agent_type = 'desktop'
self.archive_data_file = 'data/top_7_stress.json'
def RunPageInteractions(self, action_runner):
raise NotImplementedError()
class GoogleWebSearchPage(Top7StressPage):
""" Why: top google property; a google tab is often open """
def __init__(self, page_set):
super(GoogleWebSearchPage, self).__init__(
url='https://www.google.com/#hl=en&q=barack+obama',
page_set=page_set)
def RunNavigateSteps(self, action_runner):
super(GoogleWebSearchPage, self).RunNavigateSteps(action_runner)
action_runner.WaitForElement(text='Next')
def RunPageInteractions(self, action_runner):
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
old_href = _GetCurrentLocation(action_runner)
action_runner.ClickElement(text='Next')
_WaitForLocationChange(action_runner, old_href)
action_runner.WaitForElement(text='Next')
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
old_href = _GetCurrentLocation(action_runner)
action_runner.ClickElement(text='Next')
_WaitForLocationChange(action_runner, old_href)
action_runner.WaitForElement(text='Next')
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
old_href = _GetCurrentLocation(action_runner)
action_runner.ClickElement(text='Next')
_WaitForLocationChange(action_runner, old_href)
action_runner.WaitForElement(text='Previous')
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
old_href = _GetCurrentLocation(action_runner)
action_runner.ClickElement(text='Previous')
_WaitForLocationChange(action_runner, old_href)
action_runner.WaitForElement(text='Previous')
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
old_href = _GetCurrentLocation(action_runner)
action_runner.ClickElement(text='Previous')
_WaitForLocationChange(action_runner, old_href)
action_runner.WaitForElement(text='Previous')
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
old_href = _GetCurrentLocation(action_runner)
action_runner.ClickElement(text='Previous')
_WaitForLocationChange(action_runner, old_href)
action_runner.WaitForElement(text='Images')
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
old_href = _GetCurrentLocation(action_runner)
action_runner.ClickElement(text='Images')
_WaitForLocationChange(action_runner, old_href)
action_runner.WaitForElement(text='Images')
class GmailPage(Top7StressPage):
""" Why: productivity, top google properties """
def __init__(self, page_set):
super(GmailPage, self).__init__(
url='https://mail.google.com/mail/',
page_set=page_set)
self.credentials = 'google'
def RunNavigateSteps(self, action_runner):
super(GmailPage, self).RunNavigateSteps(action_runner)
action_runner.WaitForJavaScriptCondition(
'window.gmonkey !== undefined &&'
'document.getElementById("gb") !== null')
def RunPageInteractions(self, action_runner):
old_href = _GetCurrentLocation(action_runner)
action_runner.ClickElement(
'a[href="https://mail.google.com/mail/u/0/?shva=1#starred"]')
_WaitForLocationChange(action_runner, old_href)
old_href = _GetCurrentLocation(action_runner)
action_runner.ClickElement(
'a[href="https://mail.google.com/mail/u/0/?shva=1#inbox"]')
_WaitForLocationChange(action_runner, old_href)
class GoogleCalendarPage(Top7StressPage):
""" Why: productivity, top google properties """
def __init__(self, page_set):
super(GoogleCalendarPage, self).__init__(
url='https://www.google.com/calendar/',
page_set=page_set)
self.credentials = 'google'
def RunNavigateSteps(self, action_runner):
super(GoogleCalendarPage, self).RunNavigateSteps(action_runner)
action_runner.Wait(2)
action_runner.WaitForElement('div[class~="navForward"]')
action_runner.ExecuteJavaScript('''
(function() {
var elem = document.createElement('meta');
elem.name='viewport';
elem.content='initial-scale=1';
document.body.appendChild(elem);
})();''')
action_runner.Wait(1)
def RunPageInteractions(self, action_runner):
action_runner.ClickElement('div[class~="navForward"]')
action_runner.Wait(2)
action_runner.WaitForElement('div[class~="navForward"]')
action_runner.ClickElement('div[class~="navForward"]')
action_runner.Wait(2)
action_runner.WaitForElement('div[class~="navForward"]')
action_runner.ClickElement('div[class~="navForward"]')
action_runner.Wait(2)
action_runner.WaitForElement('div[class~="navForward"]')
action_runner.ClickElement('div[class~="navForward"]')
action_runner.Wait(2)
action_runner.WaitForElement('div[class~="navBack"]')
action_runner.ClickElement('div[class~="navBack"]')
action_runner.Wait(2)
action_runner.WaitForElement('div[class~="navBack"]')
action_runner.ClickElement('div[class~="navBack"]')
action_runner.Wait(2)
action_runner.WaitForElement('div[class~="navBack"]')
action_runner.ClickElement('div[class~="navBack"]')
action_runner.Wait(2)
action_runner.WaitForElement('div[class~="navBack"]')
action_runner.ClickElement('div[class~="navBack"]')
action_runner.Wait(2)
action_runner.WaitForElement('div[class~="navBack"]')
class GooglePlusPage(Top7StressPage):
""" Why: social; top google property; Public profile; infinite scrolls """
def __init__(self, page_set):
super(GooglePlusPage, self).__init__(
url='https://plus.google.com/110031535020051778989/posts',
page_set=page_set)
self.credentials = 'google'
def RunNavigateSteps(self, action_runner):
super(GooglePlusPage, self).RunNavigateSteps(action_runner)
action_runner.WaitForElement(text='Home')
def RunPageInteractions(self, action_runner):
action_runner.ClickElement(text='Home')
action_runner.Wait(2)
action_runner.WaitForElement(text='Profile')
action_runner.ClickElement(text='Profile')
action_runner.Wait(2)
action_runner.WaitForElement(text='Explore')
action_runner.ClickElement(text='Explore')
action_runner.Wait(2)
action_runner.WaitForElement(text='Events')
action_runner.ClickElement(text='Events')
action_runner.Wait(2)
action_runner.WaitForElement(text='Communities')
action_runner.ClickElement(text='Communities')
action_runner.Wait(2)
action_runner.WaitForElement(text='Home')
class BlogspotPage(Top7StressPage):
""" Why: #11 (Alexa global), google property; some blogger layouts have
infinite scroll but more interesting """
def __init__(self, page_set):
super(BlogspotPage, self).__init__(
url='http://googlewebmastercentral.blogspot.com/',
page_set=page_set,
name='Blogger')
def RunNavigateSteps(self, action_runner):
super(BlogspotPage, self).RunNavigateSteps(action_runner)
action_runner.WaitForElement(text='accessibility')
def RunPageInteractions(self, action_runner):
action_runner.ClickElement(text='accessibility')
action_runner.WaitForNavigate()
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
# Insert 300ms wait to simulate user finger movement,
# and ensure scheduling of idle tasks.
action_runner.Wait(0.3)
action_runner.ClickElement(text='advanced')
action_runner.WaitForNavigate()
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
action_runner.Wait(0.3)
action_runner.ClickElement(text='beginner')
action_runner.WaitForNavigate()
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
action_runner.Wait(0.3)
action_runner.ClickElement(text='Home')
action_runner.WaitForNavigate()
class WordpressPage(Top7StressPage):
""" Why: #18 (Alexa global), Picked an interesting post """
def __init__(self, page_set):
super(WordpressPage, self).__init__(
# pylint: disable=C0301
url='http://en.blog.wordpress.com/2012/09/04/freshly-pressed-editors-picks-for-august-2012/',
page_set=page_set,
name='Wordpress')
def RunNavigateSteps(self, action_runner):
super(WordpressPage, self).RunNavigateSteps(action_runner)
action_runner.WaitForElement(
# pylint: disable=C0301
'a[href="http://en.blog.wordpress.com/2012/08/30/new-themes-able-and-sight/"]')
def RunPageInteractions(self, action_runner):
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
# Insert 300ms wait to simulate user finger movement,
# and ensure scheduling of idle tasks.
action_runner.Wait(0.3)
action_runner.ClickElement(
# pylint: disable=C0301
'a[href="http://en.blog.wordpress.com/2012/08/30/new-themes-able-and-sight/"]')
action_runner.WaitForNavigate()
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
action_runner.Wait(0.3)
action_runner.ClickElement(text='Features')
action_runner.WaitForNavigate()
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
action_runner.Wait(0.3)
action_runner.ClickElement(text='News')
action_runner.WaitForNavigate()
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
class FacebookPage(Top7StressPage):
""" Why: top social,Public profile """
def __init__(self, page_set):
super(FacebookPage, self).__init__(
url='https://www.facebook.com/barackobama',
page_set=page_set,
name='Facebook')
self.credentials = 'facebook2'
def RunNavigateSteps(self, action_runner):
super(FacebookPage, self).RunNavigateSteps(action_runner)
action_runner.WaitForElement(text='About')
def RunPageInteractions(self, action_runner):
# Scroll and wait for the next page to be loaded.
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
action_runner.WaitForJavaScriptCondition(
'document.documentElement.scrollHeight - window.innerHeight - '
'window.pageYOffset > 0')
# Scroll and wait again.
with action_runner.CreateGestureInteraction('ScrollAction'):
action_runner.ScrollPage()
action_runner.WaitForJavaScriptCondition(
'document.documentElement.scrollHeight - window.innerHeight - '
'window.pageYOffset > 0')
class Top7StressPageSet(page_set_module.PageSet):
""" Pages hand-picked for stress testing. """
def __init__(self):
super(Top7StressPageSet, self).__init__(
user_agent_type='desktop',
archive_data_file='data/top_7_stress.json',
bucket=page_set_module.PARTNER_BUCKET)
self.AddUserStory(GoogleWebSearchPage(self))
self.AddUserStory(GmailPage(self))
self.AddUserStory(GoogleCalendarPage(self))
self.AddUserStory(GooglePlusPage(self))
self.AddUserStory(BlogspotPage(self))
self.AddUserStory(WordpressPage(self))
self.AddUserStory(FacebookPage(self))