This repository has been archived by the owner on Aug 20, 2018. It is now read-only.
forked from mozilla/bidpom
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
295 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/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 | ||
|
||
|
||
class AccountManager(Base): | ||
|
||
_emails_locator = "id('emailList')/descendant::div[contains(@class, 'email')]" | ||
_edit_password_button_locator = 'css=#edit_password button.edit' | ||
_old_password_field_locator = 'id=old_password' | ||
_new_password_field_locator = 'id=new_password' | ||
_change_password_done_locator = 'id=changePassword' | ||
_sign_in_locator = 'css=a.signIn' | ||
_sign_out_locator = 'css=a.signOut' | ||
|
||
def __init__(self, selenium, timeout): | ||
Base.__init__(self, selenium, timeout) | ||
self.wait_for_element_visible('xpath=%s' % self._emails_locator) | ||
|
||
@property | ||
def emails(self): | ||
return [self.selenium.get_text('xpath=%s[%s]' % (self._emails_locator, i)) for i in range(1, self.selenium.get_xpath_count(self._emails_locator) + 1)] | ||
|
||
def click_edit_password(self): | ||
"""Click edit password to show the new/old password fields""" | ||
self.selenium.click(self._edit_password_button_locator) | ||
self.wait_for_element_visible(self._old_password_field_locator) | ||
|
||
@property | ||
def old_password(self): | ||
"""Get the value of the old password field.""" | ||
return self.selenium.get_text(self._old_password_field_locator) | ||
|
||
@old_password.setter | ||
def old_password(self, value): | ||
"""Set the value of the old password field.""" | ||
self.selenium.type(self._old_password_field_locator, value) | ||
|
||
@property | ||
def new_password(self): | ||
"""Get the value of the new password field.""" | ||
return self.selenium.get_text(self._new_password_field_locator) | ||
|
||
@new_password.setter | ||
def new_password(self, value): | ||
"""Set the value of the new password field.""" | ||
self.selenium.type(self._new_password_field_locator, value) | ||
|
||
def click_password_done(self): | ||
"""Click password done to save the new password.""" | ||
self.selenium.click(self._change_password_done_locator) | ||
self.wait_for_element_visible(self._edit_password_button_locator) | ||
|
||
def click_sign_out(self): | ||
self.selenium.click(self._sign_out_locator) | ||
self.wait_for_element_visible(self._sign_in_locator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/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 AccountManager(Base): | ||
|
||
_emails_locator = (By.CSS_SELECTOR, '#emailList .email') | ||
_edit_password_button_locator = (By.CSS_SELECTOR, '#edit_password button.edit') | ||
_old_password_field_locator = (By.ID, 'old_password') | ||
_new_password_field_locator = (By.ID, 'new_password') | ||
_change_password_done_locator = (By.ID, 'changePassword') | ||
_sign_in_locator = (By.CSS_SELECTOR, 'a.signIn') | ||
_sign_out_locator = (By.CSS_SELECTOR, 'a.signOut') | ||
|
||
def __init__(self, selenium, timeout): | ||
Base.__init__(self, selenium, timeout) | ||
|
||
WebDriverWait(self.selenium, self.timeout).until( | ||
lambda s: s.find_element(*self._emails_locator).is_displayed()) | ||
|
||
@property | ||
def emails(self): | ||
return [element.text for element in self.selenium.find_elements(*self._emails_locator)] | ||
|
||
def click_edit_password(self): | ||
"""Click edit password to show the new/old password fields""" | ||
self.selenium.find_element(*self._edit_password_button_locator).click() | ||
WebDriverWait(self.selenium, self.timeout).until( | ||
lambda s: s.find_element(*self._old_password_field_locator).is_displayed()) | ||
|
||
@property | ||
def old_password(self): | ||
"""Get the value of the old password field.""" | ||
return self.selenium.find_element(*self._old_password_field_locator).text | ||
|
||
@old_password.setter | ||
def old_password(self, value): | ||
"""Set the value of the old password field.""" | ||
password = self.selenium.find_element(*self._old_password_field_locator) | ||
password.clear() | ||
password.send_keys(value) | ||
|
||
@property | ||
def new_password(self): | ||
"""Get the value of the new password field.""" | ||
return self.selenium.find_element(*self._new_password_field_locator).text | ||
|
||
@new_password.setter | ||
def new_password(self, value): | ||
"""Set the value of the new password field.""" | ||
password = self.selenium.find_element(*self._new_password_field_locator) | ||
password.clear() | ||
password.send_keys(value) | ||
|
||
def click_password_done(self): | ||
"""Click password done to save the new password.""" | ||
self.selenium.find_element(*self._change_password_done_locator).click() | ||
WebDriverWait(self.selenium, self.timeout).until( | ||
lambda s: s.find_element(*self._edit_password_button_locator).is_displayed()) | ||
|
||
def click_sign_out(self): | ||
self.selenium.find_element(*self._sign_out_locator).click() | ||
WebDriverWait(self.selenium, self.timeout).until( | ||
lambda s: s.find_element(*self._sign_in_locator).is_displayed()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/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/. | ||
|
||
import re | ||
import uuid | ||
|
||
from ... import BrowserID | ||
from .. import restmail | ||
|
||
|
||
class BaseTest(object): | ||
|
||
def create_verified_user(self, selenium, timeout): | ||
restmail_username = 'bidpom_%s' % uuid.uuid1() | ||
email = '%s@restmail.net' % restmail_username | ||
password = 'password' | ||
|
||
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.complete_registration import CompleteRegistration | ||
complete_registration = CompleteRegistration(selenium, | ||
timeout, | ||
expect='success') | ||
assert 'Thank you' in complete_registration.thank_you | ||
return (email, password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/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/. | ||
|
||
import pytest | ||
|
||
from ... import BrowserID | ||
from base import BaseTest | ||
|
||
|
||
@pytest.mark.nondestructive | ||
class TestSignIn(BaseTest): | ||
|
||
@pytest.mark.travis | ||
def test_change_password(self, mozwebqa): | ||
(email, password) = self.create_verified_user(mozwebqa.selenium, | ||
mozwebqa.timeout) | ||
|
||
mozwebqa.selenium.open('https://login.dev.anosrep.org') | ||
from ...pages.rc.account_manager import AccountManager | ||
account_manager = AccountManager(mozwebqa.selenium, mozwebqa.timeout) | ||
|
||
assert email in account_manager.emails | ||
|
||
account_manager.click_edit_password() | ||
account_manager.old_password = password | ||
new_password = password + '_new' | ||
account_manager.new_password = new_password | ||
account_manager.click_password_done() | ||
account_manager.click_sign_out() | ||
|
||
mozwebqa.selenium.open('%s/' % mozwebqa.base_url) | ||
|
||
login_locator = 'css=#loggedout button' | ||
mozwebqa.wait_for_element_visible(mozwebqa, login_locator) | ||
mozwebqa.selenium.click(login_locator) | ||
|
||
browser_id = BrowserID(mozwebqa.selenium, mozwebqa.timeout) | ||
browser_id.sign_in(email, new_password) | ||
|
||
logout_locator = 'css=#loggedin a' | ||
mozwebqa.wait_for_element_visible(mozwebqa, logout_locator) | ||
assert mozwebqa.selenium.is_visible(logout_locator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/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/. | ||
|
||
import re | ||
import uuid | ||
|
||
from ... import BrowserID | ||
from .. import restmail | ||
|
||
|
||
class BaseTest(object): | ||
|
||
def create_verified_user(self, selenium, timeout): | ||
restmail_username = 'bidpom_%s' % uuid.uuid1() | ||
email = '%s@restmail.net' % restmail_username | ||
password = 'password' | ||
|
||
from ...pages.webdriver.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.get(verify_url) | ||
from ...pages.webdriver.complete_registration import CompleteRegistration | ||
complete_registration = CompleteRegistration(selenium, | ||
timeout, | ||
expect='success') | ||
assert 'Thank you' in complete_registration.thank_you | ||
return (email, password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/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/. | ||
|
||
import pytest | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
|
||
from ... import BrowserID | ||
from base import BaseTest | ||
|
||
|
||
@pytest.mark.nondestructive | ||
class TestSignIn(BaseTest): | ||
|
||
@pytest.mark.travis | ||
def test_change_password(self, mozwebqa): | ||
(email, password) = self.create_verified_user(mozwebqa.selenium, | ||
mozwebqa.timeout) | ||
|
||
mozwebqa.selenium.get('https://login.dev.anosrep.org') | ||
from ...pages.webdriver.account_manager import AccountManager | ||
account_manager = AccountManager(mozwebqa.selenium, mozwebqa.timeout) | ||
|
||
assert email in account_manager.emails | ||
|
||
account_manager.click_edit_password() | ||
account_manager.old_password = password | ||
new_password = password + '_new' | ||
account_manager.new_password = new_password | ||
account_manager.click_password_done() | ||
account_manager.click_sign_out() | ||
|
||
mozwebqa.selenium.get('%s/' % mozwebqa.base_url) | ||
|
||
login_locator = '#loggedout button' | ||
WebDriverWait(mozwebqa.selenium, mozwebqa.timeout).until( | ||
lambda s: s.find_element_by_css_selector(login_locator).is_displayed()) | ||
mozwebqa.selenium.find_element_by_css_selector(login_locator).click() | ||
|
||
browser_id = BrowserID(mozwebqa.selenium, mozwebqa.timeout) | ||
browser_id.sign_in(email, new_password) | ||
|
||
WebDriverWait(mozwebqa.selenium, mozwebqa.timeout).until( | ||
lambda s: s.find_element_by_id('loggedin').is_displayed()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters