From 75446f721503e088eddd9f4271b818dff74f5dc1 Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Fri, 24 Aug 2012 12:17:10 -0600
Subject: [PATCH] (automated tests) when completing email verification
 triggered via 123done, wait for the redirect rather than trying to test the
 contents of the landing page.

---
 .../123done/tests/test_change_password.py     |  3 +-
 .../123done/tests/test_new_user.py            |  7 +----
 .../browserid/pages/complete_registration.py  | 29 +++++++++++++++----
 3 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/automation-tests/123done/tests/test_change_password.py b/automation-tests/123done/tests/test_change_password.py
index 621e694b5..9c346dbff 100644
--- a/automation-tests/123done/tests/test_change_password.py
+++ b/automation-tests/123done/tests/test_change_password.py
@@ -27,9 +27,8 @@ class TestChangePassword:
         email = inbox.find_by_index(0)
 
         # Load the BrowserID link from the email in the browser
-        mozwebqa.selenium.get(email.verify_user_link)
         from browserid.pages.complete_registration import CompleteRegistration
-        CompleteRegistration(mozwebqa.selenium, mozwebqa.timeout)
+        CompleteRegistration(mozwebqa.selenium, email.verify_user_link)
 
         mozwebqa.selenium.get(mozwebqa.server_base_url)
         from browserid.pages.account_manager import AccountManager
diff --git a/automation-tests/123done/tests/test_new_user.py b/automation-tests/123done/tests/test_new_user.py
index ed04e9c7e..832305c51 100644
--- a/automation-tests/123done/tests/test_new_user.py
+++ b/automation-tests/123done/tests/test_new_user.py
@@ -27,13 +27,8 @@ class TestNewAccount:
         email = inbox.find_by_index(0)
 
         # Load the BrowserID link from the email in the browser
-        mozwebqa.selenium.get(email.verify_user_link)
         from browserid.pages.complete_registration import CompleteRegistration
-        complete_registration = CompleteRegistration(mozwebqa.selenium, mozwebqa.timeout)
-
-        # Check the message on the registration page reflects a successful registration!
-        Assert.contains("Thank you for signing up with Persona.", complete_registration.thank_you)
+        complete_registration = CompleteRegistration(mozwebqa.selenium, email.verify_user_link)
 
         home_pg.go_to_home_page()
-
         Assert.equal(home_pg.logged_in_user_email, user['email'])
diff --git a/automation-tests/browserid/pages/complete_registration.py b/automation-tests/browserid/pages/complete_registration.py
index 141c1ea1f..a08bec829 100644
--- a/automation-tests/browserid/pages/complete_registration.py
+++ b/automation-tests/browserid/pages/complete_registration.py
@@ -12,20 +12,39 @@ from selenium.webdriver.support.ui import WebDriverWait
 
 class CompleteRegistration(Base):
 
+    _page_title = 'Mozilla Persona: Complete Registration'
     _email_locator = (By.ID, 'email')
     _password_locator = (By.ID, 'password')
     _finish_locator = (By.CSS_SELECTOR, 'div.submit > button')
     _thank_you_locator = (By.ID, 'congrats')
 
-    def __init__(self, selenium, timeout, expect='success'):
-        Base.__init__(self, selenium, timeout)
+    def __init__(self, mozwebqa, url, expect='redirect'):
+        """
+        class init method
+        :Args:
+        - url - the confirmation url from the email
+        - expect - redirect/success/reset/verify (default redirect)
+        """
+        Base.__init__(self, mozwebqa)
+        print "the url" + url
+        self.selenium.get(url)
 
-        if expect == 'success':
+        if expect == 'redirect':
             WebDriverWait(self.selenium, self.timeout).until(
-                lambda s: s.find_element(*self._thank_you_locator).is_displayed())
+                lambda s: s.title != self._page_title,
+                "Complete Registration page did not redirect")
+        elif expect == 'success':
+            WebDriverWait(self.selenium, self.timeout).until(
+                lambda s: 'Thank you' in s.find_element(*self._thank_you_locator).text,
+                "Complete Registration did not succeed")
+        elif expect == 'reset':
+            WebDriverWait(self.selenium, self.timeout).until(
+                lambda s: 'verified' in s.find_element(*self._thank_you_locator).text,
+                "Complete Registration did not succeed")
         elif expect == 'verify':
             WebDriverWait(self.selenium, self.timeout).until(
-                lambda s: s.find_element(*self._password_locator).is_displayed())
+                lambda s: s.find_element(*self._password_locator).is_displayed(),
+                "password field did not become visible")
         else:
             raise Exception('Unknown expect value: %s' % expect)
 
-- 
GitLab