Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / components / test / data / password_manager / websitetest.py
index 9a72b44..751ce38 100644 (file)
@@ -83,6 +83,7 @@ class WebsiteTest:
       selector: The element CSS selector.
     """
     logging.info("action: Click %s" % selector)
+    self.WaitUntilDisplayed(selector)
     element = self.driver.find_element_by_css_selector(selector)
     element.click()
 
@@ -101,6 +102,7 @@ class WebsiteTest:
       False otherwise.
     """
     logging.info("action: ClickIfVisible %s" % selector)
+    self.WaitUntilDisplayed(selector)
     try:
       element = self.driver.find_element_by_css_selector(selector)
       element.click()
@@ -128,6 +130,7 @@ class WebsiteTest:
       selector: The element CSS selector.
     """
     logging.info("action: Hover %s" % selector)
+    self.WaitUntilDisplayed(selector)
     element = self.driver.find_element_by_css_selector(selector)
     hover = ActionChains(self.driver).move_to_element(element)
     hover.perform()
@@ -207,24 +210,13 @@ class WebsiteTest:
           different than the one we expected.
     """
     logging.info("action: FillPasswordInto %s" % selector)
-
+    self.WaitUntilDisplayed(selector)
     password_element = self.driver.find_element_by_css_selector(selector)
     # Chrome protects the password inputs and doesn't fill them until
     # the user interacts with the page. To be sure that such thing has
-    # happened we click on the password fields or one of its ancestors.
-    element = password_element
-    while True:
-      try:
-        element.click()
-        break
-      except Exception:
-        try:
-          element = element.parent
-        except AttributeError:
-          raise Exception("Error: unable to find a clickable element to "
-              "release the password protection for the following website: %s \n"
-              % (self.name))
-
+    # happened we perform |Keys.CONTROL| keypress.
+    action_chains = ActionChains(self.driver)
+    action_chains.key_down(Keys.CONTROL).key_up(Keys.CONTROL).perform()
     if self.mode == self.Mode.AUTOFILLED:
       autofilled_password = password_element.get_attribute("value")
       if autofilled_password != self.password:
@@ -256,6 +248,7 @@ class WebsiteTest:
           different that the one we expected.
     """
     logging.info("action: FillUsernameInto %s" % selector)
+    self.WaitUntilDisplayed(selector)
     username_element = self.driver.find_element_by_css_selector(selector)
 
     if (self.mode == self.Mode.AUTOFILLED and not self.username_not_auto):
@@ -274,6 +267,7 @@ class WebsiteTest:
       selector: The input CSS selector.
     """
     logging.info("action: Submit %s" % selector)
+    self.WaitUntilDisplayed(selector)
     element = self.driver.find_element_by_css_selector(selector)
     element.submit()
 
@@ -295,7 +289,6 @@ class WebsiteTest:
 
   def Logout(self):
     """Logout Method."""
-    self.environment.ClearAllCookies()
 
   # Tests
 
@@ -310,18 +303,20 @@ class WebsiteTest:
           not like we expected or if the password is saved.
     """
     logging.info("\nWrong Login Test for %s \n" % self.name)
-    correct_password = self.password
-    self.password = self.password + "1"
-    self.LoginWhenNotAutofilled()
-    self.password = correct_password
-    self.Wait(2)
-    self.environment.SwitchToInternals()
-    self.environment.CheckForNewMessage(
-        environment.MESSAGE_SAVE,
-        False,
-        "Error: password manager thinks that a login with wrong password was "
-        "successful for the following website : %s \n" % self.name)
-    self.environment.SwitchFromInternals()
+    try:
+      correct_password = self.password
+      self.password = self.password + "1"
+      self.LoginWhenNotAutofilled()
+      self.password = correct_password
+      self.Wait(2)
+      self.environment.SwitchToInternals()
+      self.environment.CheckForNewMessage(
+          environment.MESSAGE_SAVE,
+          False,
+          "Error: password manager thinks that a login with wrong password was "
+          "successful for the following website : %s \n" % self.name)
+    finally:
+      self.environment.SwitchFromInternals()
 
   def SuccessfulLoginTest(self):
     """Does the successful login when the password is not expected to be
@@ -336,17 +331,19 @@ class WebsiteTest:
           saved.
     """
     logging.info("\nSuccessful Login Test for %s \n" % self.name)
-    self.LoginWhenNotAutofilled()
-    self.Wait(2)
-    self.environment.SwitchToInternals()
-    self.environment.CheckForNewMessage(
-        environment.MESSAGE_SAVE,
-        True,
-        "Error: password manager hasn't detected a successful login for the "
-        "following website : %s \n"
-        % self.name)
-    self.environment.SwitchFromInternals()
-    self.Logout()
+    try:
+      self.LoginWhenNotAutofilled()
+      self.Wait(2)
+      self.environment.SwitchToInternals()
+      self.environment.CheckForNewMessage(
+          environment.MESSAGE_SAVE,
+          True,
+          "Error: password manager hasn't detected a successful login for the "
+          "following website : %s \n"
+          % self.name)
+    finally:
+      self.environment.SwitchFromInternals()
+      self.Logout()
 
   def SuccessfulLoginWithAutofilledPasswordTest(self):
     """Does the successful login when the password is expected to be autofilled
@@ -362,17 +359,19 @@ class WebsiteTest:
     """
     logging.info("\nSuccessful Login With Autofilled Password"
                         " Test %s \n" % self.name)
-    self.LoginWhenAutofilled()
-    self.Wait(2)
-    self.environment.SwitchToInternals()
-    self.environment.CheckForNewMessage(
-        environment.MESSAGE_SAVE,
-        True,
-        "Error: password manager hasn't detected a successful login for the "
-        "following website : %s \n"
-        % self.name)
-    self.environment.SwitchFromInternals()
-    self.Logout()
+    try:
+      self.LoginWhenAutofilled()
+      self.Wait(2)
+      self.environment.SwitchToInternals()
+      self.environment.CheckForNewMessage(
+          environment.MESSAGE_SAVE,
+          True,
+          "Error: password manager hasn't detected a successful login for the "
+          "following website : %s \n"
+          % self.name)
+    finally:
+      self.environment.SwitchFromInternals()
+      self.Logout()
 
   def PromptTest(self):
     """Does the prompt test: Tries to login with a wrong password and
@@ -387,25 +386,27 @@ class WebsiteTest:
           password or is shown for a wrong one.
     """
     logging.info("\nPrompt Test for %s \n" % self.name)
-    correct_password = self.password
-    self.password = self.password + "1"
-    self.LoginWhenNotAutofilled()
-    self.password = correct_password
-    self.Wait(2)
-    self.environment.SwitchToInternals()
-    self.environment.CheckForNewMessage(
-        environment.MESSAGE_ASK,
-        False,
-        "Error: password manager thinks that a login with wrong password was "
-        "successful for the following website : %s \n" % self.name)
-    self.environment.SwitchFromInternals()
-
-    self.LoginWhenNotAutofilled()
-    self.Wait(2)
-    self.environment.SwitchToInternals()
-    self.environment.CheckForNewMessage(
-        environment.MESSAGE_ASK,
-        True,
-        "Error: password manager thinks that a login with wrong password was "
-        "successful for the following website : %s \n" % self.name)
-    self.environment.SwitchFromInternals()
+    try:
+      correct_password = self.password
+      self.password = self.password + "1"
+      self.LoginWhenNotAutofilled()
+      self.password = correct_password
+      self.Wait(2)
+      self.environment.SwitchToInternals()
+      self.environment.CheckForNewMessage(
+          environment.MESSAGE_ASK,
+          False,
+          "Error: password manager thinks that a login with wrong password was "
+          "successful for the following website : %s \n" % self.name)
+      self.environment.SwitchFromInternals()
+
+      self.LoginWhenNotAutofilled()
+      self.Wait(2)
+      self.environment.SwitchToInternals()
+      self.environment.CheckForNewMessage(
+          environment.MESSAGE_ASK,
+          True,
+          "Error: password manager hasn't detected a successful login for the "
+          "following website : %s \n" % self.name)
+    finally:
+      self.environment.SwitchFromInternals()