Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Updated for changes in 2012.05.25
Browse files Browse the repository at this point in the history
  • Loading branch information
davehunt committed May 30, 2012
1 parent c02a13a commit c4d1952
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 186 deletions.
15 changes: 3 additions & 12 deletions browser_id.py
Expand Up @@ -17,20 +17,11 @@ def __init__(self, sel, timeout=60):
selenium.selenium))
self.timeout = timeout

def sign_in(self, email=None, password=None):
def sign_in(self, email, password):
"""Signs in using the specified email address and password."""
if self.selenium.rc:
from pages.rc.sign_in import SignIn
else:
from pages.webdriver.sign_in import SignIn
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()
sign_in = SignIn(self.selenium, timeout=self.timeout, expect='new')
sign_in.sign_in(email, password)
Expand Up @@ -6,21 +6,23 @@

from base import Base

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait


class VerifyEmailAddress(Base):
class CompleteRegistration(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)
def __init__(self, selenium, timeout, expect='success'):
Base.__init__(self, selenium, timeout)

if expect == 'success':
self.wait_for_element_visible(self._thank_you_locator)
elif expect == 'verify':
self.wait_for_element_visible(self._password_locator)
else:
raise Exception('Unknown expect value: %s' % expect)

@property
def email(self):
Expand All @@ -37,22 +39,12 @@ 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()
@property
def thank_you(self):
"""Returns the 'thank you' message."""
return self.selenium.get_text(self._thank_you_locator)
17 changes: 15 additions & 2 deletions pages/rc/sign_in.py
Expand Up @@ -12,10 +12,11 @@ class SignIn(Base):
_signed_in_email_locator = 'css=label[for=email_0]'
_email_locator = 'id=email'
_password_locator = 'id=password'
_verify_password_locator = 'id=vpassword'
_next_locator = 'css=button.start'
_sign_in_locator = 'css=button.returning'
_sign_in_returning_user_locator = 'id=signInButton'
_verify_email_locator = 'css=button.newuser'
_verify_email_locator = 'id=verify_user'
_use_another_email_address_locator = 'id=back'

def __init__(self, selenium, timeout, expect='new'):
Expand Down Expand Up @@ -60,6 +61,16 @@ 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 verify password field."""
return self.selenium.get_text(self._verify_password_locator)

@password.setter
def verify_password(self, value):
"""Set the value of the verify password field."""
self.selenium.type(self._verify_password_locator, value)

def click_next(self, expect='password'):
"""Clicks the 'next' button."""
self.selenium.click(self._next_locator)
Expand Down Expand Up @@ -92,10 +103,12 @@ def sign_in(self, email, password):
self.password = password
self.click_sign_in()

def sign_in_new_user(self, email):
def sign_in_new_user(self, email, password):
"""Requests verification email using the specified email address."""
self.email = email
self.click_next(expect='verify')
self.password = password
self.verify_password = password
self.click_verify_email()
self.close_window()
self.switch_to_main_window()
Expand Down
Expand Up @@ -10,18 +10,24 @@
from selenium.webdriver.support.ui import WebDriverWait


class VerifyEmailAddress(Base):
class CompleteRegistration(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())
def __init__(self, selenium, timeout, expect='success'):
Base.__init__(self, selenium, timeout)

if expect == 'success':
WebDriverWait(self.selenium, self.timeout).until(
lambda s: s.find_element(*self._thank_you_locator).is_displayed())
elif expect == 'verify':
WebDriverWait(self.selenium, self.timeout).until(
lambda s: s.find_element(*self._password_locator).is_displayed())
else:
raise Exception('Unknown expect value: %s' % expect)

@property
def email(self):
Expand All @@ -40,25 +46,13 @@ def password(self, value):
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()
@property
def thank_you(self):
"""Returns the 'thank you' message."""
return self.selenium.find_element(*self._thank_you_locator).text
19 changes: 17 additions & 2 deletions pages/webdriver/sign_in.py
Expand Up @@ -15,10 +15,11 @@ class SignIn(Base):
_signed_in_email_locator = (By.CSS_SELECTOR, 'label[for=email_0]')
_email_locator = (By.ID, 'email')
_password_locator = (By.ID, 'password')
_verify_password_locator = (By.ID, 'vpassword')
_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')
_verify_email_locator = (By.ID, 'verify_user')
_use_another_email_address_locator = (By.ID, 'back')

def __init__(self, selenium, timeout, expect='new'):
Expand Down Expand Up @@ -72,6 +73,18 @@ def password(self, value):
password.clear()
password.send_keys(value)

@property
def verify_password(self):
"""Get the value of the verify password field."""
return self.selenium.find_element(*self._verify_password_locator).text

@password.setter
def verify_password(self, value):
"""Set the value of the verify password field."""
password = self.selenium.find_element(*self._verify_password_locator)
password.clear()
password.send_keys(value)

def click_next(self, expect='password'):
"""Clicks the 'next' button."""
self.selenium.find_element(*self._next_locator).click()
Expand Down Expand Up @@ -111,10 +124,12 @@ def sign_in(self, email, password):
self.password = password
self.click_sign_in()

def sign_in_new_user(self, email):
def sign_in_new_user(self, email, password):
"""Requests verification email using the specified email address."""
self.email = email
self.click_next(expect='verify')
self.password = password
self.verify_password = password
self.click_verify_email()
self.close_window()
self.switch_to_main_window()
Expand Down
39 changes: 26 additions & 13 deletions tests/rc/check_sign_in.py
Expand Up @@ -18,7 +18,7 @@
class TestSignIn:

def test_sign_in_helper(self, mozwebqa):
browser_id = BrowserID(mozwebqa.selenium)
browser_id = BrowserID(mozwebqa.selenium, mozwebqa.timeout)
browser_id.sign_in(mozwebqa.email, mozwebqa.password)

logout_locator = 'css=#loggedin a'
Expand All @@ -39,20 +39,27 @@ def test_sign_in(self, mozwebqa):

def test_sign_in_new_user_helper(self, mozwebqa):
restmail_username = 'bidpom_%s' % uuid.uuid1()
browser_id = BrowserID(mozwebqa.selenium, mozwebqa.timeout)
print 'signing in as %s@restmail.net' % restmail_username
browser_id.sign_in('%s@restmail.net' % restmail_username)
email = '%s@restmail.net' % restmail_username

from ...pages.rc.sign_in import SignIn
signin = SignIn(mozwebqa.selenium, mozwebqa.timeout, expect='new')
print 'signing in as %s' % email
signin.sign_in_new_user(email, 'password')
mail = restmail.get_mail(restmail_username)
assert 'Thanks for verifying' in mail[0]['text']

def test_sign_in_new_user(self, mozwebqa):
restmail_username = 'bidpom_%s' % uuid.uuid1()
email = '%s@restmail.net' % restmail_username
password = 'password'

from ...pages.rc.sign_in import SignIn
signin = SignIn(mozwebqa.selenium, mozwebqa.timeout, expect='new')
print 'signing in as %s@restmail.net' % restmail_username
signin.email = '%s@restmail.net' % restmail_username
print 'signing in as %s' % email
signin.email = email
signin.click_next(expect='verify')
signin.password = password
signin.verify_password = password
signin.click_verify_email()
signin.close_window()
signin.switch_to_main_window()
Expand All @@ -66,8 +73,9 @@ def test_sign_in_returning_user_helper(self, mozwebqa):
mozwebqa.wait_for_element_visible(mozwebqa, login_locator)
mozwebqa.selenium.click(login_locator)

browser_id = BrowserID(mozwebqa.selenium, mozwebqa.timeout)
browser_id.sign_in()
from ...pages.rc.sign_in import SignIn
signin = SignIn(mozwebqa.selenium, mozwebqa.timeout, expect='returning')
signin.sign_in_returning_user()
logout_locator = 'css=#loggedin a'
mozwebqa.wait_for_element_visible(mozwebqa, logout_locator)
assert mozwebqa.selenium.is_visible(logout_locator)
Expand All @@ -94,13 +102,18 @@ def create_verified_user(self, selenium, timeout):
restmail_username = 'bidpom_%s' % uuid.uuid1()
email = '%s@restmail.net' % restmail_username
password = 'password'
browser_id = BrowserID(selenium, timeout)
browser_id.sign_in(email)

from ...pages.rc.sign_in import SignIn
signin = SignIn(selenium, timeout, expect='new')
signin.sign_in_new_user(email, password)
mail = restmail.get_mail(restmail_username)
verify_url = re.search(BrowserID.VERIFY_URL_REGEX,
mail[0]['text']).group(0)

selenium.open(verify_url)
from ...pages.rc.verify_email_address import VerifyEmailAddress
verify_email_address = VerifyEmailAddress(selenium, timeout)
verify_email_address.verify_email_address(password)
from ...pages.rc.complete_registration import CompleteRegistration
complete_registration = CompleteRegistration(selenium,
timeout,
expect='success')
assert 'Thank you' in complete_registration.thank_you
return (email, password)
50 changes: 0 additions & 50 deletions tests/rc/check_verify_email_address.py

This file was deleted.

0 comments on commit c4d1952

Please sign in to comment.