Index: components/test/data/password_manager/action.py |
diff --git a/components/test/data/password_manager/action.py b/components/test/data/password_manager/action.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..991399f0b50737ba3a7530b7d976f9c6a95d5e7a |
--- /dev/null |
+++ b/components/test/data/password_manager/action.py |
@@ -0,0 +1,124 @@ |
+import time |
vabr (Chromium)
2014/05/08 13:53:45
Please add a module docstring (also in other Pytho
vabr (Chromium)
2014/05/08 13:53:45
Also please add the encoding, like you did in test
rchtara
2014/05/14 11:58:04
Done.
|
+from selenium.webdriver.common.action_chains import ActionChains |
+from selenium.webdriver.common.keys import Keys |
+from selenium.common.exceptions import ElementNotVisibleException |
+ |
+ |
+class Action: |
+ |
vabr (Chromium)
2014/05/08 13:53:45
Please add a docstring documenting this class.
Als
|
+ def __init__(self, action_type, param, website): |
+ self.action_type = action_type |
+ self.param = param |
+ self.website = website |
+ |
+ def Do(self, driver): |
+ """Do the default behavior of the action. |
+ """ |
vabr (Chromium)
2014/05/08 13:53:45
'For one liner docstrings, please keep the closing
rchtara
2014/05/14 11:58:04
Done.
|
+ print "actiontype: %s actionparam: %s" % (self.action_type, self.param) |
vabr (Chromium)
2014/05/08 13:53:45
If you need this temporarily as a debugging messag
rchtara
2014/05/14 11:58:04
I think it's important to put the log, because the
|
+ if self.action_type == "goto": |
+ driver.get(self.param) |
+ elif self.action_type == "wait": |
+ time.sleep(self.param) |
+ elif self.action_type == "click": |
+ element = driver.find_element_by_css_selector(self.param) |
+ element.click() |
+ elif self.action_type == "hover": |
+ element = driver.find_element_by_css_selector(self.param) |
+ hover = ActionChains(driver).move_to_element(element) |
+ hover.perform() |
+ elif self.action_type == "submit": |
+ element = driver.find_element_by_css_selector(self.param) |
+ element.submit() |
+ elif self.action_type == "enter": |
+ body = driver.find_element_by_tag_name("body") |
+ body.send_keys(Keys.ENTER) |
+ elif self.action_type == "optinalfillusername": |
vabr (Chromium)
2014/05/08 13:53:45
typo: optinal -> optional
rchtara
2014/05/14 11:58:04
Done.
|
+ username_element = driver.find_element_by_css_selector(self.param) |
+ print username_element |
+ try: |
+ username_element.clear() |
+ username_element.send_keys(self.website.username) |
+ except ElementNotVisibleException: |
+ pass |
+ elif self.action_type == "fillusername": |
+ username_element = driver.find_element_by_css_selector(self.param) |
+ username_element.clear() |
+ username_element.send_keys(self.website.username) |
+ elif self.action_type == "fillpassword": |
+ """Chrome protects the password inputs and doesn't fill them until |
vabr (Chromium)
2014/05/08 13:53:45
As already mentioned off-line: except for doc-stri
rchtara
2014/05/14 11:58:04
Done.
|
+ the user interacts with them. So when using chromedriver, we need |
+ to be careful about that: we need to send a key to password |
+ element, chrome is going to autofill it if he has already saved |
+ password for it, then we need to clear everything and send the |
+ password. |
+ """ |
+ password_element = driver.find_element_by_css_selector(self.param) |
+ password_element.send_keys("a") |
vabr (Chromium)
2014/05/08 13:53:45
Why do we actually care if Chrome fills the passwo
rchtara
2014/05/14 11:58:04
Chrome doesn't fill password input until the user
|
+ password_element.clear() |
+ password_element.send_keys(self.website.password) |
+ elif self.action_type == "wait": |
+ time.sleep(self.param) |
vabr (Chromium)
2014/05/08 13:53:45
You already have one if-branch for "wait". Please
rchtara
2014/05/14 11:58:04
Done.
|
+ |
+ def DoAutofilled(self, driver): |
+ """Make the action behavior when the username and password fields are |
vabr (Chromium)
2014/05/08 13:53:45
nit: Please use single-space consistently, no doub
vabr (Chromium)
2014/05/08 13:53:45
I cannot parse the sentence. Are you trying to say
rchtara
2014/05/14 11:58:04
Done.
rchtara
2014/05/14 11:58:04
Done.
|
+ expected to be autofilled: for fillusername amd fillpassword, check that |
+ the autofilled values are equal to the ones we expect. For other actions, |
+ do the default behavior. |
+ |
vabr (Chromium)
2014/05/08 13:53:45
nit: Please remove the blank line.
rchtara
2014/05/14 11:58:04
Done.
|
+ """ |
+ if (self.action_type == "fillusername" and |
+ not self.website.username_not_auto): |
+ print "actiontype: %s actionparam: %s" % (self.action_type, self.param) |
+ username_element = driver.find_element_by_css_selector(self.param) |
+ assert username_element.get_attribute("value") == self.website.username, ( |
vabr (Chromium)
2014/05/08 13:53:45
The Chromium style guide for Python (http://dev.ch
rchtara
2014/05/14 11:58:04
Done.
|
+ "Error: autofilled " |
+ "username is different form the one we just saved for the " |
+ "following website : %s \n" % self.website.Url()) |
+ elif self.action_type == "fillpassword": |
+ print "actiontype: %s actionparam: %s" % (self.action_type, self.param) |
+ """Chrome protects the password inputs and doesn't fill them until |
vabr (Chromium)
2014/05/08 13:53:45
Actually, some errors I saw in the past were when
rchtara
2014/05/14 11:58:04
I made the test and you right: the password is aut
|
+ the user interacts with them. So when using chromedriver, if we |
+ want to get the stored password, we need to be careful about that: |
+ we need to send a key to password element, chrome is going to |
+ autofill it if he has already saved password for it, then we need |
+ to get the value of the input and we remove the character we add |
+ it before. |
+ """ |
+ password_element = driver.find_element_by_css_selector(self.param) |
+ password_element.send_keys("a") |
+ ps = password_element.get_attribute("value")[:-1] |
+ password_element.clear() |
+ password_element.send_keys(ps) |
+ assert password_element.get_attribute("value") == self.website.password, ( |
+ "Error: autofilled password is different from the one we just saved " |
+ "for the following website : %s p1: %s p2:%s \n" % |
+ (self.website.Url(), password_element.get_attribute("value"), |
+ self.website.password)) |
+ else: |
+ self.Do(driver) |
+ |
+ def DoNotAutofilled(self, driver): |
+ """Do the action behavior when the password field is not expected to be |
vabr (Chromium)
2014/05/08 13:53:45
Please once you improve the docstring for the prev
rchtara
2014/05/14 11:58:04
Done.
rchtara
2014/05/14 11:58:04
Done.
|
+ autofilled: for fillpassword check that the password field is empty before |
+ filling it. For other actions, do the default behavior. |
+ """ |
+ if self.action_type == "fillpassword": |
+ """Chrome protects the password inputs and doesn't fill them until |
+ the user interacts with them. So when using chromedriver, if we |
+ want to get the stored password, we need to be careful about that: |
+ we need to send a key to password element, chrome is going to |
+ autofill it if he has already saved password for it, then we need |
+ to get the value of the input and we remove the character we add |
+ it before. |
+ """ |
+ password_element = driver.find_element_by_css_selector(self.param) |
+ password_element.send_keys("a") |
+ ps = password_element.get_attribute("value")[1:] |
+ password_element.clear() |
+ password_element.send_keys(ps) |
+ |
+ assert len(ps) == 0, ("Error: password is autofilled when it shouldn't " |
vabr (Chromium)
2014/05/08 13:53:45
len(ps) == 0
should be just
ps
(Look for "len(" in
rchtara
2014/05/14 11:58:04
Done.
|
+ " be for the following website : %s \n" |
+ % self.website.Url()) |
+ |
+ self.Do(driver) |