From 6b5de66fc5adc3c62a92738e9f317c4b1335f838 Mon Sep 17 00:00:00 2001 From: Tiago Ferraz Date: Mon, 9 Mar 2015 16:14:50 -0300 Subject: Refactoring of fuctional tests The scenarios were updated to follow the conventions of gherkin steps. Removal of duplicated code. --- .../features/compose_save_draft_and_send.feature | 12 +++++++----- service/test/functional/features/environment.py | 8 ++------ .../features/forward_trash_archive.feature | 17 +++++++++-------- .../functional/features/search_and_destroy.feature | 9 +++++---- service/test/functional/features/steps/__init__.py | 15 +++++++++++++++ service/test/functional/features/steps/compose.py | 20 ++++---------------- service/test/functional/features/steps/mail_list.py | 8 +++++++- service/test/functional/features/steps/mail_view.py | 12 ++++++------ service/test/functional/features/steps/tag_list.py | 13 +++++-------- .../test/functional/features/tag_and_reply.feature | 7 +++++-- 10 files changed, 65 insertions(+), 56 deletions(-) diff --git a/service/test/functional/features/compose_save_draft_and_send.feature b/service/test/functional/features/compose_save_draft_and_send.feature index 10fa1aa2..b24d4c51 100644 --- a/service/test/functional/features/compose_save_draft_and_send.feature +++ b/service/test/functional/features/compose_save_draft_and_send.feature @@ -15,16 +15,18 @@ # along with Pixelated. If not, see . Feature: compose mail, save draft and send mail + As a user of Pixelated + I want to save drafts + So I can review and send them later Scenario: user composes and email, save the draft, later sends the draft and checks the sent message - Given I compose a message with + When I compose a message with | subject | body | | Pixelated rocks! | You should definitely use it. Cheers, User. | - # And for the 'To' field I type 'ab' and chose the first contact that shows - And for the 'To' field I enter 'pixelated@friends.org' - And I save the draft + And for the 'To' field I enter 'pixelated@friends.org' + And I save the draft When I open the saved draft and send it Then I see that mail under the 'sent' tag When I open that mail Then I see that the subject reads 'Pixelated rocks!' - And I see that the body reads 'You should definitely use it. Cheers, User.' + And I see that the body reads 'You should definitely use it. Cheers, User.' diff --git a/service/test/functional/features/environment.py b/service/test/functional/features/environment.py index 5e93c840..5969120a 100644 --- a/service/test/functional/features/environment.py +++ b/service/test/functional/features/environment.py @@ -14,11 +14,11 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see . import logging -import time -from test.support.dispatcher.proxy import Proxy +from test.support.dispatcher.proxy import Proxy from test.support.integration import AppTestClient from selenium import webdriver + from pixelated.resources.features_resource import FeaturesResource @@ -50,10 +50,6 @@ def after_feature(context, feature): context.browser.quit() -def take_screenshot(context): - context.browser.save_screenshot('/tmp/screenshot.jpeg') - - def save_source(context): with open('/tmp/source.html', 'w') as out: out.write(context.browser.page_source.encode('utf8')) diff --git a/service/test/functional/features/forward_trash_archive.feature b/service/test/functional/features/forward_trash_archive.feature index 91e078ea..85c422d9 100644 --- a/service/test/functional/features/forward_trash_archive.feature +++ b/service/test/functional/features/forward_trash_archive.feature @@ -14,18 +14,19 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see . -Feature: forward_trash_archive +Feature: forward and deletion + As a user of Pixelated + I want to forward emails using CC and Bcc features + So I can take actions Scenario: User forwards a mail, add CC and BCC address, later trash the mail Given I have a mail in my inbox When I open the first mail in the 'inbox' - Then I choose to forward this mail - # And for the 'CC' field I type 'ab' and chose the first contact that shows - # And for the 'Bcc' field I type 'fr' and chose the first contact that shows - Given for the 'CC' field I enter 'pixelated@friends.org' - And for the 'Bcc' field I enter 'pixelated@family.org' - Then I forward this mail + And I choose to forward this mail + When for the 'CC' field I enter 'pixelated@friends.org' + And for the 'Bcc' field I enter 'pixelated@family.org' + And I forward this mail When I open the first mail in the 'sent' Then I see the mail has a cc and a bcc recipient - And I choose to trash + When I choose to trash Then I see that mail under the 'trash' tag diff --git a/service/test/functional/features/search_and_destroy.feature b/service/test/functional/features/search_and_destroy.feature index 6efeae8b..4ce37b78 100644 --- a/service/test/functional/features/search_and_destroy.feature +++ b/service/test/functional/features/search_and_destroy.feature @@ -16,15 +16,16 @@ # XXX: must implement with HTML content -Feature: search mail and destroy +Feature: search mail and deletion + As a user of pixelated + I want to search for emails + So I can manage them - Scenario: User searches for a mail and deletes it' + Scenario: User searches for a mail and deletes it Given I have a mail in my inbox When I search for a mail with the words "the body of this message" When I open the first mail in the mail list Then I see one or more mails in the search results -# Then I see if the mail has html content When I try to delete the first mail - # Then I learn that the mail was deleted When I select the tag 'trash' Then the deleted mail is there diff --git a/service/test/functional/features/steps/__init__.py b/service/test/functional/features/steps/__init__.py index e69de29b..2756a319 100644 --- a/service/test/functional/features/steps/__init__.py +++ b/service/test/functional/features/steps/__init__.py @@ -0,0 +1,15 @@ +# +# Copyright (c) 2014 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 . diff --git a/service/test/functional/features/steps/compose.py b/service/test/functional/features/steps/compose.py index cf75979e..aeef11c4 100644 --- a/service/test/functional/features/steps/compose.py +++ b/service/test/functional/features/steps/compose.py @@ -20,7 +20,7 @@ from common import * from hamcrest import * -@given('I compose a message with') +@when('I compose a message with') def impl(context): take_screenshot(context, '/tmp/screenshot.jpeg') toggle = context.browser.find_element_by_id('compose-mails-trigger') @@ -31,31 +31,19 @@ def impl(context): fill_by_xpath(context, '//*[@id="text-box"]', row['body']) -@given("for the '{recipients_field}' field I type '{to_type}' and chose the first contact that shows") -def choose_impl(context, recipients_field, to_type): - browser = context.browser - browser.find_element_by_css_selector('#recipients-to-area span input.tt-input').click() - recipients_field = recipients_field.lower() - css_selector = '#recipients-%s-area' % recipients_field - recipients_element = browser.find_element_by_css_selector(css_selector) - recipients_element.find_element_by_css_selector('.tt-input').send_keys(to_type) - wait_until_element_is_visible_by_locator(context, (By.CSS_SELECTOR, '.tt-dropdown-menu div div')) - browser.find_element_by_css_selector('.tt-dropdown-menu div div').click() - - -@given("for the '{recipients_field}' field I enter '{to_type}'") +@when("for the '{recipients_field}' field I enter '{to_type}'") def enter_address_impl(context, recipients_field, to_type): _enter_recipient(context, recipients_field, to_type + "\n") -@then("for the '{recipients_field}' field I type '{to_type}' and chose the first contact that shows") +@when("for the '{recipients_field}' field I type '{to_type}' and chose the first contact that shows") def choose_impl(context, recipients_field, to_type): _enter_recipient(context, recipients_field, to_type) sleep(1) find_element_by_css_selector(context, '.tt-dropdown-menu div div').click() -@given('I save the draft') +@when('I save the draft') def save_impl(context): context.browser.find_element_by_id('draft-button').click() diff --git a/service/test/functional/features/steps/mail_list.py b/service/test/functional/features/steps/mail_list.py index 6a764568..4122f065 100644 --- a/service/test/functional/features/steps/mail_list.py +++ b/service/test/functional/features/steps/mail_list.py @@ -54,7 +54,7 @@ def impl(context, tag): context.execute_steps(u'When I open the first mail in the mail list') -@then('I open the mail I previously tagged') +@when('I open the mail I previously tagged') def impl(context): open_current_mail(context) @@ -68,3 +68,9 @@ def impl(context): @then('the deleted mail is there') def impl(context): check_current_mail_is_visible(context) + + +@given('I have mails') +def impl(context): + elements = wait_until_elements_are_visible_by_locator(context, (By.XPATH, '//*[@id="mail-list"]//a')) + assert len(elements) > 0 diff --git a/service/test/functional/features/steps/mail_view.py b/service/test/functional/features/steps/mail_view.py index 46e01515..98591aa4 100644 --- a/service/test/functional/features/steps/mail_view.py +++ b/service/test/functional/features/steps/mail_view.py @@ -49,7 +49,7 @@ def impl(context, tag): wait_until_element_is_visible_by_locator(context, (By.XPATH, '//li[@data-tag="%s"]' % tag)) -@then('I reply to it') +@when('I reply to it') def impl(context): click_button(context, 'Reply') click_button(context, 'Send') @@ -73,20 +73,20 @@ def impl(context): assert_that(e.text, equal_to('Your message was moved to trash!')) -@then('I choose to forward this mail') +@when('I choose to forward this mail') def impl(context): wait_until_button_is_visible(context, 'Forward') click_button(context, 'Forward') -@then('I forward this mail') +@when('I forward this mail') def impl(context): - context.execute_steps(u'Given I save the draft') # FIXME: this won't be necessary after #89 is done + context.execute_steps(u'When I save the draft') # FIXME: this won't be necessary after #89 is done wait_until_button_is_visible(context, 'Send') click_button(context, 'Send') -@then('I remove all tags') +@when('I remove all tags') def impl(context): e = find_element_by_css_selector(context, '.tagsArea') tags = e.find_elements_by_css_selector('.tag') @@ -95,7 +95,7 @@ def impl(context): tag.click() -@then('I choose to trash') +@when('I choose to trash') def impl(context): context.browser.execute_script("$('button#view-more-actions').click()") click_button(context, 'Delete this message', 'span') diff --git a/service/test/functional/features/steps/tag_list.py b/service/test/functional/features/steps/tag_list.py index c50387f0..348b121a 100644 --- a/service/test/functional/features/steps/tag_list.py +++ b/service/test/functional/features/steps/tag_list.py @@ -22,27 +22,24 @@ def click_first_element_with_class(context, classname): def is_side_nax_expanded(context): - return context.browser.find_elements_by_class_name('content')[0].get_attribute('class').count(u'move-right') == 1 + e = context.browser.find_elements_by_class_name('content')[0].get_attribute('class').count(u'move-right') == 1 + return e -def ensure_side_nav_is_expanded(context): +def expand_side_nav(context): if is_side_nax_expanded(context): return toggle = context.browser.find_elements_by_class_name('side-nav-toggle')[0] toggle.click() - wait = WebDriverWait(context, 5) - wait.until(is_side_nax_expanded) - @when('I select the tag \'{tag}\'') def impl(context, tag): wait_for_user_alert_to_disapear(context) + expand_side_nav(context) - ensure_side_nav_is_expanded(context) - - wait_until_element_is_visible_by_locator(context, (By.ID, 'tag-%s' % tag.lower()), 20) + wait_until_element_is_visible_by_locator(context, (By.ID, 'tag-%s' % tag), 20) e = find_element_by_id(context, 'tag-%s' % tag.lower()) e.click() diff --git a/service/test/functional/features/tag_and_reply.feature b/service/test/functional/features/tag_and_reply.feature index 8fe4cf84..450cb92d 100644 --- a/service/test/functional/features/tag_and_reply.feature +++ b/service/test/functional/features/tag_and_reply.feature @@ -14,14 +14,17 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see . -Feature: tagging and replying +Feature: Tag and reply + As a user of Pixelated + I want to tag my emails + So that I can easily find them Scenario: User tags a mail, replies to it then checks that mail is in the right tag Given I have a mail in my inbox When I open the first mail in the 'inbox' When I add the tag 'website' to that mail Then I see that mail under the 'website' tag - And I open the mail I previously tagged + When I open the mail I previously tagged And I reply to it When I select the tag 'sent' Then I see the mail I sent -- cgit v1.2.3