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

Side by Side Diff: components/test/data/password_manager/tests.py

Issue 273523004: Password Manager testing automation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months 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 unified diff | Download patch
OLDNEW
(Empty)
1 # -*- coding: utf-8 -*-
2 """Automated tests for many websites"""
3
4 import argparse
5 import logging
6
7 from environment import Environment
8 from websitetest import WebsiteTest
9
10
11 class Facebook(WebsiteTest):
12
13 def Login(self):
14 self.GoTo("https://www.facebook.com")
15 self.FillUsernameInto("[name='email']")
16 self.FillPasswordInto("[name='pass']")
17 self.Submit("[name='pass']")
18
19 def Logout(self):
20 self.WaitUntilDisplayed("#userNavigationLabel")
21 self.Click("#userNavigationLabel")
22 self.WaitUntilDisplayed("#logout_form [type='submit']")
23 self.Click("#logout_form [type='submit']")
24
25
26 class Google(WebsiteTest):
27
28 def Login(self):
29 self.GoTo("https://accounts.google.com/ServiceLogin?sacu=1&continue=")
30 self.FillUsernameInto("#Email")
31 self.FillPasswordInto("#Passwd")
32 self.Submit("#Passwd")
33
34 def Logout(self):
35 self.GoTo("https://accounts.google.com/Logout")
36
37
38 class Linkedin(WebsiteTest):
39
40 def Login(self):
41 self.GoTo("https://www.linkedin.com")
42 self.FillUsernameInto("#session_key-login")
43 self.FillPasswordInto("#session_password-login")
44 self.Submit("#session_password-login")
45
46 def Logout(self):
47 self.WaitUntilDisplayed(".account-toggle")
48 self.HoverOver(".account-toggle")
49 self.WaitUntilDisplayed(".account-settings .act-set-action")
50 self.Click(".account-settings .act-set-action")
51
52
53 class Mailru(WebsiteTest):
54
55 def Login(self):
56 self.GoTo("https://mail.ru")
57 self.FillUsernameInto("#mailbox__login")
58 self.FillPasswordInto("#mailbox__password")
59 self.Submit("#mailbox__password")
60
61 def Logout(self):
62 self.Click("#PH_logoutLink")
63
64
65 class Nytimes(WebsiteTest):
66
67 def Login(self):
68 self.GoTo("https://myaccount.nytimes.com/auth/login")
69 self.FillUsernameInto("#userid")
70 self.FillPasswordInto("#password")
71 self.Submit("#password")
72
73 def Logout(self):
74 self.GoTo("https://myaccount.nytimes.com/gst/signout")
75
76
77 class Pinterest(WebsiteTest):
78
79 def Login(self):
80 self.GoTo("https://www.pinterest.com/login/")
81 self.FillUsernameInto("[name='username_or_email']")
82 self.FillPasswordInto("[name='password']")
83 self.Submit("[name='password']")
84
85 def Logout(self):
86 self.GoTo("https://www.pinterest.com/logout/")
87
88
89 class Reddit(WebsiteTest):
90
91 def Login(self):
92 self.GoTo("http://www.reddit.com")
93 self.Click(".user .login-required")
94 self.FillUsernameInto("#user_login")
95 self.FillPasswordInto("#passwd_login")
96 self.Wait(2)
97 self.Submit("#passwd_login")
98
99 def Logout(self):
100 self.Click("form[action='http://www.reddit.com/logout'] a")
101
102
103 class Tumblr(WebsiteTest):
104
105 def Login(self):
106 self.GoTo("https://www.tumblr.com/login")
107 self.FillUsernameInto("#signup_email")
108 self.FillPasswordInto("#signup_password")
109 self.Submit("#signup_password")
110
111 def Logout(self):
112 self.GoTo("https://www.tumblr.com/logout")
113
114
115 class Wikipedia(WebsiteTest):
116
117 def Login(self):
118 self.GoTo("https://en.wikipedia.org/w/index.php?title=Special:UserLogin")
119 self.FillUsernameInto("#wpName1")
120 self.FillPasswordInto("#wpPassword1")
121 self.Submit("#wpPassword1")
122
123 def Logout(self):
124 self.GoTo("https://en.wikipedia.org/w/index.php?title=Special:UserLogout")
125
126
127 class Yandex(WebsiteTest):
128
129 def Login(self):
130 self.GoTo("https://mail.yandex.com")
131 self.FillUsernameInto("#b-mail-domik-username11")
132 self.FillPasswordInto("#b-mail-domik-password11")
133 self.Click(".b-mail-button__button")
134
135 def Logout(self):
136 while not self.IsDisplayed(".b-mail-dropdown__item__content"
137 u".Выход.daria-action"):
138 self.ClickIfClickable(".header-user-pic.b-mail-dropdown__handle")
139 self.Wait(1)
140 self.Click(u".b-mail-dropdown__item__content.Выход.daria-action")
141
142
143 # Disabled tests.
144
145
146 # Bug not reproducible without test.
147 class Amazon(WebsiteTest):
148
149 def Login(self):
150 self.GoTo(
151 "https://www.amazon.com/ap/signin?openid.assoc_handle=usflex"
152 "&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net"
153 "%2Fauth%2F2.0")
154 self.FillUsernameInto("[name='email']")
155 self.FillPasswordInto("[name='password']")
156 self.Submit("[name='password']")
157
158 def Logout(self):
159 while not self.IsDisplayed("#nav-item-signout"):
160 self.Wait(1)
161 self.HoverOver("#nav-signin-title")
162 self.Click("#nav-item-signout")
163
164
165 # Password not saved.
166 class Ask(WebsiteTest):
167
168 def Login(self):
169 self.GoTo("http://www.ask.com/answers/browse?qsrc=321&q=&o=0&l=dir#")
170 while not self.IsDisplayed("[name='username']"):
171 self.Click("#a16CnbSignInText")
172 self.Wait(1)
173 self.FillUsernameInto("[name='username']")
174 self.FillPasswordInto("[name='password']")
175 self.Click(".signin_show.signin_submit")
176
177 def Logout(self):
178 self.WaitUntilDisplayed("#a16CnbSignInText")
179 self.Click("#a16CnbSignInText")
180
181
182 # Password not saved.
183 class Baidu(WebsiteTest):
184
185 def Login(self):
186 self.GoTo("http://www.baidu.com/")
187 self.Click("[name='tj_login']")
188 self.WaitUntilDisplayed("[name='userName']")
189 self.FillUsernameInto("[name='userName']")
190 self.FillPasswordInto("[name='password']")
191 self.Submit("[name='password']")
192
193 def Logout(self):
194 self.Wait(1)
195 self.GoTo("https://passport.baidu.com/?logout&u=http://www.baidu.com")
196
197
198 # http://crbug.com/368690
199 class Cnn(WebsiteTest):
200
201 def Login(self):
202 self.GoTo("http://www.cnn.com")
203 self.Wait(5)
204 while not self.IsDisplayed(".cnnOvrlyBtn.cnnBtnLogIn"):
205 self.ClickIfClickable("#hdr-auth .no-border.no-pad-right a")
206 self.Wait(1)
207
208 self.Click(".cnnOvrlyBtn.cnnBtnLogIn")
209 self.FillUsernameInto("#cnnOverlayEmail1l")
210 self.FillPasswordInto("#cnnOverlayPwd")
211 self.Click(".cnnOvrlyBtn.cnnBtnLogIn")
212 self.Click(".cnnOvrlyBtn.cnnBtnLogIn")
213 self.Wait(5)
214
215 def Logout(self):
216 self.Wait(4)
217 self.Click("#hdr-auth .no-border.no-pad-right")
218
219
220 # http://crbug.com/368690
221 class Ebay(WebsiteTest):
222
223 def Login(self):
224 self.GoTo("https://signin.ebay.com/")
225 self.FillUsernameInto("[name='userid']")
226 self.FillPasswordInto("[name='pass']")
227 self.Submit("[name='pass']")
228
229 def Logout(self):
230 self.WaitUntilDisplayed("#gh-ug")
231 self.Click("#gh-ug")
232 self.WaitUntilDisplayed("#gh-uo")
233 self.Click("#gh-uo")
234
235
236 # Iframe, password saved but not autofileld.
237 class Espn(WebsiteTest):
238
239 def Login(self):
240 self.GoTo("http://espn.go.com/")
241 while not self.IsDisplayed("#cboxLoadedContent iframe"):
242 self.Click("#signin .cbOverlay")
243 self.Wait(1)
244 frame = self.driver.find_element_by_css_selector("#cboxLoadedContent "
245 "iframe")
246 self.driver.switch_to_frame(frame)
247 self.WaitUntilDisplayed("#username")
248 self.FillUsernameInto("#username")
249 self.FillPasswordInto("#password")
250 while self.IsDisplayed("#password"):
251 self.ClickIfClickable("#submitBtn")
252 self.Wait(1)
253
254 def Logout(self):
255 self.WaitUntilDisplayed("#signin .small")
256 self.Click("#signin .small")
257
258
259 # http://crbug.com/367768
260 class Live(WebsiteTest):
261
262 def Login(self):
263 self.GoTo("https://www.live.com")
264 self.FillUsernameInto("[name='login']")
265 self.FillPasswordInto("[name='passwd']")
266 self.Submit("[name='passwd']")
267
268 def Logout(self):
269 self.WaitUntilDisplayed("#c_meun")
270 self.Click("#c_meun")
271 self.WaitUntilDisplayed("#c_signout")
272 self.Click("#c_signout")
273
274
275 # http://crbug.com/368690
276 class One63(WebsiteTest):
277
278 def Login(self):
279 self.GoTo("http://www.163.com")
280 self.HoverOver("#js_N_navHighlight")
281 self.WaitUntilDisplayed("#js_loginframe_username")
282 self.FillUsernameInto("#js_loginframe_username")
283 self.FillPasswordInto(".ntes-loginframe-label-ipt[type='password']")
284 self.Click(".ntes-loginframe-btn")
285
286 def Logout(self):
287 self.WaitUntilDisplayed("#js_N_navLogout")
288 self.Click("#js_N_navLogout")
289
290
291 # http://crbug.com/368690
292 class Vube(WebsiteTest):
293
294 def Login(self):
295 self.GoTo("https://vube.com")
296 self.Click("[vube-login='']")
297 self.WaitUntilDisplayed("[ng-model='login.user']")
298 self.FillUsernameInto("[ng-model='login.user']")
299 self.FillPasswordInto("[ng-model='login.pass']")
300 while (self.IsDisplayed("[ng-model='login.pass']")
301 and not self.IsDisplayed(".prompt.alert")):
302 self.ClickIfClickable("[ng-click='login()']")
303 self.Wait(1)
304
305 def Logout(self):
306 self.WaitUntilDisplayed("[ng-click='user.logout()']")
307 self.Click("[ng-click='user.logout()']")
308
309
310 # Tests that can cause a crash.
311
312
313 class Yahoo(WebsiteTest):
314
315 def Login(self):
316 self.GoTo("https://login.yahoo.com")
317 self.FillUsernameInto("#username")
318 self.FillPasswordInto("#passwd")
319 self.Submit("#passwd")
320
321 def Logout(self):
322 self.WaitUntilDisplayed(".tab.tab-user>.mod.view_default")
323 self.HoverOver(".tab.tab-user>.mod.view_default")
324 self.WaitUntilDisplayed("[data-pos='4'] .lbl.y-link-1")
325 self.Click("[data-pos='4'] .lbl.y-link-1")
326
327
328 def Tests(environment):
329
330
331 # Working tests.
332
333
334 environment.AddWebsiteTest(Facebook("facebook"))
335
336 environment.AddWebsiteTest(Google("google"))
337
338 environment.AddWebsiteTest(Linkedin("linkedin"))
339
340 environment.AddWebsiteTest(Mailru("mailru"))
341
342 environment.AddWebsiteTest(Nytimes("nytimes"))
343
344 environment.AddWebsiteTest(Pinterest("pinterest"))
345
346 environment.AddWebsiteTest(Reddit("reddit", username_not_auto=True))
347
348 environment.AddWebsiteTest(Tumblr("tumblr", username_not_auto=True))
349
350 environment.AddWebsiteTest(Wikipedia("wikipedia", username_not_auto=True))
351
352 environment.AddWebsiteTest(Yandex("yandex"))
353
354
355 # Disabled tests.
356
357
358 # Bug not reproducible without test.
359 environment.AddWebsiteTest(Amazon("amazon"), disabled=True)
360
361 # Password not saved.
362 environment.AddWebsiteTest(Ask("ask"), disabled=True)
363
364 # Password not saved.
365 environment.AddWebsiteTest(Baidu("baidu"), disabled=True)
366
367 # http://crbug.com/368690
368 environment.AddWebsiteTest(Cnn("cnn"), disabled=True)
369
370 # http://crbug.com/368690
371 environment.AddWebsiteTest(Ebay("ebay"), disabled=True)
372
373 # Iframe, password saved but not autofileld.
374 environment.AddWebsiteTest(Espn("espn"), disabled=True)
375
376 # http://crbug.com/367768
377 environment.AddWebsiteTest(Live("live", username_not_auto=True),
378 disabled=True)
379
380 # http://crbug.com/368690
381 environment.AddWebsiteTest(One63("163"), disabled=True)
382
383 # http://crbug.com/368690
384 environment.AddWebsiteTest(Vube("vube"), disabled=True)
385
386 # Tests that can cause a crash (the cause of the crash is not related to the
387 # password manager).
388 environment.AddWebsiteTest(Yahoo("yahoo", username_not_auto=True),
389 disabled=True)
390
391
392 def RunTests(chrome_path, chromedriver_path, profile_path,
393 environment_passwords_path, enable_automatic_password_saving,
394 environment_numeric_level, log_to_console, environment_log_file,
395 all_tests, tests):
396
397 """Runs the the tests
398
399 Args:
400 chrome_path: The chrome binary file.
401 chromedriver_path: The chromedriver binary file.
402 profile_path: The chrome testing profile folder.
403 environment_passwords_path: The usernames and passwords file.
404 enable_automatic_password_saving: If True, the passwords are going to be
405 saved without showing the prompt.
406 environment_numeric_level: The log verbosity.
407 log_to_console: If True, the debug logs will be shown on the console.
408 environment_log_file: The file where to store the log. If it's empty, the
409 log is not stored.
410 all_tests: If True, all the tests are going to be ran.
411 tests: A list of the names of the WebsiteTests that are going to be tested.
412
413 Raises:
414 Exception: An exception is raised if the one of the tests fails.
415 """
416
417 environment = Environment(chrome_path, chromedriver_path, profile_path,
418 environment_passwords_path,
419 enable_automatic_password_saving,
420 environment_numeric_level,
421 log_to_console,
422 environment_log_file)
423
424 # Test which care about the save-password prompt need the prompt
425 # to be shown. Automatic password saving results in no prompt.
426 run_prompt_tests = not enable_automatic_password_saving
427
428 Tests(environment)
429
430 if all_tests:
431 environment.AllTests(run_prompt_tests)
432 elif tests:
433 environment.Test(tests, run_prompt_tests)
434 else:
435 environment.WorkingTests(run_prompt_tests)
436
437 environment.Quit()
438
439
440 # Tests setup.
441 if __name__ == "__main__":
442 parser = argparse.ArgumentParser(
443 description="Password Manager automated tests help.")
444
445 parser.add_argument(
446 "--chrome-path", action="store", dest="chrome_path",
447 help="Set the chrome path (required).", nargs=1, required=True)
448 parser.add_argument(
449 "--chromedriver-path", action="store", dest="chromedriver_path",
450 help="Set the chromedriver path (required).", nargs=1, required=True)
451 parser.add_argument(
452 "--profile-path", action="store", dest="profile_path",
453 help="Set the profile path (required). You just need to choose a "
454 "temporary empty folder. If the folder is not empty all its content "
455 "is going to be removed.",
456 nargs=1, required=True)
457
458 parser.add_argument(
459 "--passwords-path", action="store", dest="passwords_path",
460 help="Set the usernames/passwords path (required).", nargs=1,
461 required=True)
462 parser.add_argument("--all", action="store_true", dest="all",
463 help="Run all tests.")
464 parser.add_argument("--log", action="store", nargs=1, dest="log_level",
465 help="Set log level.")
466
467 parser.add_argument("--log-screen", action="store_true", dest="log_screen",
468 help="Show log on the screen.")
469 parser.add_argument("--log-file", action="store", dest="log_file",
470 help="Write the log in a file.", nargs=1)
471 parser.add_argument("tests", help="Tests to be run.", nargs="*")
472
473 args = parser.parse_args()
474
475 passwords_path = None
vabr (Chromium) 2014/05/22 15:46:24 nit: Now that passwords_path is required, you can
rchtara 2014/05/22 16:22:26 Done.
476 if args.passwords_path:
477 passwords_path = args.passwords_path[0]
478
479 numeric_level = None
480 if args.log_level:
481 numeric_level = getattr(logging, args.log_level[0].upper(), None)
482 if not isinstance(numeric_level, int):
483 raise ValueError("Invalid log level: %s" % args.log_level[0])
484
485 log_file = None
486 if args.log_file:
487 log_file = args.log_file[0]
488
489 # Run the test without enable-automatic-password-saving to check whether or
490 # not the prompt is shown in the way we expected.
491 RunTests(args.chrome_path[0],
492 args.chromedriver_path[0],
493 args.profile_path[0],
494 passwords_path,
495 False,
496 numeric_level,
497 args.log_screen,
498 log_file,
499 args.all,
500 args.tests)
501
502 # Run the test with enable-automatic-password-saving to check whether or not
503 # the passwords is stored in the the way we expected.
504 RunTests(args.chrome_path[0],
505 args.chromedriver_path[0],
506 args.profile_path[0],
507 passwords_path,
508 True,
509 numeric_level,
510 args.log_screen,
511 log_file,
512 args.all,
513 args.tests)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698