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