Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Side by Side Diff: components/test/data/password_manager/websitetest.py

Issue 538403003: Automatically wait for elements to be displayed in the password manager python tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/test/data/password_manager/tests.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """WebsiteTest testing class.""" 5 """WebsiteTest testing class."""
6 6
7 import logging 7 import logging
8 import sys 8 import sys
9 import time 9 import time
10 10
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 # Mouse/Keyboard actions. 77 # Mouse/Keyboard actions.
78 78
79 def Click(self, selector): 79 def Click(self, selector):
80 """Clicks on an element. 80 """Clicks on an element.
81 81
82 Args: 82 Args:
83 selector: The element CSS selector. 83 selector: The element CSS selector.
84 """ 84 """
85 logging.info("action: Click %s" % selector) 85 logging.info("action: Click %s" % selector)
86 self.WaitUntilDisplayed(selector)
86 element = self.driver.find_element_by_css_selector(selector) 87 element = self.driver.find_element_by_css_selector(selector)
87 element.click() 88 element.click()
88 89
89 def ClickIfClickable(self, selector): 90 def ClickIfClickable(self, selector):
90 """Clicks on an element if it's clickable: If it doesn't exist in the DOM, 91 """Clicks on an element if it's clickable: If it doesn't exist in the DOM,
91 it's covered by another element or it's out viewing area, nothing is 92 it's covered by another element or it's out viewing area, nothing is
92 done and False is returned. Otherwise, even if the element is 100% 93 done and False is returned. Otherwise, even if the element is 100%
93 transparent, the element is going to receive a click and a True is 94 transparent, the element is going to receive a click and a True is
94 returned. 95 returned.
95 96
96 Args: 97 Args:
97 selector: The element CSS selector. 98 selector: The element CSS selector.
98 99
99 Returns: 100 Returns:
100 True if the click happens. 101 True if the click happens.
101 False otherwise. 102 False otherwise.
102 """ 103 """
103 logging.info("action: ClickIfVisible %s" % selector) 104 logging.info("action: ClickIfVisible %s" % selector)
105 self.WaitUntilDisplayed(selector)
104 try: 106 try:
105 element = self.driver.find_element_by_css_selector(selector) 107 element = self.driver.find_element_by_css_selector(selector)
106 element.click() 108 element.click()
107 return True 109 return True
108 except Exception: 110 except Exception:
109 return False 111 return False
110 112
111 def GoTo(self, url): 113 def GoTo(self, url):
112 """Navigates the main frame to the |url|. 114 """Navigates the main frame to the |url|.
113 115
114 Args: 116 Args:
115 url: The URL. 117 url: The URL.
116 """ 118 """
117 logging.info("action: GoTo %s" % self.name) 119 logging.info("action: GoTo %s" % self.name)
118 if self.environment.first_go_to: 120 if self.environment.first_go_to:
119 self.environment.OpenTabAndGoToInternals(url) 121 self.environment.OpenTabAndGoToInternals(url)
120 self.environment.first_go_to = False 122 self.environment.first_go_to = False
121 else: 123 else:
122 self.driver.get(url) 124 self.driver.get(url)
123 125
124 def HoverOver(self, selector): 126 def HoverOver(self, selector):
125 """Hovers over an element. 127 """Hovers over an element.
126 128
127 Args: 129 Args:
128 selector: The element CSS selector. 130 selector: The element CSS selector.
129 """ 131 """
130 logging.info("action: Hover %s" % selector) 132 logging.info("action: Hover %s" % selector)
133 self.WaitUntilDisplayed(selector)
131 element = self.driver.find_element_by_css_selector(selector) 134 element = self.driver.find_element_by_css_selector(selector)
132 hover = ActionChains(self.driver).move_to_element(element) 135 hover = ActionChains(self.driver).move_to_element(element)
133 hover.perform() 136 hover.perform()
134 137
135 def SendEnterTo(self, selector): 138 def SendEnterTo(self, selector):
136 """Sends an enter key to an element. 139 """Sends an enter key to an element.
137 140
138 Args: 141 Args:
139 selector: The element CSS selector. 142 selector: The element CSS selector.
140 """ 143 """
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 Then, fills the input with the Website password. 203 Then, fills the input with the Website password.
201 204
202 Args: 205 Args:
203 selector: The password input CSS selector. 206 selector: The password input CSS selector.
204 207
205 Raises: 208 Raises:
206 Exception: An exception is raised if the DOM value of the password is 209 Exception: An exception is raised if the DOM value of the password is
207 different than the one we expected. 210 different than the one we expected.
208 """ 211 """
209 logging.info("action: FillPasswordInto %s" % selector) 212 logging.info("action: FillPasswordInto %s" % selector)
210 213 self.WaitUntilDisplayed(selector)
211 password_element = self.driver.find_element_by_css_selector(selector) 214 password_element = self.driver.find_element_by_css_selector(selector)
212 # Chrome protects the password inputs and doesn't fill them until 215 # Chrome protects the password inputs and doesn't fill them until
213 # the user interacts with the page. To be sure that such thing has 216 # the user interacts with the page. To be sure that such thing has
214 # happened we perform |Keys.CONTROL| keypress. 217 # happened we perform |Keys.CONTROL| keypress.
215 action_chains = ActionChains(self.driver) 218 action_chains = ActionChains(self.driver)
216 action_chains.key_down(Keys.CONTROL).key_up(Keys.CONTROL).perform() 219 action_chains.key_down(Keys.CONTROL).key_up(Keys.CONTROL).perform()
217 if self.mode == self.Mode.AUTOFILLED: 220 if self.mode == self.Mode.AUTOFILLED:
218 autofilled_password = password_element.get_attribute("value") 221 autofilled_password = password_element.get_attribute("value")
219 if autofilled_password != self.password: 222 if autofilled_password != self.password:
220 raise Exception("Error: autofilled password is different from the one " 223 raise Exception("Error: autofilled password is different from the one "
(...skipping 17 matching lines...) Expand all
238 username. 241 username.
239 242
240 Args: 243 Args:
241 selector: The username input CSS selector. 244 selector: The username input CSS selector.
242 245
243 Raises: 246 Raises:
244 Exception: An exception is raised if the DOM value of the username is 247 Exception: An exception is raised if the DOM value of the username is
245 different that the one we expected. 248 different that the one we expected.
246 """ 249 """
247 logging.info("action: FillUsernameInto %s" % selector) 250 logging.info("action: FillUsernameInto %s" % selector)
251 self.WaitUntilDisplayed(selector)
248 username_element = self.driver.find_element_by_css_selector(selector) 252 username_element = self.driver.find_element_by_css_selector(selector)
249 253
250 if (self.mode == self.Mode.AUTOFILLED and not self.username_not_auto): 254 if (self.mode == self.Mode.AUTOFILLED and not self.username_not_auto):
251 if not (username_element.get_attribute("value") == self.username): 255 if not (username_element.get_attribute("value") == self.username):
252 raise Exception("Error: autofilled username is different form the one " 256 raise Exception("Error: autofilled username is different form the one "
253 "we just saved for the following website : %s \n" % 257 "we just saved for the following website : %s \n" %
254 self.name) 258 self.name)
255 else: 259 else:
256 username_element.clear() 260 username_element.clear()
257 username_element.send_keys(self.username) 261 username_element.send_keys(self.username)
258 262
259 def Submit(self, selector): 263 def Submit(self, selector):
260 """Finds an element using CSS Selector and calls its submit() handler. 264 """Finds an element using CSS Selector and calls its submit() handler.
261 265
262 Args: 266 Args:
263 selector: The input CSS selector. 267 selector: The input CSS selector.
264 """ 268 """
265 logging.info("action: Submit %s" % selector) 269 logging.info("action: Submit %s" % selector)
270 self.WaitUntilDisplayed(selector)
266 element = self.driver.find_element_by_css_selector(selector) 271 element = self.driver.find_element_by_css_selector(selector)
267 element.submit() 272 element.submit()
268 273
269 # Login/Logout Methods 274 # Login/Logout Methods
270 275
271 def Login(self): 276 def Login(self):
272 """Login Method. Has to be overloaded by the WebsiteTest test.""" 277 """Login Method. Has to be overloaded by the WebsiteTest test."""
273 raise NotImplementedError("Login is not implemented.") 278 raise NotImplementedError("Login is not implemented.")
274 279
275 def LoginWhenAutofilled(self): 280 def LoginWhenAutofilled(self):
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 396
392 self.LoginWhenNotAutofilled() 397 self.LoginWhenNotAutofilled()
393 self.Wait(2) 398 self.Wait(2)
394 self.environment.SwitchToInternals() 399 self.environment.SwitchToInternals()
395 self.environment.CheckForNewMessage( 400 self.environment.CheckForNewMessage(
396 environment.MESSAGE_ASK, 401 environment.MESSAGE_ASK,
397 True, 402 True,
398 "Error: password manager hasn't detected a successful login for the " 403 "Error: password manager hasn't detected a successful login for the "
399 "following website : %s \n" % self.name) 404 "following website : %s \n" % self.name)
400 self.environment.SwitchFromInternals() 405 self.environment.SwitchFromInternals()
OLDNEW
« no previous file with comments | « components/test/data/password_manager/tests.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698