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" |
| 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: |
| 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 |
| 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 p = self.password |
| 108 self.password = self.password + "1" |
| 109 self.LoginWhenNotAutofilled() |
| 110 self.password = p |
| 111 self.internals_file = "wrongpass.html" |
| 112 self.SwitchToInternals() |
| 113 url = self.Url() |
| 114 self.UrlExists("unsuccessfullogins", ("Error: password manager " |
| 115 "thinks that a login with wrong " |
| 116 "password was successful for the " |
| 117 "following website : %s \n" % url)) |
| 118 self.UrlNotExists( |
| 119 "showedprompts", |
| 120 "Error: prompt is shown for a " |
| 121 "wrong password for the following website : %s \n" % url) |
| 122 self.SwitchFromInternals() |
| 123 |
| 124 def SucessfulLoginTest(self): |
| 125 self.LoginWhenNotAutofilled() |
| 126 time.sleep(2) |
| 127 self.internals_file = "rightpass.html" |
| 128 self.SwitchToInternals() |
| 129 url = self.Url() |
| 130 self.UrlExists( |
| 131 "successfullogins", |
| 132 "Error: password manager " |
| 133 "hasn't detected a successful login for the following website : %s" |
| 134 " \n" |
| 135 % url) |
| 136 self.UrlExists( |
| 137 "showedprompts", |
| 138 "Error: prompt is not shown for a " |
| 139 "right password for the following website : %s \n" % url) |
| 140 self.SwitchFromInternals() |
| 141 self.Logout() |
| 142 |
| 143 def SucessfulLoginWithAutofilledPasswordTest(self): |
| 144 self.LoginWhenAutofilled() |
| 145 time.sleep(2) |
| 146 self.internals_file = "rightpass.html" |
| 147 self.SwitchToInternals() |
| 148 url = self.Url() |
| 149 self.UrlExists( |
| 150 "successfullogins", |
| 151 "Error: password manager " |
| 152 "hasn't detected a successful login for the following website : %s" |
| 153 " \n" |
| 154 % url) |
| 155 self.UrlExists( |
| 156 "showedprompts", |
| 157 "Error: prompt is not shown for a " |
| 158 "right password for the following website : %s \n" % url) |
| 159 self.SwitchFromInternals() |
| 160 self.Logout() |
| 161 |
| 162 def SucessfulLoginAfterDeletionTest(self): |
| 163 self.LoginWhenNotAutofilled() |
| 164 self.internals_file = "rightpass.html" |
| 165 self.SwitchToInternals() |
| 166 url = self.Url() |
| 167 self.UrlExists( |
| 168 "successfullogins", |
| 169 "Error: password manager " |
| 170 "hasn't detected a successful login for the following website : %s" |
| 171 " \n" |
| 172 % url) |
| 173 self.UrlExists( |
| 174 "showedprompts", |
| 175 "Error: prompt is not shown for a " |
| 176 "right password for the following website : %s \n" % url) |
| 177 self.SwitchFromInternals() |
| 178 self.Logout() |
OLD | NEW |