Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behave acceptance tests #170

Merged
merged 2 commits into from
Apr 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ sudo: false
python:
- "2.7"

addons:
apt:
packages:
- xvfb
- firefox

env:
global:
- COLAB_SETTINGS=tests/colab_settings.py

install:
- pip install coveralls flake8 behave behave_django
- pip install coveralls flake8 behave behave_django selenium
- pip install .

script:
- python setup.py test
- colab-admin behave
- xvfb-run -a colab-admin behave --format=progress
- flake8 colab

after_success:
Expand Down
49 changes: 49 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,52 @@ Follow the steps below:
.. code-block::

python setup.py test

How to run Acceptance Tests
---------------------------

Follow the steps below to run the acceptance tests.

1- Log in virtual machine:

1.1 - To run without opening a graphic interface

.. code-block::

vagrant ssh

1.2 - To run opening a graphic interface

.. code-block::

vagrant ssh -- -X

2- Use colab virtualenv:

.. code-block::

workon colab

3- Enter into colab source code directory:

.. code-block::

cd /vagrant

4- Run all the acceptance tests with:

.. code-block::

COLAB_SETTINGS=tests/colab_settings.py colab-admin behave

4.1 To run without opening a browser:
.. code-block::

COLAB_SETTINGS=tests/colab_settings.py xvfb-run -a colab-admin behave

4.2 To run a specific feature:

.. code-block::

COLAB_SETTINGS=tests/colab_settings.py colab-admin behave /path/to/features/file.feature

11 changes: 11 additions & 0 deletions features/environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from selenium import webdriver


def before_feature(context, feature):
context.driver = webdriver.Firefox()
context.driver.set_window_size(1000, 600)
context.driver.implicitly_wait(5)


def after_feature(context, feature):
context.driver.quit()
79 changes: 79 additions & 0 deletions features/profile_edition.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

Feature: User Profile Edition
In order to update my personal information
As an User
I want to be able to edit my profile

Background:
Given I am logged in as "john"

Scenario: Edit profile without required information
When I open the user menu
When I click in "My Profile"
When I click in "Edit Profile"
When I fill " " in "id_first_name" field
When I fill " " in "id_last_name" field
When I click in "Update" button
Then The field "id_first_name" should have an error
Then The field "id_last_name" should have an error

Scenario: Edit profile with valid information
When I open the user menu
When I click in "My Profile"
When I click in "Edit Profile"
When I fill "John" in "id_first_name" field
When I fill "McClaine" in "id_last_name" field
When I fill "Die Hard" in "id_institution" field
When I fill "police officer" in "id_role" field
When I fill "diehard.com" in "id_webpage" field
When I fill "I am tough." in "id_bio" field
When I click in "Update" button
Then I should see "John McClaine" in "user-profile"
Then I should see "Die Hard" in "user-profile"
Then I should see "police officer" in "user-profile"
Then I should see "I am tough." in "user-profile"
When I click in "Edit Profile"
Then I should see "diehard.com" in "id_webpage"

Scenario: Change password with wrong current password
When I open the user menu
When I click in "My Profile"
When I click in "Edit Profile"
When I click in "Change Password"
When I fill "wrong" in "id_old_password" field
When I fill "newpassword" in "id_new_password1" field
When I fill "newpassword" in "id_new_password2" field
When I click in "Change my password" button
Then The field "id_old_password" should have an error

Scenario: Change password with wrong password confirmation
When I open the user menu
When I click in "My Profile"
When I click in "Edit Profile"
When I click in "Change Password"
When I fill "john" in "id_old_password" field
When I fill "newpassword" in "id_new_password1" field
When I fill "differentpassword" in "id_new_password2" field
When I click in "Change my password" button
Then The field "id_new_password2" should have an error

Scenario: Change password with success
When I open the user menu
When I click in "My Profile"
When I click in "Edit Profile"
When I click in "Change Password"
When I fill "john" in "id_old_password" field
When I fill "newpassword" in "id_new_password1" field
When I fill "newpassword" in "id_new_password2" field
When I click in "Change my password" button
When I open the user menu
When I click in "My Profile"
When I open the user menu
When I click in "Logout"
When I click in "Acesso "
When I click in "Login"
When I fill "john" in "id_username" field
When I fill "newpassword" in "id_password" field
When I click in "Acesso "
When I click in "Login" button
Then The browser URL should be "/dashboard"
9 changes: 0 additions & 9 deletions features/steps/home.py

This file was deleted.

38 changes: 38 additions & 0 deletions features/steps/user_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from colab.accounts.models import User
from behave import given, when


@given(u'The user "{username}" with the password "{password}" is "{status}"')
def create_user(context, username, password, status):
user = User()
user.username = username
user.set_password(password)
user.email = "usertest@colab.com.br"
user.id = 1
user.first_name = "USERtestCoLaB"
user.last_name = "COLAB"
user.needs_update = False
if status == "active":
user.is_active = True
else:
user.is_active = False
user.save()


@given(u'I am logged in as "{username}"')
def step_impl(context, username):
context.execute_steps('''
When I access the URL "/"
When I click in "Acesso "
When I click in "Login"
Given The user "%s" with the password "%s" is "%s"
When I fill "%s" in "id_username" field
When I fill "%s" in "id_password" field
When I click in "Login" button
''' % (username, username, 'active', username, username))


@when(u'I open the user menu')
def step_impl(context):
dropdown = context.driver.find_element_by_id('user-menu')
dropdown.find_element_by_xpath('.//a').click()
55 changes: 55 additions & 0 deletions features/steps/web_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from selenium.webdriver.common.keys import Keys
from behave import when, then


@when(u'I access the URL "{url}"')
def step_impl(context, url):
context.driver.get(context.base_url + "/")


@when(u'I click in "{link}"')
def step_impl(context, link):
context.driver.find_element_by_xpath("//a[contains(., '%s')]" %
link).click()


@when(u'I click in "{button_value}" button')
def step_impl(context, button_value):
context.driver.find_element_by_xpath(
"//input[@value='%s']|//button[.='%s']" %
(button_value, button_value)).click()


@when(u'I fill "{text}" in "{field_id}" field')
def step_impl(context, text, field_id):
field = context.driver.find_element_by_id(field_id)
field.clear()
field.send_keys(text)


@when(u'I fill "{text}" in "{field_id}" field and hit enter')
def step_impl(context, text, field_id):
field = context.driver.find_element_by_id(field_id)
field.clear()
field.send_keys(text)
field.send_keys(Keys.RETURN)


@then(u'The field "{field_id}" should have an error')
def step_impl(context, field_id):
field = context.driver.find_element_by_id(field_id)
container = field.find_element_by_xpath('..')
classes = container.get_attribute('class')
assert 'has-error' in classes


@then(u'I should see "{content}" in "{element_id}"')
def step_impl(context, content, element_id):
element = context.driver.find_element_by_id(element_id)
assert (content in element.text) or \
(content in element.get_attribute("value"))


@then(u'The browser URL should be "{url}"')
def step_impl(context, url):
assert context.driver.current_url.endswith(url)
97 changes: 97 additions & 0 deletions features/user_sign_in.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

Feature: User sign in
In order to be able to access the system funcionalities
As an User
I want to be able to sign in

# Valid scenarios

Scenario: Clicking the login button and displaying login page
When I access the URL "/"
When I click in "Acesso "
When I click in "Login"
Then The browser URL should be "/account/login"

Scenario: Sign in with a valid user
Given The user "colabtest" with the password "colabtest" is "active"
When I access the URL "/"
When I click in "Acesso "
When I click in "Login"
When I fill "colabtest" in "id_username" field
When I fill "colabtest" in "id_password" field
When I click in "Login" button
Then The browser URL should be "/dashboard"

Scenario: Sign in with a valid user by hitting ENTER
Given The user "colabtest" with the password "colabtest" is "active"
When I access the URL "/"
When I click in "Acesso "
When I click in "Login"
When I fill "colabtest" in "id_username" field
When I fill "colabtest" in "id_password" field and hit enter
Then The browser URL should be "/dashboard"

Scenario: Sign in with a valid user and displaying user profile
Given The user "colabtest" with the password "colabtest" is "active"
When I access the URL "/"
When I click in "Acesso "
When I click in "Login"
When I fill "colabtest" in "id_username" field
When I fill "colabtest" in "id_password" field
When I click in "Login" button
Then The browser URL should be "/dashboard"
When I open the user menu
Then I should see "USERtestCoLaB COLAB" in "user-menu"
Then I should see "usertest@colab.com.br" in "user-menu"


# Invalid scenarios

Scenario: Sign in with an unregistered user
When I access the URL "/"
When I click in "Acesso "
When I click in "Login"
When I fill "unregistered" in "id_username" field
When I fill "any" in "id_password" field
When I click in "Login" button
Then The browser URL should be "/account/login"
Then I should see "Please correct the error below and try again" in "main-content"

Scenario: Sign in with a inactive user
Given The user "colabtest" with the password "colabtest" is "inactive"
When I access the URL "/"
When I click in "Acesso "
When I click in "Login"
When I fill "colabtest" in "id_username" field
When I fill "colabtest" in "id_password" field
When I click in "Login" button
Then The browser URL should be "/account/login"
Then I should see "This account is inactive" in "main-content"

Scenario: Sign in with no user information given
When I access the URL "/"
When I click in "Acesso "
When I click in "Login"
When I click in "Login" button
Then The browser URL should be "/account/login"
Then The field "id_username" should have an error
Then The field "id_password" should have an error

Scenario: Sign in with no password given
When I access the URL "/"
When I click in "Acesso "
When I click in "Login"
When I fill "colabtest" in "id_username" field
When I click in "Login" button
Then The browser URL should be "/account/login"
Then The field "id_password" should have an error

Scenario: Sign in with no username given
When I access the URL "/"
When I click in "Acesso "
When I click in "Login"
When I fill "colabtest" in "id_password" field
When I click in "Login" button
Then The browser URL should be "/account/login"
Then The field "id_username" should have an error