From cab44227c133af60a31f1988939cbeca5a865efd Mon Sep 17 00:00:00 2001 From: Tulio Casagrande Date: Wed, 12 Apr 2017 17:14:51 -0300 Subject: [#927] Confirm email with the recovery code with @deniscostadsc --- .../functional/features/account_recovery.feature | 6 +++ service/test/functional/features/environment.py | 13 +++--- .../functional/features/page_objects/__init__.py | 3 +- .../functional/features/page_objects/base_page.py | 6 ++- .../functional/features/page_objects/inbox_page.py | 52 ++++++++++++++++++++++ .../functional/features/steps/backup_account.py | 2 +- service/test/functional/features/steps/common.py | 4 -- service/test/functional/features/steps/login.py | 1 + .../test/functional/features/steps/mail_list.py | 24 +++++----- .../test/functional/features/steps/mail_view.py | 9 ++-- 10 files changed, 93 insertions(+), 27 deletions(-) create mode 100644 service/test/functional/features/page_objects/inbox_page.py diff --git a/service/test/functional/features/account_recovery.feature b/service/test/functional/features/account_recovery.feature index cf0144e0..414cf30e 100644 --- a/service/test/functional/features/account_recovery.feature +++ b/service/test/functional/features/account_recovery.feature @@ -28,6 +28,12 @@ Feature: Account Recovery And I logout from the header And I should see the login page + Scenario: Confirming I received the recovery code at my backup email + Given I am logged in Pixelated + When I open the mail with the recovery code + Then I see the mail has the recovery code + Then I logout + Scenario: Recovering an account Given I am on the account recovery page When I submit admin recovery code diff --git a/service/test/functional/features/environment.py b/service/test/functional/features/environment.py index f1cc0e44..efc86801 100644 --- a/service/test/functional/features/environment.py +++ b/service/test/functional/features/environment.py @@ -52,12 +52,14 @@ def before_all(context): if not context.host.startswith('http'): context.host = 'https://{}'.format(context.host) - hostname = urlparse(context.host).hostname - context.signup_url = 'https://{}/signup'.format(hostname) - context.login_url = 'https://mail.{}/login'.format(hostname) - context.backup_account_url = 'https://mail.{}/backup-account'.format(hostname) - context.account_recovery_url = 'https://mail.{}/account-recovery'.format(hostname) + context.hostname = urlparse(context.host).hostname + context.signup_url = 'https://{}/signup'.format(context.hostname) + context.inbox_url = 'https://mail.{}'.format(context.hostname) + context.login_url = 'https://mail.{}/login'.format(context.hostname) + context.backup_account_url = 'https://mail.{}/backup-account'.format(context.hostname) + context.account_recovery_url = 'https://mail.{}/account-recovery'.format(context.hostname) context.username = 'testuser_{}'.format(uuid.uuid4()) + context.user_email = '{}@{}'.format(context.username, context.hostname) if 'localhost' in context.host: _mock_user_agent(context) @@ -70,6 +72,7 @@ def before_all(context): def before_tag(context, tag): if tag == "smoke": context.username = 'testuser_{}'.format(uuid.uuid4()) + context.user_email = '{}@{}'.format(context.username, context.hostname) utils.create_user(context) diff --git a/service/test/functional/features/page_objects/__init__.py b/service/test/functional/features/page_objects/__init__.py index 6868330b..920bf541 100644 --- a/service/test/functional/features/page_objects/__init__.py +++ b/service/test/functional/features/page_objects/__init__.py @@ -14,5 +14,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see . -from base_page import BasePage from account_recovery_page import AccountRecoveryPage +from base_page import BasePage +from inbox_page import InboxPage diff --git a/service/test/functional/features/page_objects/base_page.py b/service/test/functional/features/page_objects/base_page.py index e5fb9a39..4756d930 100644 --- a/service/test/functional/features/page_objects/base_page.py +++ b/service/test/functional/features/page_objects/base_page.py @@ -16,7 +16,8 @@ from steps.common import ( fill_by_css_selector, - find_element_by_css_selector) + find_element_by_css_selector, + find_element_by_xpath) class BasePage(object): @@ -31,5 +32,8 @@ class BasePage(object): def fill_by_css_selector(self, loc, text): fill_by_css_selector(self.context, loc, text) + def find_element_by_xpath(self, xpath): + return find_element_by_xpath(self.context, xpath) + def visit(self): self.context.browser.get(self.base_url) diff --git a/service/test/functional/features/page_objects/inbox_page.py b/service/test/functional/features/page_objects/inbox_page.py new file mode 100644 index 00000000..67ef1375 --- /dev/null +++ b/service/test/functional/features/page_objects/inbox_page.py @@ -0,0 +1,52 @@ +# +# Copyright (c) 2017 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . + +from base_page import BasePage +from common import execute_ignoring_staleness + + +class InboxPage(BasePage): + def __init__(self, context): + super(InboxPage, self).__init__(context, context.inbox_url) + + self._locators = { + 'first_email': '.mail-list-entry__item', + 'read_sandbox': '#read-sandbox', + 'iframe_body': 'body', + } + + def _get_first_mail(self): + return self.find_element_by_css_selector(self._locators['first_email']) + + def get_mail_with_subject(self, subject): + return self.find_element_by_xpath("//*[@class='mail-list-entry__item-subject' and contains(.,'%s')]" % subject) + + def open_first_mail_in_the_mail_list(self): + # it seems page is often still loading so staleness exceptions happen often + self.context.current_mail_id = 'mail-' + execute_ignoring_staleness( + lambda: self._get_first_mail().get_attribute('href').split('/')[-1]) + execute_ignoring_staleness(lambda: self._get_first_mail().click()) + + def open_mail_with_the_recovery_code(self): + self.get_mail_with_subject('Recovery Code').click() + + def get_body_message(self): + self.find_element_by_css_selector(self._locators['read_sandbox']) + self.context.browser.switch_to_frame('read-sandbox') + body_message = self.find_element_by_css_selector(self._locators['iframe_body']).text + self.context.browser.switch_to_default_content() + + return body_message diff --git a/service/test/functional/features/steps/backup_account.py b/service/test/functional/features/steps/backup_account.py index 56d30211..5a1052a8 100644 --- a/service/test/functional/features/steps/backup_account.py +++ b/service/test/functional/features/steps/backup_account.py @@ -29,7 +29,7 @@ def backup_account_page(context): @when(u'I submit my backup account') def submit_backup_email(context): - fill_by_css_selector(context, 'input[name="email"]', 'test@test.com') + fill_by_css_selector(context, 'input[name="email"]', context.user_email) find_element_by_css_selector(context, '.submit-button button[type="submit"]').click() diff --git a/service/test/functional/features/steps/common.py b/service/test/functional/features/steps/common.py index 3e1e995e..ff6e6166 100644 --- a/service/test/functional/features/steps/common.py +++ b/service/test/functional/features/steps/common.py @@ -146,10 +146,6 @@ def click_button(context, title, element='button'): button.click() -def mail_list_with_subject_exists(context, subject): - return find_element_by_xpath(context, "//*[@class='mail-list-entry__item-subject' and contains(.,'%s')]" % subject) - - def reply_subject(context): e = find_element_by_css_selector(context, '#reply-subject') return e.text diff --git a/service/test/functional/features/steps/login.py b/service/test/functional/features/steps/login.py index 35bb5ca2..7360adb7 100644 --- a/service/test/functional/features/steps/login.py +++ b/service/test/functional/features/steps/login.py @@ -56,6 +56,7 @@ def see_interstitial(context): find_element_by_css_selector(context, 'section#hive-section') +@then(u'I logout') @when(u'I logout') def click_logout(context): find_element_by_css_selector(context, '#logout-form div').click() diff --git a/service/test/functional/features/steps/mail_list.py b/service/test/functional/features/steps/mail_list.py index 227aa9ed..2953c1af 100644 --- a/service/test/functional/features/steps/mail_list.py +++ b/service/test/functional/features/steps/mail_list.py @@ -17,13 +17,12 @@ from behave import when, then, given from selenium.common.exceptions import TimeoutException +from ..page_objects import InboxPage from common import ( ImplicitWait, - execute_ignoring_staleness, find_element_by_id, find_element_by_css_selector, find_elements_by_css_selector, - mail_list_with_subject_exists, wait_for_condition, wait_for_loading_to_finish) @@ -42,10 +41,6 @@ def open_current_mail(context): e.click() -def get_first_email(context): - return find_element_by_css_selector(context, '.mail-list-entry__item') - - @then('I see that mail under the \'{tag}\' tag') def impl(context, tag): context.execute_steps("when I select the tag '%s'" % tag) @@ -59,9 +54,12 @@ def impl(context): @when('I open the first mail in the mail list') def impl(context): - # it seems page is often still loading so staleness exceptions happen often - context.current_mail_id = 'mail-' + execute_ignoring_staleness(lambda: get_first_email(context).get_attribute('href').split('/')[-1]) - execute_ignoring_staleness(lambda: get_first_email(context).click()) + InboxPage(context).open_first_mail_in_the_mail_list() + + +@when('I open the mail with the recovery code') +def impl(context): + InboxPage(context).open_mail_with_the_recovery_code() @when('I open the first mail in the \'{tag}\'') @@ -83,7 +81,7 @@ def impl(context): @then('the deleted mail is there') def impl(context): - mail_list_with_subject_exists(context, context.last_subject) + InboxPage(context).get_mail_with_subject(context.last_subject) @given('I have mails') @@ -140,3 +138,9 @@ def impl(context): @then('I should not see any email') def impl(context): _wait_for_mail_list_to_be_empty(context) + + +@then(u'I see the mail has the recovery code') +def step_impl(context): + expected_body = 'Your code' + context.execute_steps(u"Then I see that the body has '%s'" % expected_body) diff --git a/service/test/functional/features/steps/mail_view.py b/service/test/functional/features/steps/mail_view.py index 65959b70..89464245 100644 --- a/service/test/functional/features/steps/mail_view.py +++ b/service/test/functional/features/steps/mail_view.py @@ -17,6 +17,7 @@ from behave import then, when from selenium.webdriver.common.keys import Keys +from ..page_objects import InboxPage from common import ( click_button, find_element_by_css_selector, @@ -32,12 +33,10 @@ def impl(context, subject): @then('I see that the body reads \'{expected_body}\'') +@then('I see that the body has \'{expected_body}\'') def impl(context, expected_body): - find_element_by_css_selector(context, '#read-sandbox') - context.browser.switch_to_frame('read-sandbox') - e = find_element_by_css_selector(context, 'body') - assert e.text == expected_body - context.browser.switch_to_default_content() + actual_body = InboxPage(context).get_body_message() + assert expected_body in actual_body @then('that email has the \'{tag}\' tag') -- cgit v1.2.3