Skip to content

Commit

Permalink
Merge pull request mozilla#98 from AndreiH/refactor_profile_page
Browse files Browse the repository at this point in the history
Refactoring "Profile page"
  • Loading branch information
Matt Brandt committed Aug 1, 2013
2 parents 10ecbbe + da27a27 commit 6484d09
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 182 deletions.
4 changes: 2 additions & 2 deletions pages/base.py
Expand Up @@ -70,8 +70,8 @@ def create_new_user(self, user):
pop_up.sign_in(user['email'], user['password'])

WebDriverWait(self.selenium, 20).until(lambda s: self.is_user_loggedin)
from pages.register import ProfileTab
return ProfileTab(self.testsetup)
from pages.register import Register
return Register(self.testsetup)

# Logged in

Expand Down
61 changes: 11 additions & 50 deletions pages/edit_profile.py
Expand Up @@ -13,14 +13,18 @@

class EditProfile(Base):

_acknowledge_deletion_checkbox_locator = (By.CSS_SELECTOR, '.acknowledge')
_cancel_button_locator = (By.CSS_SELECTOR, "#edit_controls a")
_update_button_locator = (By.CSS_SELECTOR, "#edit_controls button")

#edit your profile tabs locators
_profile_tab_locator = (By.CSS_SELECTOR, 'div.tabbable > ul.nav > li:nth-of-type(1) > a')
_skills_tab_locator = (By.CSS_SELECTOR, 'div.tabbable > ul.nav > li:nth-of-type(2) > a')
_vouches_tab_locator = (By.CSS_SELECTOR, 'div.tabbable > ul.nav > li:nth-of-type(3) > a')
_account_tab_locator = (By.CSS_SELECTOR, 'div.tabbable > ul.nav > li:nth-of-type(4) > a')
_full_name_field_locator = (By.ID, 'id_full_name')
_website_field_locator = (By.ID, 'id_website')
_bio_field_locator = (By.ID, 'id_bio')
_groups_field_locator = (By.CSS_SELECTOR, '#id_groups + ul input')
_skills_field_locator = (By.CSS_SELECTOR, '#id_skills + ul input')
_voucher_name_locator = (By.CSS_SELECTOR, '#vouches .vouched')
_username_field_locator = (By.ID, 'id_username')
_browserid_mail_locator = (By.CSS_SELECTOR, '.control-group:nth-of-type(2) .label-text')
_delete_profile_button_locator = (By.CSS_SELECTOR, '.delete')

def click_update_button(self):
self.selenium.find_element(*self._update_button_locator).click()
Expand All @@ -29,27 +33,6 @@ def click_update_button(self):
def click_cancel_button(self):
self.selenium.find_element(*self._cancel_button_locator).click()

def go_to_tab(self, tab_name):
if tab_name is "profile":
self.selenium.find_element(*self._profile_tab_locator).click()
return ProfileTab(self.testsetup)
elif tab_name is "skills":
self.selenium.find_element(*self._skills_tab_locator).click()
return SkillsAndGroupsTab(self.testsetup)
elif tab_name is "vouches":
self.selenium.find_element(*self._vouches_tab_locator).click()
return VouchesAndInvitesTab(self.testsetup)
elif tab_name is "account":
self.selenium.find_element(*self._account_tab_locator).click()
return AccountTab(self.testsetup)


class ProfileTab(EditProfile):

_full_name_field_locator = (By.ID, 'id_full_name')
_website_field_locator = (By.ID, 'id_website')
_bio_field_locator = (By.ID, 'id_bio')

def set_full_name(self, full_name):
element = self.selenium.find_element(*self._full_name_field_locator)
element.clear()
Expand All @@ -65,12 +48,6 @@ def set_bio(self, biography):
element.clear()
element.send_keys(biography)


class SkillsAndGroupsTab(EditProfile):

_groups_field_locator = (By.CSS_SELECTOR, '#id_groups + ul input')
_skills_field_locator = (By.CSS_SELECTOR, '#id_skills + ul input')

def add_group(self, group_name):
element = self.selenium.find_element(*self._group_field_locator)
element.send_keys(group_name)
Expand All @@ -79,23 +56,10 @@ def add_skill(self, skill_name):
element = self.selenium.send_keys(*self._skill_field_locator)
element.send_keys(skill_name)


class VouchesAndInvitesTab(EditProfile):

_voucher_name_locator = (By.CSS_SELECTOR, '#vouches .vouched')

@property
def vouched_by(self):
return self.selenium.find_element(*self._voucher_name_locator).text


class AccountTab(EditProfile):

_username_field_locator = (By.ID, 'id_username')
_browserid_mail_locator = (By.CSS_SELECTOR, '.control-group:nth-of-type(2) .label-text')
_delete_profile_button_locator = (By.CSS_SELECTOR, '.btn.btn-danger')
_browserid_link_locator = (By.CSS_SELECTOR, '#account div.controls > span > a')

@property
def username(self):
return self.selenium.find_element(*self._username_field_locator).text
Expand All @@ -104,11 +68,8 @@ def username(self):
def browserid_email(self):
return self.selenium.find_element(*self._browserid_mail_locator).text

@property
def is_browserid_link_present(self):
return self.is_element_present(*self._browserid_link_locator)

def click_delete_profile_button(self):
self.selenium.find_element(*self._acknowledge_deletion_checkbox_locator).click()
self.selenium.find_element(*self._delete_profile_button_locator).click()
from pages.confirm_profile_delete import ConfirmProfileDelete
return ConfirmProfileDelete(self.testsetup)
2 changes: 1 addition & 1 deletion pages/invite.py
Expand Up @@ -14,7 +14,7 @@ class Invite(Base):

_recipient_field_locator = (By.ID, 'id_recipient')
_send_invite_button_locator = (By.CSS_SELECTOR, '#main button')
_error_text_locator = (By.CSS_SELECTOR, '.help-inline')
_error_text_locator = (By.CSS_SELECTOR, '.error-message')

@property
def error_text_message(self):
Expand Down
28 changes: 11 additions & 17 deletions pages/profile.py
Expand Up @@ -13,19 +13,18 @@

class Profile(Base):

_edit_my_profile_button_locator = (By.ID, 'edit-profile')
_profile_photo_locator = (By.ID, 'profile-photo')
_name_locator = (By.CSS_SELECTOR, 'h2.p-name')
_email_locator = (By.CSS_SELECTOR, '#profile-info a[href^="mailto:"]')
_website_locator = (By.CSS_SELECTOR, '#profile-info > dl > dd > a[href^="http"]')
_profile_photo_locator = (By.CSS_SELECTOR, '.profile-photo > img')
_name_locator = (By.CSS_SELECTOR, 'h1.p-name')
_email_locator = (By.CSS_SELECTOR, '.u-email.email')
_website_locator = (By.CSS_SELECTOR, '.u-url.url > a')
_vouched_by_locator = (By.CSS_SELECTOR, '#profile-info .vouched')
_biography_locator = (By.ID, 'bio')
_biography_locator = (By.CSS_SELECTOR, '#bio > p')
_skills_locator = (By.ID, 'skills')
_languages_locator = (By.ID, 'languages')
_location_locator = (By.XPATH, '//dt[.="Location"]/following-sibling::dd')
_city_locator = (By.XPATH, '//dt[.="Location"]/following-sibling::dd/a[contains(@href, "city")]')
_region_locator = (By.XPATH, '//dt[.="Location"]/following-sibling::dd/a[contains(@href, "region")]')
_country_locator = (By.XPATH, '//dt[.="Location"]/following-sibling::dd/a[last()]')
_location_locator = (By.ID, 'location')
_city_locator = (By.CSS_SELECTOR, '#location > a:nth-child(2)')
_region_locator = (By.CSS_SELECTOR, '#location > a:nth-child(3)')
_country_locator = (By.CSS_SELECTOR, '#location > a:nth-child(4)')

def __init__(self, testsetup):
Base.__init__(self, testsetup)
Expand Down Expand Up @@ -54,7 +53,7 @@ def vouched_by(self):

@property
def skills(self):
return self.selenium.find_element(*self._skills_locator).text
return self.selenium.find_element(*self._skills_locator).text.split('\n')[1]

@property
def location(self):
Expand Down Expand Up @@ -89,9 +88,4 @@ def click_country_name(self, **kwargs):

@property
def languages(self):
return self.selenium.find_element(*self._languages_locator).text

def click_edit_my_profile_button(self):
self.selenium.find_element(*self._edit_my_profile_button_locator).click()
from pages.edit_profile import EditProfile
return EditProfile(self.testsetup)
return self.selenium.find_element(*self._languages_locator).text.split('\n')[1]
65 changes: 12 additions & 53 deletions pages/register.py
Expand Up @@ -13,36 +13,23 @@

class Register(Base):

#edit your profile tabs locators
_profile_tab_locator = (By.CSS_SELECTOR, 'div.tabbable > ul.nav > li:nth-of-type(1) > a')
_skills_tab_locator = (By.CSS_SELECTOR, 'div.tabbable > ul.nav > li:nth-of-type(2) > a')
_location_tab_locator = (By.CSS_SELECTOR, 'div.tabbable > ul.nav > li:nth-of-type(3) > a')

_error_locator = (By.CSS_SELECTOR, 'div.alert.alert-error')

@property
def error_message(self):
return self.selenium.find_element(*self._error_locator).text

def go_to_tab(self, tab_name):
if tab_name is "profile":
self.selenium.find_element(*self._profile_tab_locator).click()
return ProfileTab(self.testsetup)
elif tab_name is "skills":
self.selenium.find_element(*self._skills_tab_locator).click()
return SkillsAndGroupsTab(self.testsetup)
elif tab_name is "location":
self.selenium.find_element(*self._location_tab_locator).click()
return LocationTab(self.testsetup)


class ProfileTab(Register):

_full_name_field_locator = (By.ID, 'id_full_name')
_website_field_locator = (By.ID, 'id_website')
_bio_field_locator = (By.ID, 'id_bio')
_skills_field_locator = (By.CSS_SELECTOR, '#id_skills + ul input')
_language_field_locator = (By.CSS_SELECTOR, '#id_languages + ul input ')
_previous_button_locator = (By.ID, 'page1button')
_country_locator = (By.ID, 'id_country')
_state_locator = (By.ID, 'id_region')
_city_locator = (By.ID, 'id_city')
_privacy_locator = (By.ID, 'id_optin')
_privacy_error_message_locator = (By.CSS_SELECTOR, '.error-message')
_create_profile_button_locator = (By.CSS_SELECTOR, '#edit_controls > button')

_next_button_locator = (By.ID, 'page2button')
@property
def error_message(self):
return self.selenium.find_element(*self._error_locator).text

def set_full_name(self, full_name):
element = self.selenium.find_element(*self._full_name_field_locator)
Expand All @@ -56,19 +43,6 @@ def set_bio(self, biography):
element = self.selenium.find_element(*self._bio_field_locator)
element.send_keys(biography)

def click_next_button(self):
self.selenium.find_element(*self._next_button_locator).click()
return SkillsAndGroupsTab(self.testsetup)


class SkillsAndGroupsTab(Register):

_skills_field_locator = (By.ID, 'id_skills')
_language_field_locator = (By.ID, 'id_languages')

_next_button_locator = (By.ID, 'page3button')
_previous_button_locator = (By.ID, 'page1button')

def add_language(self, language_name):
element = self.selenium.find_element(*self._language_field_locator)
element.send_keys(language_name)
Expand All @@ -81,23 +55,8 @@ def add_skill(self, skill_name):
# send tab to make the entry "stick"
element.send_keys("\t")

def click_next_button(self):
self.selenium.find_element(*self._next_button_locator).click()
return LocationTab(self.testsetup)

def click_previous_button(self):
self.selenium.find_element(*self._previous_button_locator).click()
return ProfileTab(self.testsetup)


class LocationTab(Register):

_country_locator = (By.ID, 'id_country')
_state_locator = (By.ID, 'id_region')
_city_locator = (By.ID, 'id_city')
_privacy_locator = (By.ID, 'id_optin')
_privacy_error_message_locator = (By.CSS_SELECTOR, 'div.control-group > div.controls > label.checkbox + span.help-inline')
_create_profile_button_locator = (By.CSS_SELECTOR, 'button.span3.btn-large.btn-primary')

@property
def privacy_error_message(self):
Expand Down
1 change: 0 additions & 1 deletion tests/test_about_page.py
Expand Up @@ -14,7 +14,6 @@
class TestAboutPage:

@pytest.mark.nondestructive
@pytest.mark.xfail(reason="TODO - update to handle new footer behavior introduced by Bug 858488")
def test_about_page(self, mozwebqa):
home_page = Home(mozwebqa)
about_mozillians_page = home_page.footer.click_about_link()
Expand Down

0 comments on commit 6484d09

Please sign in to comment.