Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 import time | |
| 2 | |
| 3 | |
| 4 from action import Action | |
| 5 | |
| 6 | |
| 7 class Website: | |
| 8 | |
| 9 def __init__( | |
| 10 self, name, username, password, driver, test_environment, | |
| 11 username_not_auto=False): | |
| 12 self.name = name | |
| 13 self.driver = driver | |
| 14 self.username = username | |
| 15 self.password = password | |
| 16 if test_environment.passwords_tree != None: | |
| 17 if username == None: | |
| 18 username_tag = (test_environment. | |
| 19 passwords_tree.find(".//*[@name='%s']/username" % name)) | |
| 20 if (username_tag != None): | |
| 21 self.username = username_tag.text | |
| 22 if password == None: | |
| 23 password_tag = (test_environment. | |
| 24 passwords_tree.find(".//*[@name='%s']/password" % name)) | |
| 25 if (password_tag != None): | |
| 26 self.password = password_tag.text | |
| 27 self.login_actions = [] | |
| 28 self.logout_actions = [] | |
| 29 self.internals_folder = ("file:///usr/local/google/home/rchtara/chrome" | |
|
vabr (Chromium)
2014/05/08 13:53:45
Please add a TODO for removing this as soon as the
rchtara
2014/05/14 11:58:04
Done.
| |
| 30 "/python/passwordinternals/internalmock/") | |
| 31 self.internals_file = "" | |
| 32 self.username_not_auto = username_not_auto | |
| 33 self.test_environment = test_environment | |
| 34 | |
| 35 def AddLoginAction(self, action_type, param): | |
| 36 self.login_actions.append(Action(action_type, param, self)) | |
| 37 | |
| 38 def AddLogoutAction(self, action_type, param): | |
| 39 self.logout_actions.append(Action(action_type, param, self)) | |
| 40 | |
| 41 def Url(self): | |
| 42 for action in self.login_actions: | |
| 43 if (action.action_type == "goto"): | |
| 44 return action.param | |
| 45 return "" | |
| 46 | |
| 47 def LoginWhenAutofilled(self): | |
| 48 for action in self.login_actions: | |
| 49 action.DoAutofilled(self.driver) | |
| 50 | |
| 51 def LoginWhenNotAutofilled(self): | |
| 52 for action in self.login_actions: | |
| 53 action.DoNotAutofilled(self.driver) | |
| 54 | |
| 55 def Logout(self): | |
| 56 for action in self.logout_actions: | |
| 57 action.Do(self.driver) | |
| 58 | |
| 59 def RemoveAllPasswords(self, urls): | |
| 60 url_to_remove = self.Url() | |
| 61 if (url_to_remove != ""): | |
| 62 i = 0 | |
| 63 for current_url in urls: | |
| 64 if current_url in url_to_remove or url_to_remove in current_url: | |
|
vabr (Chromium)
2014/05/08 13:53:45
You use the
x in y or y in x
pattern quite often f
rchtara
2014/05/14 11:58:04
Done.
| |
| 65 self.driver.execute_script( | |
| 66 "document.querySelectorAll('#saved-passwords-list " | |
| 67 ".row-delete-button')[%d].click()" % i) | |
| 68 time.sleep(1) # wait until command is executed | |
|
vabr (Chromium)
2014/05/08 13:53:45
nit: please start the comment with a capital lette
rchtara
2014/05/14 11:58:04
Done.
| |
| 69 else: | |
| 70 i = i + 1 | |
| 71 | |
| 72 def SwitchToInternals(self): | |
| 73 self.driver.switch_to_window(self.test_environment.internals_window) | |
| 74 self.driver.get(self.internals_folder + self.internals_file) | |
| 75 | |
| 76 def SwitchFromInternals(self): | |
| 77 self.driver.switch_to_window(self.test_environment.websitewindow) | |
| 78 | |
| 79 """ TestsTools """ | |
| 80 | |
| 81 def UrlExists(self, id, msg): | |
| 82 url = self.Url() | |
| 83 elments = self.driver.find_element_by_id(id) | |
| 84 urls = elments.find_elements_by_class_name("url") | |
| 85 match = False | |
| 86 for u in urls: | |
| 87 if (u.text in url or url in u.text or | |
| 88 u.text in self.name or self.name in u.text): | |
| 89 match = True | |
| 90 break | |
| 91 assert match, msg | |
| 92 | |
| 93 def UrlNotExists(self, id, msg): | |
| 94 url = self.Url() | |
| 95 elments = self.driver.find_element_by_id(id) | |
| 96 urls = elments.find_elements_by_class_name("url") | |
| 97 match = False | |
| 98 for u in urls: | |
| 99 if u.text in url or url in u.text: | |
| 100 match = True | |
| 101 break | |
| 102 assert match == False, msg | |
| 103 | |
| 104 """ Tests """ | |
| 105 | |
| 106 def WrongLoginTest(self): | |
| 107 name = self.name | |
| 108 print "\nWrong Login Test for %s \n" % name | |
| 109 p = self.password | |
|
vabr (Chromium)
2014/05/08 13:53:45
Please use more descriptive variable names.
Here,
rchtara
2014/05/14 11:58:04
Done.
| |
| 110 self.password = self.password + "1" | |
| 111 self.LoginWhenNotAutofilled() | |
| 112 self.password = p | |
| 113 self.internals_file = "wrongpass.html" | |
| 114 self.SwitchToInternals() | |
| 115 self.UrlExists("unsuccessfullogins", ("Error: password manager " | |
| 116 "thinks that a login with wrong " | |
| 117 "password was successful for the " | |
| 118 "following website : %s \n" % name)) | |
| 119 self.UrlNotExists( | |
| 120 "showedprompts", | |
| 121 "Error: prompt is shown for a " | |
| 122 "wrong password for the following website : %s \n" % name) | |
| 123 self.SwitchFromInternals() | |
| 124 | |
| 125 def SuccessfulLoginTest(self): | |
| 126 name = self.name | |
| 127 print "\nSuccessful Login Test for %s \n" % name | |
| 128 self.LoginWhenNotAutofilled() | |
| 129 time.sleep(2) | |
| 130 self.internals_file = "rightpass.html" | |
| 131 self.SwitchToInternals() | |
| 132 self.UrlExists( | |
| 133 "successfullogins", | |
| 134 "Error: password manager " | |
| 135 "hasn't detected a successful login for the following website : %s" | |
| 136 " \n" | |
| 137 % name) | |
| 138 self.UrlExists( | |
| 139 "showedprompts", | |
| 140 "Error: prompt is not shown for a " | |
| 141 "right password for the following website : %s \n" % name) | |
| 142 self.SwitchFromInternals() | |
| 143 self.Logout() | |
| 144 | |
| 145 def SuccessfulLoginWithAutofilledPasswordTest(self): | |
| 146 name = self.name | |
| 147 print "\nSuccessful Login With Autofilled Password Test %s \n" % name | |
| 148 self.LoginWhenAutofilled() | |
| 149 time.sleep(2) | |
| 150 self.internals_file = "rightpass.html" | |
| 151 self.SwitchToInternals() | |
| 152 self.UrlExists( | |
| 153 "successfullogins", | |
| 154 "Error: password manager " | |
| 155 "hasn't detected a successful login for the following website : %s" | |
| 156 " \n" | |
| 157 % name) | |
| 158 self.UrlExists( | |
| 159 "showedprompts", | |
| 160 "Error: prompt is not shown for a " | |
| 161 "right password for the following website : %s \n" % name) | |
| 162 self.SwitchFromInternals() | |
| 163 self.Logout() | |
| 164 | |
| 165 def SuccessfulLoginAfterDeletionTest(self): | |
| 166 name = self.name | |
| 167 print "\nSuccessful Login After Deletion Test for %s \n" % name | |
| 168 self.LoginWhenNotAutofilled() | |
| 169 self.internals_file = "rightpass.html" | |
| 170 self.SwitchToInternals() | |
| 171 self.UrlExists( | |
| 172 "successfullogins", | |
| 173 "Error: password manager " | |
| 174 "hasn't detected a successful login for the following website : %s" | |
| 175 " \n" | |
| 176 % name) | |
| 177 self.UrlExists( | |
| 178 "showedprompts", | |
| 179 "Error: prompt is not shown for a " | |
| 180 "right password for the following website : %s \n" % name) | |
| 181 self.SwitchFromInternals() | |
| 182 self.Logout() | |
| OLD | NEW |