Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # -*- coding: utf-8 -*- | |
| 2 """Automated tests for many websites""" | |
| 3 | |
| 4 | |
| 5 import sys | |
| 6 | |
| 7 from environment import Environment | |
| 8 from website import Website | |
| 9 | |
| 10 | |
| 11 # Working tests. | |
| 12 def WorkingTests(environment): | |
|
vabr (Chromium)
2014/05/16 09:36:00
Since you specify "disabled" in AddWebsite(), you
rchtara
2014/05/20 08:24:47
Done.
| |
| 13 | |
| 14 | |
| 15 class Amazon(Website): | |
|
vabr (Chromium)
2014/05/16 09:36:00
Please extract the class definitions out of the fu
rchtara
2014/05/20 08:24:47
Done.
| |
| 16 | |
| 17 def Login(self): | |
| 18 self.GoTo( | |
| 19 "https://www.amazon.com/ap/signin?openid.assoc_handle=usflex" | |
| 20 "&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net" | |
| 21 "%2Fauth%2F2.0") | |
| 22 self.FillUsernameInto("[name='email']") | |
| 23 self.FillPasswordInto("[name='password']") | |
| 24 self.Submit("[name='password']") | |
| 25 | |
| 26 def Logout(self): | |
| 27 while not self.IsDisplayed("#nav-item-signout"): | |
| 28 self.Wait(1) | |
| 29 self.HoverOver("#nav-signin-title") | |
| 30 self.Click("#nav-item-signout") | |
| 31 | |
| 32 environment.AddWebsite( | |
| 33 Amazon( | |
| 34 "amazon", | |
| 35 "https://www.amazon.com/ap/" | |
| 36 "signin?openid.assoc_handle=usflex&openid.mode=checkid_setup&openid." | |
| 37 "ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0"), | |
| 38 disabled=True) | |
| 39 | |
| 40 | |
| 41 class Espn(Website): | |
| 42 | |
| 43 def Login(self): | |
| 44 self.GoTo("http://espn.go.com/") | |
| 45 while not self.IsDisplayed("#cboxLoadedContent iframe"): | |
| 46 self.Click("#signin .cbOverlay") | |
| 47 self.Wait(1) | |
| 48 frame = self.driver.find_element_by_css_selector("#cboxLoadedContent " | |
| 49 "iframe") | |
| 50 self.driver.switch_to_frame(frame) | |
| 51 self.WaitUntilDisplayed("#username") | |
| 52 self.FillUsernameInto("#username") | |
| 53 self.FillPasswordInto("#password") | |
| 54 while self.IsDisplayed("#password"): | |
| 55 self.ClickIfVisible("#submitBtn") | |
| 56 self.Wait(1) | |
| 57 | |
| 58 def Logout(self): | |
| 59 self.WaitUntilDisplayed("#signin .small") | |
| 60 self.Click("#signin .small") | |
| 61 | |
| 62 environment.AddWebsite( | |
| 63 Espn( | |
|
vabr (Chromium)
2014/05/16 09:36:00
nit: This line-break seems unnecessary.
rchtara
2014/05/20 08:24:47
Done.
| |
| 64 "espn", | |
| 65 "https://r.espn.go.com/members/v3_1/login?language=en®istrationFor" | |
| 66 "mId=espn&affiliateName=espn&forwardUrl=&appRedirect=http%3A%2F%2F" | |
| 67 "espn.go.com%2F&parentLocation=http%3A%2F%2Fespn.go.com%2F")) | |
| 68 | |
| 69 | |
| 70 class Facebook(Website): | |
| 71 | |
| 72 def Login(self): | |
| 73 self.GoTo("https://www.facebook.com") | |
| 74 self.FillUsernameInto("[name='email']") | |
| 75 self.FillPasswordInto("[name='pass']") | |
| 76 self.Submit("[name='pass']") | |
| 77 | |
| 78 def Logout(self): | |
| 79 self.WaitUntilDisplayed("#userNavigationLabel") | |
| 80 self.Click("#userNavigationLabel") | |
| 81 self.WaitUntilDisplayed("#logout_form [type='submit']") | |
| 82 self.Click("#logout_form [type='submit']") | |
| 83 | |
| 84 environment.AddWebsite( | |
| 85 Facebook("facebook", "https://www.facebook.com")) | |
| 86 | |
|
vabr (Chromium)
2014/05/16 09:36:00
nit: Keep in mind the style guide requires 2 blank
rchtara
2014/05/20 08:24:47
Done.
| |
| 87 class Google(Website): | |
| 88 | |
| 89 def Login(self): | |
| 90 self.GoTo("https://accounts.google.com/ServiceLogin?sacu=1&continue=") | |
| 91 self.FillUsernameInto("#Email") | |
| 92 self.FillPasswordInto("#Passwd") | |
| 93 self.Submit("#Passwd") | |
| 94 | |
| 95 def Logout(self): | |
| 96 self.WaitUntilDisplayed(".gb_V.gbii") | |
| 97 self.Click(".gb_V.gbii") | |
| 98 self.WaitUntilDisplayed("#gb_71") | |
| 99 self.Click("#gb_71") | |
| 100 | |
| 101 environment.AddWebsite( | |
| 102 Google( | |
| 103 "google", | |
| 104 "https://accounts.google.com/ServiceLogin?sacu=1&continue=")) | |
| 105 | |
| 106 class Mailru(Website): | |
| 107 | |
| 108 def Login(self): | |
| 109 self.GoTo("https://mail.ru") | |
| 110 self.FillUsernameInto("#mailbox__login") | |
| 111 self.FillPasswordInto("#mailbox__password") | |
| 112 self.Submit("#mailbox__password") | |
| 113 | |
| 114 def Logout(self): | |
| 115 self.Click("#PH_logoutLink") | |
| 116 | |
| 117 environment.AddWebsite(Mailru("mailru", "https://mail.ru")) | |
| 118 | |
| 119 class Nytimes(Website): | |
| 120 | |
| 121 def Login(self): | |
| 122 self.GoTo("https://myaccount.nytimes.com/auth/login") | |
| 123 self.FillUsernameInto("#userid") | |
| 124 self.FillPasswordInto("#password") | |
| 125 self.Submit("#password") | |
| 126 | |
| 127 def Logout(self): | |
| 128 self.GoTo("https://myaccount.nytimes.com/gst/signout") | |
| 129 | |
| 130 environment.AddWebsite( | |
| 131 Nytimes("nytimes", "https://myaccount.nytimes.com/auth/login")) | |
| 132 | |
| 133 # website detected unsual activity | |
| 134 class Pinterest(Website): | |
| 135 | |
| 136 def Login(self): | |
| 137 self.GoTo("https://www.pinterest.com/login/") | |
| 138 self.FillUsernameInto("[name='username_or_email']") | |
| 139 self.FillPasswordInto("[name='password']") | |
| 140 self.Submit("[name='password']") | |
| 141 | |
| 142 def Logout(self): | |
| 143 self.GoTo("https://www.pinterest.com/logout/") | |
| 144 | |
| 145 environment.AddWebsite( | |
| 146 Pinterest("pinterest", "https://www.pinterest.com/login/")) | |
| 147 | |
| 148 class Reddit(Website): | |
| 149 | |
| 150 def Login(self): | |
| 151 self.GoTo("http://www.reddit.com") | |
| 152 self.Click(".user .login-required") | |
| 153 self.FillUsernameInto("#user_login") | |
| 154 self.FillPasswordInto("#passwd_login") | |
| 155 self.Wait(2) | |
| 156 self.Submit("#passwd_login") | |
| 157 | |
| 158 def Logout(self): | |
| 159 self.Click("form[action='http://www.reddit.com/logout'] a") | |
| 160 | |
| 161 environment.AddWebsite( | |
| 162 Reddit("reddit", "http://www.reddit.com", username_not_auto=True)) | |
| 163 | |
| 164 class Tumblr(Website): | |
| 165 | |
| 166 def Login(self): | |
| 167 self.GoTo("https://www.tumblr.com/login") | |
| 168 self.FillUsernameInto("#signup_email") | |
| 169 self.FillPasswordInto("#signup_password") | |
| 170 self.Submit("#signup_password") | |
| 171 | |
| 172 def Logout(self): | |
| 173 self.GoTo("https://www.tumblr.com/logout") | |
| 174 | |
| 175 environment.AddWebsite( | |
| 176 Tumblr("tumblr", "https://www.tumblr.com/login", | |
| 177 username_not_auto=True)) | |
| 178 | |
| 179 class Wikipedia(Website): | |
| 180 | |
| 181 def Login(self): | |
| 182 self.GoTo("https://en.wikipedia.org/w/index.php?title=Special:UserLogin") | |
| 183 self.FillUsernameInto("#wpName1") | |
| 184 self.FillPasswordInto("#wpPassword1") | |
| 185 self.Submit("#wpPassword1") | |
| 186 | |
| 187 def Logout(self): | |
| 188 self.GoTo("https://en.wikipedia.org/w/index.php?title=Special:UserLogout") | |
| 189 | |
| 190 environment.AddWebsite( | |
| 191 Wikipedia( | |
| 192 "wikipedia", | |
| 193 "https://en.wikipedia.org/w/index.php?title=Special:UserLogin", | |
| 194 username_not_auto=True)) | |
| 195 | |
| 196 class Yandex(Website): | |
| 197 | |
| 198 def Login(self): | |
| 199 self.GoTo("https://mail.yandex.com") | |
| 200 self.FillUsernameInto("#b-mail-domik-username11") | |
| 201 self.FillPasswordInto("#b-mail-domik-password11") | |
| 202 self.Click(".b-mail-button__button") | |
| 203 | |
| 204 def Logout(self): | |
| 205 while not self.IsDisplayed(".b-mail-dropdown__item__content" | |
| 206 u".Выход.daria-action"): | |
| 207 self.ClickIfVisible(".header-user-pic.b-mail-dropdown__handle") | |
| 208 self.Wait(1) | |
| 209 self.Click(u".b-mail-dropdown__item__content.Выход.daria-action") | |
| 210 | |
| 211 environment.AddWebsite(Yandex("yandex", "https://mail.yandex.com")) | |
| 212 | |
| 213 | |
| 214 # Disabled tests. | |
| 215 def DisabledTests(environment): | |
| 216 | |
| 217 | |
| 218 class Ask(Website): | |
| 219 | |
| 220 def Login(self): | |
| 221 self.GoTo("http://www.ask.com/answers/browse?qsrc=321&q=&o=0&l=dir#") | |
| 222 while not self.IsDisplayed("[name='username']"): | |
| 223 self.Click("#a16CnbSignInText") | |
| 224 self.Wait(1) | |
| 225 self.FillUsernameInto("[name='username']") | |
| 226 self.FillPasswordInto("[name='password']") | |
| 227 self.Click(".signin_show.signin_submit") | |
| 228 | |
| 229 def Logout(self): | |
| 230 self.WaitUntilDisplayed("#a16CnbSignInText") | |
| 231 self.Click("#a16CnbSignInText") | |
| 232 | |
| 233 environment.AddWebsite(Ask("ask", "http://www.ask.com/answers/" | |
| 234 "browse?qsrc=321&q=&o=0&l=dir#")) | |
|
vabr (Chromium)
2014/05/16 09:36:00
nit: indenting is off
rchtara
2014/05/20 08:24:47
Done.
| |
| 235 # crbug.com/368690 | |
| 236 class Cnn(Website): | |
| 237 | |
| 238 def Login(self): | |
| 239 self.GoTo("http://www.cnn.com") | |
| 240 self.Wait(5) | |
| 241 while not self.IsDisplayed(".cnnOvrlyBtn.cnnBtnLogIn"): | |
| 242 self.ClickIfVisible("#hdr-auth .no-border.no-pad-right a") | |
| 243 self.Wait(1) | |
| 244 | |
| 245 self.Click(".cnnOvrlyBtn.cnnBtnLogIn") | |
| 246 self.FillUsernameInto("#cnnOverlayEmail1l") | |
| 247 self.FillPasswordInto("#cnnOverlayPwd") | |
| 248 self.Click(".cnnOvrlyBtn.cnnBtnLogIn") | |
| 249 self.Click(".cnnOvrlyBtn.cnnBtnLogIn") | |
| 250 self.Wait(5) | |
| 251 | |
| 252 def Logout(self): | |
| 253 self.Wait(4) | |
| 254 self.Click("#hdr-auth .no-border.no-pad-right") | |
| 255 | |
| 256 environment.AddWebsite(Cnn("cnn", "http://www.cnn.com"), disabled=True) | |
| 257 | |
| 258 # crbug.com/368690 | |
| 259 class Ebay(Website): | |
| 260 | |
| 261 def Login(self): | |
| 262 self.GoTo("https://signin.ebay.com/") | |
| 263 self.FillUsernameInto("[name='userid']") | |
| 264 self.FillPasswordInto("[name='pass']") | |
| 265 self.Submit("[name='pass']") | |
| 266 | |
| 267 def Logout(self): | |
| 268 self.WaitUntilDisplayed("#gh-ug") | |
| 269 self.Click("#gh-ug") | |
| 270 self.WaitUntilDisplayed("#gh-uo") | |
| 271 self.Click("#gh-uo") | |
| 272 | |
| 273 environment.AddWebsite( | |
| 274 Ebay("ebay", "https://signin.ebay.com/"), disabled=True) | |
| 275 | |
| 276 # crbug.com/367768 | |
| 277 class Live(Website): | |
| 278 | |
| 279 def Login(self): | |
| 280 self.GoTo("https://www.live.com") | |
| 281 self.FillUsernameInto("[name='login']") | |
| 282 self.FillPasswordInto("[name='passwd']") | |
| 283 self.Submit("[name='passwd']") | |
| 284 | |
| 285 def Logout(self): | |
| 286 self.WaitUntilDisplayed("#c_meun") | |
| 287 self.Click("#c_meun") | |
| 288 self.WaitUntilDisplayed("#c_signout") | |
| 289 self.Click("#c_signout") | |
| 290 | |
| 291 environment.AddWebsite( | |
| 292 Live("live", "https://www.live.com", username_not_auto=True), | |
| 293 disabled=True) | |
| 294 | |
| 295 # crbug.com/368690 | |
| 296 class One63(Website): | |
| 297 | |
| 298 def Login(self): | |
| 299 self.GoTo("http://www.163.com") | |
| 300 self.HoverOver("#js_N_navHighlight") | |
| 301 self.WaitUntilDisplayed("#js_loginframe_username") | |
| 302 self.FillUsernameInto("#js_loginframe_username") | |
| 303 self.FillPasswordInto(".ntes-loginframe-label-ipt[type='password']") | |
| 304 self.Click(".ntes-loginframe-btn") | |
| 305 | |
| 306 def Logout(self): | |
| 307 self.WaitUntilDisplayed("#js_N_navLogout") | |
| 308 self.Click("#js_N_navLogout") | |
| 309 | |
| 310 environment.AddWebsite( | |
| 311 One63("163", "http://www.163.com"), disabled=True) | |
| 312 | |
| 313 # crbug.com/368690 | |
| 314 class Vube(Website): | |
| 315 | |
| 316 def Login(self): | |
| 317 self.GoTo("https://vube.com") | |
| 318 self.Click("[vube-login='']") | |
| 319 self.WaitUntilDisplayed("[ng-model='login.user']") | |
| 320 self.FillUsernameInto("[ng-model='login.user']") | |
| 321 self.FillPasswordInto("[ng-model='login.pass']") | |
| 322 while (self.IsDisplayed("[ng-model='login.pass']") | |
| 323 and not self.IsDisplayed(".prompt.alert")): | |
| 324 self.ClickIfVisible("[ng-click='login()']") | |
| 325 self.Wait(1) | |
| 326 | |
| 327 def Logout(self): | |
| 328 self.WaitUntilDisplayed("[ng-click='user.logout()']") | |
| 329 self.Click("[ng-click='user.logout()']") | |
| 330 | |
| 331 environment.AddWebsite(Vube("vube", "https://vube.com"), disabled=True) | |
| 332 | |
| 333 | |
| 334 # Tests that can cause a crash (the cause of the crash is not related to the | |
|
vabr (Chromium)
2014/05/16 09:36:00
Are you really sure that the crash is not related
rchtara
2014/05/20 08:24:47
chrome crashes when click on sign out.
So it could
vabr (Chromium)
2014/05/20 14:47:25
So do you or do you not think it's related to the
rchtara
2014/05/22 08:44:38
Done.
| |
| 335 # password manager). | |
| 336 | |
| 337 | |
| 338 class Baidu(Website): | |
| 339 | |
| 340 def Login(self): | |
| 341 self.GoTo("http://www.baidu.com/") | |
| 342 self.Click("[name='tj_login']") | |
| 343 self.WaitUntilDisplayed("[name='userName']") | |
| 344 self.FillUsernameInto("[name='userName']") | |
| 345 self.FillPasswordInto("[name='password']") | |
| 346 self.Submit("[name='password']") | |
| 347 | |
| 348 def Logout(self): | |
| 349 self.Wait(1) | |
| 350 self.GoTo("https://passport.baidu.com/?logout&u=http://www.baidu.com") | |
| 351 | |
| 352 environment.AddWebsite( | |
| 353 Baidu("baidu", "http://www.baidu.com/"), disabled=True) | |
| 354 | |
| 355 class Linkedin(Website): | |
| 356 | |
| 357 def Login(self): | |
| 358 self.GoTo("https://www.linkedin.com") | |
| 359 self.FillUsernameInto("#session_key-login") | |
| 360 self.FillPasswordInto("#session_password-login") | |
| 361 self.Submit("#session_password-login") | |
| 362 | |
| 363 def Logout(self): | |
| 364 self.WaitUntilDisplayed(".account-toggle") | |
| 365 self.HoverOver(".account-toggle") | |
| 366 self.WaitUntilDisplayed(".account-settings .act-set-action") | |
| 367 self.Click(".account-settings .act-set-action") | |
| 368 | |
| 369 environment.AddWebsite( | |
| 370 Linkedin("linkedin", "https://www.linkedin.com"), disabled=True) | |
| 371 | |
| 372 class Yahoo(Website): | |
| 373 | |
| 374 def Login(self): | |
| 375 self.GoTo("https://login.yahoo.com") | |
| 376 self.FillUsernameInto("#username") | |
| 377 self.FillPasswordInto("#passwd") | |
| 378 self.Submit("#passwd") | |
| 379 | |
| 380 def Logout(self): | |
| 381 self.WaitUntilDisplayed(".tab.tab-user>.mod.view_default") | |
| 382 self.HoverOver(".tab.tab-user>.mod.view_default") | |
| 383 self.WaitUntilDisplayed("[data-pos='4'] .lbl.y-link-1") | |
| 384 self.Click("[data-pos='4'] .lbl.y-link-1") | |
| 385 | |
| 386 environment.AddWebsite( | |
| 387 Yahoo("yahoo", "https://login.yahoo.com", username_not_auto=True), | |
| 388 disabled=True) | |
| 389 | |
| 390 | |
| 391 # Tests setup. | |
| 392 if __name__ == "__main__": | |
| 393 | |
| 394 args = sys.argv[1:] | |
| 395 if "--help" in args: | |
|
vabr (Chromium)
2014/05/16 09:36:00
Please use argparse instead of handling the argume
vabr (Chromium)
2014/05/16 09:36:00
Also, in general, help should be printed if the ar
rchtara
2014/05/20 08:24:47
Done.
rchtara
2014/05/20 08:24:47
Done.
| |
| 396 print "Password Manager automated tests help." | |
|
vabr (Chromium)
2014/05/16 09:36:00
nit: Consider using multi-line strings """...""" i
rchtara
2014/05/20 08:24:47
Done.
| |
| 397 print "Usage: python tests.py --chrome-path path --chromedriver-path path" | |
| 398 print ("--profile-path path [--passwords-path path] [--all] [--help] " | |
| 399 "[--log]") | |
| 400 print ("[--log-file path] [test] ... .") | |
| 401 print "--chrome-path : Set the chrome path (required)." | |
| 402 print "--chromedriver-path : Set the chromedriver path (required)." | |
| 403 print "--profile-path : Set the test profile path (required)." | |
| 404 print ("You just need to choose a temporary empty folder. If the folder is " | |
| 405 "not empty ") | |
| 406 print "all its content is going to be removed." | |
| 407 print "--passwords-path : Set the usernames/passwords path (optinal)" | |
| 408 print "Default behavior : Run only working tests." | |
| 409 print "--all : Run all tests." | |
| 410 print "--log : Show log on the screen." | |
| 411 print "--log-file : Write the log in a file." | |
| 412 print "--help : Show help." | |
| 413 print "test ... : Tests to be run." | |
| 414 else: | |
| 415 chrome_path = "" | |
| 416 if "--chrome-path" not in args: | |
| 417 sys.exit("Error: You have to specify the chrome path via --chrome-path") | |
| 418 else: | |
| 419 index = args.index("--chrome-path") | |
| 420 chrome_path = args[index + 1] | |
| 421 del args[index + 1] | |
| 422 del args[index] | |
| 423 | |
| 424 chromedriver_path = "" | |
| 425 if "--chromedriver-path" not in args: | |
| 426 sys.exit("Error: You have to specify the chromedriver path via " | |
| 427 "--chromedriver-path") | |
| 428 else: | |
| 429 index = args.index("--chromedriver-path") | |
| 430 chromedriver_path = args[index + 1] | |
| 431 del args[index + 1] | |
| 432 del args[index] | |
| 433 | |
| 434 profile_path = "" | |
| 435 if "--profile-path" not in args: | |
| 436 sys.exit("Error: You have to specify the test profile path via " | |
| 437 "--profile-path") | |
| 438 else: | |
| 439 index = args.index("--profile-path") | |
| 440 profile_path = args[index + 1] | |
| 441 del args[index + 1] | |
| 442 del args[index] | |
| 443 | |
| 444 passwords_path = None | |
| 445 if "--passwords-path" in args: | |
| 446 index = args.index("--passwords-path") | |
| 447 passwords_path = args[index + 1] | |
| 448 del args[index + 1] | |
| 449 del args[index] | |
| 450 | |
| 451 log_to_screen = False | |
| 452 log_file = None | |
| 453 if "--log" in args: | |
| 454 index = args.index("--log") | |
| 455 del args[index] | |
| 456 log_to_screen = True | |
| 457 if "--log-file" in args: | |
| 458 index = args.index("--log-file") | |
| 459 log_file = args[index + 1] | |
| 460 del args[index + 1] | |
| 461 del args[index] | |
| 462 | |
| 463 | |
| 464 testing_environment = Environment(chrome_path, chromedriver_path, | |
| 465 profile_path, passwords_path, | |
| 466 log_to_screen, log_file) | |
| 467 WorkingTests(testing_environment) | |
| 468 DisabledTests(testing_environment) | |
| 469 | |
| 470 if len(args) == 0: | |
| 471 testing_environment.WorkingTests() | |
| 472 elif "--all" in args: | |
| 473 testing_environment.AllTests() | |
| 474 else: | |
| 475 testing_environment.Test(args) | |
| 476 | |
| 477 testing_environment.Quit() | |
| OLD | NEW |