Skip to content

Commit

Permalink
Merge e74185e into 9374fcc
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanjenx committed Sep 26, 2018
2 parents 9374fcc + e74185e commit e47d792
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .behaverc
@@ -0,0 +1,2 @@
[behave]
paths=cairis/automatedTest
12 changes: 10 additions & 2 deletions .travis.yml
Expand Up @@ -22,16 +22,24 @@ addons:
- docbook-utils
- libxml2-dev
- libxslt1-dev

- google-chrome-stable

env:
- PYTHONPATH=. CAIRIS_SRC=$PYTHONPATH/cairis CAIRIS_CFG=cairis_travis.cnf XML_CATALOG_FILES=$CAIRIS_SRC/config/catalog
- PYTHONPATH=. CAIRIS_SRC=$PYTHONPATH/cairis CAIRIS_CFG=cairis_travis.cnf XML_CATALOG_FILES=$CAIRIS_SRC/config/catalog
$CAIRIS_CFG_DIR=./travisConfig

install:
- pip install -r test_requirements.txt
- pip install -r requirements.txt

before_script:
- latestChromeDriver=$(curl https://chromedriver.storage.googleapis.com/LATEST_RELEASE)
- wget https://chromedriver.storage.googleapis.com/$latestChromeDriver/chromedriver_linux64.zip
- sudo unzip chromedriver_linux64 -d /usr/bin
- sudo chmod a+x /usr/bin/chromedriver

script:
- behave
- py.test cairis/test --doctest-modules -v --cov cairis/core cairis/daemon cairis/controllers
cairis/data cairis/tools --cov-report term-missing

Expand Down
12 changes: 12 additions & 0 deletions cairis/automatedTest/environment.py
@@ -0,0 +1,12 @@
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

def before_scenario(context, scenario):
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=1920x1080")
browser = webdriver.Chrome(chrome_options=chrome_options, executable_path="chromedriver")
context.browser = browser

def after_scenario(context, scenario):
context.browser.quit()
25 changes: 25 additions & 0 deletions cairis/automatedTest/features/login.feature
@@ -0,0 +1,25 @@
Feature: Login and Logout
In order to secure CAIRIS
As a Product Owner
I want the application to be secured with a user name and password

Scenario: Successful Login
Given I have navigated to the CAIRIS web application
When I supply valid credentials
Then I am granted access to the application

Scenario Outline: Unsuccessful Login
Given I have navigated to the CAIRIS web application
When I supply <username> and <password>
Then I am refused access to the application

Examples:
| username | password |
| test | incorrect |
| incorrect | test |
| incorrect | incorrect |

Scenario: Logout
Given I have successfully authenticated with CAIRIS
When I click logout
Then I am returned to the landing page
63 changes: 63 additions & 0 deletions cairis/automatedTest/steps/GenericSteps.py
@@ -0,0 +1,63 @@
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import ElementNotVisibleException

validUsername = 'test'
validPassword = 'test'

def NavigateToApp(context):
context.browser.get("https://demo.cairis.org")

def EnterValidCredentials(context):
EnterCredentials(context, validUsername, validPassword)
ClickButtonWithId(context, 'submit')

def EnterCredentials(context, username, password):
usernameEl = FindElementById(context, 'email')
passwordEl = FindElementById(context, 'password')

EnterText(usernameEl, username)
EnterText(passwordEl, password)

def ClickButtonWithId(context, id):
button = FindElementById(context, id)
button.click()

def FindElementById(context, id):
return context.browser.find_element_by_id(id)

def EnterText(element, text):
element.send_keys(text)

def ElementWithIdInvisible(context, id):
elelement = FindElementById(context, id);
assert element.is_displayed is False

def WaitForSpinningWheelOfDoom(context):
spinningWheelOfDoom = 'displayWrapper'
WaitForInvisibleByClass(context, 'divLoading')

def WaitForVisibleByClass(context, className):
return WaitForVisibleStateByClass(context, className, True)

def WaitForInvisibleByClass(context, className):
return WaitForVisibleStateByClass(context, className, False)

def WaitForVisibleStateByClass(context, className, displayState):
if(displayState == True):
element = WebDriverWait(context.browser, 30, 0.5, (ElementNotVisibleException)).until(lambda x: x.find_element_by_class_name(className).is_displayed())
else:
element = WebDriverWait(context.browser, 30, 0.5, (ElementNotVisibleException)).until_not(lambda x: x.find_element_by_class_name(className).is_displayed())
return element

def WaitForVisibleById(context, id):
return WaitForVisibleStateById(context, id, True)

def WaitForInvisibleById(context, id):
return WaitForVisibleStateById(context, id, False)

def WaitForVisibleStateById(context, id, displayState):
if(displayState == True):
element = WebDriverWait(context.browser, 30, 0.5, (ElementNotVisibleException)).until(lambda x: x.find_element_by_id(id).is_displayed())
else:
element = WebDriverWait(context.browser, 30, 0.5, (ElementNotVisibleException)).until_not(lambda x: x.find_element_by_id(id).is_displayed())
return element
47 changes: 47 additions & 0 deletions cairis/automatedTest/steps/LoginSteps.py
@@ -0,0 +1,47 @@
from behave import *
from GenericSteps import *

@given('I have navigated to the CAIRIS web application')
def step_impl(context):
NavigateToApp(context)

@when('I supply valid credentials')
def step_impl(context):
EnterValidCredentials(context)

@then('I am granted access to the application')
def step_impl(context):
LoggedIn(context)

@when('I supply {username} and {password}')
def step_impl(context, username, password):
EnterCredentials(context, username, password)
ClickButtonWithId(context, 'submit')

@then('I am refused access to the application')
def step_impl(context):
assert OnLandingPage(context) is True

@given('I have successfully authenticated with CAIRIS')
def step_impl(context):
NavigateToApp(context)
EnterValidCredentials(context)
LoggedIn(context)

@when('I click logout')
def step_impl(context):
logout = context.browser.find_element_by_id('logoutClick')
logout.click()

@then('I am returned to the landing page')
def step_impl(context):
assert OnLandingPage(context) is True

def LoggedIn(context):
WaitForSpinningWheelOfDoom(context)
ClickButtonWithId(context, 'homeClick')

def OnLandingPage(context):
WaitForVisibleById(context, 'email')
WaitForVisibleById(context, 'password')
return True
2 changes: 2 additions & 0 deletions test_requirements.txt
Expand Up @@ -2,3 +2,5 @@ python-coveralls
codecov
#httpretty
git+https://github.com/melor/HTTPretty.git@py33
selenium
behave

0 comments on commit e47d792

Please sign in to comment.