OLD | NEW |
---|---|
(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.ClickIfVisible(".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 # crbug.com/368690 | |
vabr (Chromium)
2014/05/20 14:47:25
nit: If you prefix the URL with "http://", the lin
rchtara
2014/05/22 08:44:38
Done.
| |
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.ClickIfVisible("#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 # 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.ClickIfVisible("#submitBtn") | |
252 self.Wait(1) | |
253 | |
254 def Logout(self): | |
255 self.WaitUntilDisplayed("#signin .small") | |
256 self.Click("#signin .small") | |
257 | |
258 | |
259 # 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 # 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 # 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.ClickIfVisible("[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 (the cause of the crash is not related to the | |
311 # password manager). | |
312 | |
313 | |
314 class Yahoo(WebsiteTest): | |
315 | |
316 def Login(self): | |
317 self.GoTo("https://login.yahoo.com") | |
318 self.FillUsernameInto("#username") | |
319 self.FillPasswordInto("#passwd") | |
320 self.Submit("#passwd") | |
321 | |
322 def Logout(self): | |
323 self.WaitUntilDisplayed(".tab.tab-user>.mod.view_default") | |
324 self.HoverOver(".tab.tab-user>.mod.view_default") | |
325 self.WaitUntilDisplayed("[data-pos='4'] .lbl.y-link-1") | |
326 self.Click("[data-pos='4'] .lbl.y-link-1") | |
327 | |
328 | |
329 def Tests(environment): | |
330 | |
331 | |
332 # Working tests. | |
333 | |
334 | |
335 environment.AddWebsiteTest(Facebook("facebook")) | |
336 | |
337 environment.AddWebsiteTest(Google("google")) | |
338 | |
339 environment.AddWebsiteTest(Linkedin("linkedin")) | |
340 | |
341 environment.AddWebsiteTest(Mailru("mailru")) | |
342 | |
343 environment.AddWebsiteTest(Nytimes("nytimes")) | |
344 | |
345 environment.AddWebsiteTest(Pinterest("pinterest")) | |
346 | |
347 environment.AddWebsiteTest(Reddit("reddit", username_not_auto=True)) | |
348 | |
349 environment.AddWebsiteTest(Tumblr("tumblr", username_not_auto=True)) | |
350 | |
351 environment.AddWebsiteTest(Wikipedia("wikipedia", username_not_auto=True)) | |
352 | |
353 environment.AddWebsiteTest(Yandex("yandex")) | |
354 | |
355 | |
356 # Disabled tests. | |
357 | |
358 | |
359 # Bug not reproducible without test. | |
360 environment.AddWebsiteTest(Amazon("amazon"), disabled=True) | |
361 | |
362 # Password not saved. | |
363 environment.AddWebsiteTest(Ask("ask"), disabled=True) | |
364 | |
365 # Password not saved. | |
366 environment.AddWebsiteTest(Baidu("baidu"), disabled=True) | |
367 | |
368 # crbug.com/368690 | |
369 environment.AddWebsiteTest(Cnn("cnn"), disabled=True) | |
370 | |
371 # crbug.com/368690 | |
372 environment.AddWebsiteTest(Ebay("ebay"), disabled=True) | |
373 | |
374 # Iframe, password saved but not autofileld. | |
375 environment.AddWebsiteTest(Espn("espn"), disabled=True) | |
376 | |
377 # crbug.com/367768 | |
378 environment.AddWebsiteTest(Live("live", username_not_auto=True), | |
379 disabled=True) | |
380 | |
381 # crbug.com/368690 | |
382 environment.AddWebsiteTest(One63("163"), disabled=True) | |
383 | |
384 # crbug.com/368690 | |
385 environment.AddWebsiteTest(Vube("vube"), disabled=True) | |
386 | |
387 # Tests that can cause a crash (the cause of the crash is not related to the | |
388 # password manager). | |
389 environment.AddWebsiteTest(Yahoo("yahoo", username_not_auto=True), | |
390 disabled=True) | |
391 | |
392 | |
393 def RunTests(chrome_path, chromedriver_path, profile_path, | |
vabr (Chromium)
2014/05/20 14:47:25
Please add a documentation string for this functio
rchtara
2014/05/22 08:44:38
Done.
| |
394 environment_passwords_path, enable_automatic_password_saving, | |
395 environment_numeric_level, log_screen, environment_log_file, | |
396 all_tests, tests): | |
397 | |
398 environment = Environment(chrome_path, chromedriver_path, profile_path, | |
399 environment_passwords_path, | |
400 enable_automatic_password_saving, | |
401 environment_numeric_level, | |
402 log_screen, | |
403 environment_log_file) | |
404 | |
405 | |
406 Tests(environment) | |
407 | |
408 if all_tests: | |
409 environment.AllTests(not enable_automatic_password_saving) | |
410 elif len(tests) == 0: | |
vabr (Chromium)
2014/05/20 14:47:25
"len(tests) == 0" -> "not tests"
(search for "len(
rchtara
2014/05/22 08:44:38
Done.
| |
411 environment.WorkingTests(not enable_automatic_password_saving) | |
412 else: | |
413 environment.Test(tests, not enable_automatic_password_saving) | |
414 | |
415 environment.Quit() | |
416 | |
417 | |
418 # Tests setup. | |
419 if __name__ == "__main__": | |
420 parser = argparse.ArgumentParser( | |
421 description="Password Manager automated tests help.") | |
422 | |
423 parser.add_argument( | |
424 "--chrome-path", action="store", dest="chrome_path", | |
425 help="Set the chrome path (required).", nargs=1, required=True) | |
426 parser.add_argument( | |
427 "--chromedriver-path", action="store", dest="chromedriver_path", | |
428 help="Set the chromedriver path (required).", nargs=1, required=True) | |
429 parser.add_argument( | |
430 "--profile-path", action="store", dest="profile_path", | |
431 help="""Set the profile path (required). You just need to choose a | |
vabr (Chromium)
2014/05/20 14:47:25
I suggest using single quotes (plus \ at the end o
rchtara
2014/05/22 08:44:38
Done.
| |
432 temporary empty folder. If the folder is not empty all its content is | |
433 going to be removed.""", nargs=1, required=True) | |
434 | |
435 parser.add_argument( | |
436 "--passwords-path", action="store", dest="passwords_path", | |
437 help="Set the usernames/passwords path (optional).", nargs=1) | |
438 parser.add_argument("--all", action="store_true", dest="all", | |
439 help="Run all tests.") | |
440 parser.add_argument("--log", action="store", nargs=1, dest="log_level", | |
441 help="Set log level.") | |
442 | |
443 parser.add_argument("--log-screen", action="store_true", dest="log_screen", | |
444 help="Show log on the screen.") | |
445 parser.add_argument("--log-file", action="store", dest="log_file", | |
446 help="Write the log in a file.", nargs=1) | |
447 parser.add_argument("tests", help="Tests to be run.", nargs="*") | |
448 | |
449 args = parser.parse_args() | |
450 | |
451 passwords_path = None | |
452 if args.passwords_path: | |
453 passwords_path = args.passwords_path[0] | |
454 | |
455 numeric_level = None | |
456 if args.log_level: | |
457 numeric_level = getattr(logging, args.log_level[0].upper(), None) | |
458 if not isinstance(numeric_level, int): | |
459 raise ValueError("Invalid log level: %s" % args.log_level[0]) | |
460 | |
461 log_file = None | |
462 if args.log_file: | |
463 log_file = args.log_file[0] | |
464 | |
465 # Run the test without enable-automatic-password-saving to check whether or | |
466 # not the prompt is shown in the way we expected. | |
467 RunTests(args.chrome_path[0], | |
468 args.chromedriver_path[0], | |
469 args.profile_path[0], | |
470 passwords_path, | |
471 False, | |
472 numeric_level, | |
473 args.log_screen, | |
474 log_file, | |
475 args.all, | |
476 args.tests) | |
477 | |
478 # Run the test with enable-automatic-password-saving to check whether or not | |
479 # the passwords is shown in the the way we expected. | |
vabr (Chromium)
2014/05/20 14:47:25
nit: Did you mean "stored" instead of "shown"?
rchtara
2014/05/22 08:44:38
Done.
| |
480 RunTests(args.chrome_path[0], | |
481 args.chromedriver_path[0], | |
482 args.profile_path[0], | |
483 passwords_path, | |
484 True, | |
485 numeric_level, | |
486 args.log_screen, | |
487 log_file, | |
488 args.all, | |
489 args.tests) | |
OLD | NEW |