Permalink
Browse files

Added flows for signing up a new user, verifying a new email address,…

… and signing in as a returning user.
  • Loading branch information...
1 parent d841394 commit 24cf367d87eae06be6aa8db7781fa701cdf8a895 @davehunt committed May 28, 2012
View
@@ -9,15 +9,28 @@
class BrowserID(object):
- def __init__(self, selenium, timeout=60):
- self.selenium = selenium
+ VERIFY_URL_REGEX = 'https?:\/\/(\S+)\/verify_email_address\?token=(\S+)'
+
+ def __init__(self, sel, timeout=60):
+ self.selenium = sel
+ setattr(self.selenium, 'rc', isinstance(self.selenium,
+ selenium.selenium))
self.timeout = timeout
- def sign_in(self, email, password):
+ def sign_in(self, email=None, password=None):
"""Signs in using the specified email address and password."""
- if isinstance(self.selenium, selenium.selenium):
+ if self.selenium.rc:
from pages.rc.sign_in import SignIn
else:
from pages.webdriver.sign_in import SignIn
- sign_in = SignIn(self.selenium, timeout=self.timeout)
- sign_in.sign_in(email, password)
+ if email and password:
+ sign_in = SignIn(self.selenium, timeout=self.timeout, expect='new')
+ sign_in.sign_in(email, password)
+ elif email:
+ sign_in = SignIn(self.selenium, timeout=self.timeout, expect='new')
+ sign_in.sign_in_new_user(email)
+ else:
+ sign_in = SignIn(self.selenium,
+ timeout=self.timeout,
+ expect='returning')
+ sign_in.sign_in_returning_user()
View
@@ -14,13 +14,13 @@ class Base(object):
def __init__(self, selenium, timeout=60000):
self.selenium = selenium
self.timeout = timeout
- if selenium.get_title != self._page_title:
- self.wait_for_popup()
- selenium.select_pop_up(self._page_title)
- def wait_for_popup(self):
+ def switch_to_main_window(self):
+ self.selenium.select_window('null')
+
+ def wait_for_popup(self, page_title):
count = 0
- while not self._page_title in self.selenium.get_all_window_titles():
+ while not page_title in self.selenium.get_all_window_titles():
time.sleep(1)
count += 1
if count == self.timeout / 1000:
View
@@ -13,10 +13,26 @@ class SignIn(Base):
_password_locator = 'id=password'
_next_locator = 'css=button.start'
_sign_in_locator = 'css=button.returning'
+ _sign_in_returning_user_locator = 'id=signInButton'
+ _verify_email_locator = 'css=button.newuser'
+ _use_another_email_address_locator = 'id=back'
- def __init__(self, *args, **kwargs):
- Base.__init__(self, *args, **kwargs)
- self.wait_for_element_visible(self._email_locator)
+ def __init__(self, selenium, timeout, expect='new'):
+ Base.__init__(self, selenium, timeout)
+
+ if self.selenium.get_title != self._page_title:
+ self.wait_for_popup(self._page_title)
+ self.selenium.select_pop_up(self._page_title)
+
+ if expect == 'new':
+ self.wait_for_element_visible(self._email_locator)
+ elif expect == 'returning':
+ self.wait_for_element_visible(self._sign_in_returning_user_locator)
+ else:
+ raise Exception('Unknown expect value: %s' % expect)
+
+ def close_window(self):
+ self.selenium.close()
@property
def email(self):
@@ -38,19 +54,46 @@ def password(self, value):
"""Set the value of the password field."""
self.selenium.type(self._password_locator, value)
- def click_next(self):
+ def click_next(self, expect='password'):
"""Clicks the 'next' button."""
self.selenium.click(self._next_locator)
- self.wait_for_element_visible(self._password_locator)
+ if expect == 'password':
+ self.wait_for_element_visible(self._password_locator)
+ elif expect == 'verify':
+ self.wait_for_element_visible(self._verify_email_locator)
+ else:
+ raise Exception('Unknown expect value: %s' % expect)
def click_sign_in(self):
"""Clicks the 'Sign In' button."""
self.selenium.click(self._sign_in_locator)
self.selenium.deselect_pop_up()
+ def click_sign_in_returning_user(self):
+ """Clicks the 'sign in' button."""
+ self.selenium.click(self._sign_in_returning_user_locator)
+ self.selenium.deselect_pop_up()
+
+ def click_verify_email(self):
+ """Clicks 'verify email' button."""
+ self.selenium.click(self._verify_email_locator)
+ self.wait_for_element_visible(self._use_another_email_address_locator)
+
def sign_in(self, email, password):
"""Signs in using the specified email address and password."""
self.email = email
- self.click_next()
+ self.click_next(expect='password')
self.password = password
self.click_sign_in()
+
+ def sign_in_new_user(self, email):
+ """Requests verification email using the specified email address."""
+ self.email = email
+ self.click_next(expect='verify')
+ self.click_verify_email()
+ self.close_window()
+ self.switch_to_main_window()
+
+ def sign_in_returning_user(self):
+ """Signs in with the stored user."""
+ self.click_sign_in_returning_user()
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from base import Base
+
+from selenium.webdriver.common.by import By
+from selenium.webdriver.support.ui import WebDriverWait
+
+
+class VerifyEmailAddress(Base):
+
+ _email_locator = 'id=email'
+ _password_locator = 'id=password'
+ _verify_password_locator = 'id=vpassword'
+ _finish_locator = 'css=div.submit > button'
+ _thank_you_locator = 'id=congrats'
+
+ def __init__(self, *args, **kwargs):
+ Base.__init__(self, *args, **kwargs)
+ self.wait_for_element_visible(self._email_locator)
+
+ @property
+ def email(self):
+ """Get the value of the email field."""
+ return self.selenium.get_text(self._email_locator)
+
+ @property
+ def password(self):
+ """Get the value of the password field."""
+ return self.selenium.get_text(self._password_locator)
+
+ @password.setter
+ def password(self, value):
+ """Set the value of the password field."""
+ self.selenium.type(self._password_locator, value)
+
+ @property
+ def verify_password(self):
+ """Get the value of the password field."""
+ return self.selenium.get_text(self._verify_password_locator)
+
+ @password.setter
+ def verify_password(self, value):
+ """Set the value of the password field."""
+ self.selenium.type(self._verify_password_locator, value)
+
+ def click_finish(self):
+ """Clicks the 'finish' button."""
+ self.selenium.click(self._finish_locator)
+ self.wait_for_element_visible(self._thank_you_locator)
+
+ def verify_email_address(self, password):
+ self.password = password
+ self.verify_password = password
+ self.click_finish()
View
@@ -12,8 +12,7 @@ class Base(object):
def __init__(self, selenium, timeout=60):
self.selenium = selenium
self.timeout = timeout
- if selenium.title != self._page_title:
- for handle in selenium.window_handles:
- selenium.switch_to_window(handle)
- if selenium.title == self._page_title:
- break
+ self._main_window_handle = self.selenium.current_window_handle
+
+ def switch_to_main_window(self):
+ self.selenium.switch_to_window(self._main_window_handle)
View
@@ -16,11 +16,31 @@ class SignIn(Base):
_password_locator = (By.ID, 'password')
_next_locator = (By.CSS_SELECTOR, 'button.start')
_sign_in_locator = (By.CSS_SELECTOR, 'button.returning')
+ _sign_in_returning_user_locator = (By.ID, 'signInButton')
+ _verify_email_locator = (By.CSS_SELECTOR, 'button.newuser')
+ _use_another_email_address_locator = (By.ID, 'back')
- def __init__(self, *args, **kwargs):
- Base.__init__(self, *args, **kwargs)
- WebDriverWait(self.selenium, self.timeout).until(
- lambda s: s.find_element(*self._email_locator).is_displayed())
+ def __init__(self, selenium, timeout, expect='new'):
+ Base.__init__(self, selenium, timeout)
+
+ if self.selenium.title != self._page_title:
+ for handle in self.selenium.window_handles:
+ self.selenium.switch_to_window(handle)
+ if self.selenium.title == self._page_title:
+ break
+
+ if expect == 'new':
+ WebDriverWait(self.selenium, self.timeout).until(
+ lambda s: s.find_element(*self._email_locator).is_displayed())
+ elif expect == 'returning':
+ WebDriverWait(self.selenium, self.timeout).until(
+ lambda s: s.find_element(
+ *self._sign_in_returning_user_locator).is_displayed())
+ else:
+ raise Exception('Unknown expect value: %s' % expect)
+
+ def close_window(self):
+ self.selenium.close()
@property
def email(self):
@@ -46,20 +66,53 @@ def password(self, value):
password.clear()
password.send_keys(value)
- def click_next(self):
+ def click_next(self, expect='password'):
"""Clicks the 'next' button."""
self.selenium.find_element(*self._next_locator).click()
- WebDriverWait(self.selenium, self.timeout).until(
- lambda s: s.find_element(*self._password_locator).is_displayed())
+ if expect == 'password':
+ WebDriverWait(self.selenium, self.timeout).until(
+ lambda s: s.find_element(
+ *self._password_locator).is_displayed())
+ elif expect == 'verify':
+ WebDriverWait(self.selenium, self.timeout).until(
+ lambda s: s.find_element(
+ *self._verify_email_locator).is_displayed())
+ else:
+ raise Exception('Unknown expect value: %s' % expect)
def click_sign_in(self):
- """Clicks the 'Sign In' button."""
+ """Clicks the 'sign in' button."""
self.selenium.find_element(*self._sign_in_locator).click()
- self.selenium.switch_to_window('')
+ self.switch_to_main_window()
+
+ def click_sign_in_returning_user(self):
+ """Clicks the 'sign in' button."""
+ self.selenium.find_element(
+ *self._sign_in_returning_user_locator).click()
+ self.switch_to_main_window()
+
+ def click_verify_email(self):
+ """Clicks 'verify email' button."""
+ self.selenium.find_element(*self._verify_email_locator).click()
+ WebDriverWait(self.selenium, self.timeout).until(
+ lambda s: s.find_element(
+ *self._use_another_email_address_locator).is_displayed())
def sign_in(self, email, password):
"""Signs in using the specified email address and password."""
self.email = email
- self.click_next()
+ self.click_next(expect='password')
self.password = password
self.click_sign_in()
+
+ def sign_in_new_user(self, email):
+ """Requests verification email using the specified email address."""
+ self.email = email
+ self.click_next(expect='verify')
+ self.click_verify_email()
+ self.close_window()
+ self.switch_to_main_window()
+
+ def sign_in_returning_user(self):
+ """Signs in with the stored user."""
+ self.click_sign_in_returning_user()
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from base import Base
+
+from selenium.webdriver.common.by import By
+from selenium.webdriver.support.ui import WebDriverWait
+
+
+class VerifyEmailAddress(Base):
+
+ _email_locator = (By.ID, 'email')
+ _password_locator = (By.ID, 'password')
+ _verify_password_locator = (By.ID, 'vpassword')
+ _finish_locator = (By.CSS_SELECTOR, 'div.submit > button')
+ _thank_you_locator = (By.ID, 'congrats')
+
+ def __init__(self, *args, **kwargs):
+ Base.__init__(self, *args, **kwargs)
+ WebDriverWait(self.selenium, self.timeout).until(
+ lambda s: s.find_element(*self._email_locator).is_displayed())
+
+ @property
+ def email(self):
+ """Get the value of the email field."""
+ return self.selenium.find_element(*self._email_locator).text
+
+ @property
+ def password(self):
+ """Get the value of the password field."""
+ return self.selenium.find_element(*self._password_locator).text
+
+ @password.setter
+ def password(self, value):
+ """Set the value of the password field."""
+ password = self.selenium.find_element(*self._password_locator)
+ password.clear()
+ password.send_keys(value)
+
+ @property
+ def verify_password(self):
+ """Get the value of the password field."""
+ return self.selenium.find_element(*self._verify_password_locator).text
+
+ @password.setter
+ def verify_password(self, value):
+ """Set the value of the password field."""
+ password = self.selenium.find_element(*self._verify_password_locator)
+ password.clear()
+ password.send_keys(value)
+
+ def click_finish(self):
+ """Clicks the 'finish' button."""
+ self.selenium.find_element(*self._finish_locator).click()
+ WebDriverWait(self.selenium, self.timeout).until(
+ lambda s: s.find_element(*self._thank_you_locator).is_displayed())
+
+ def verify_email_address(self, password):
+ self.password = password
+ self.verify_password = password
+ self.click_finish()
View
@@ -1 +1,2 @@
pytest-mozwebqa==0.10
+requests==0.12.1
Oops, something went wrong.

0 comments on commit 24cf367

Please sign in to comment.