Permalink
Browse files

Added two working end-to-end acceptance test scenarios

  • Loading branch information...
1 parent 03fbead commit 9851eaa94ec4151e7fd3b754195fa9e7da71a14c @alisterscott alisterscott committed Mar 1, 2012
View
@@ -4,3 +4,6 @@ log/*.log
tmp/**/*
.idea
*.swp
+acceptance/lib/config/*.yml
+acceptance/results.html
+dump.rdb
View
@@ -13,6 +13,9 @@ gem 'heroku'
group :test, :development do
gem "rspec-rails", "~> 2.4"
- gem "shoulda"
- gem "taps"
-end
+ gem "shoulda"
+ gem "taps"
+ gem "cucumber"
+ gem "watir-webdriver"
+ gem "watir-page-helper"
+end
View
@@ -31,15 +31,27 @@ GEM
addressable (2.2.6)
arel (2.0.10)
bcrypt-ruby (2.1.4)
+ bond (0.4.1)
builder (2.1.2)
+ childprocess (0.3.1)
+ ffi (~> 1.0.6)
crack (0.1.8)
crummy (1.2)
+ cucumber (1.1.9)
+ builder (>= 2.1.2)
+ diff-lcs (>= 1.1.2)
+ gherkin (~> 2.9.0)
+ json (>= 1.4.6)
+ term-ansicolor (>= 1.0.6)
devise (1.1.9)
bcrypt-ruby (~> 2.1.2)
warden (~> 1.0.2)
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
+ ffi (1.0.11)
+ gherkin (2.9.0)
+ json (>= 1.4.6)
heroku (2.18.1)
launchy (>= 0.3.2)
rest-client (~> 1.6.1)
@@ -48,6 +60,7 @@ GEM
httparty (0.7.8)
crack (= 0.1.8)
i18n (0.5.0)
+ json (1.6.5)
launchy (2.0.5)
addressable (~> 2.2.6)
mail (2.2.19)
@@ -56,6 +69,7 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
+ multi_json (1.0.4)
oauth (0.4.5)
polyglot (0.3.1)
rack (1.2.3)
@@ -85,6 +99,8 @@ GEM
rforce (0.6)
builder (~> 2.0)
oauth (~> 0.4)
+ ripl (0.6.2)
+ bond (~> 0.4.0)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
@@ -99,6 +115,11 @@ GEM
railties (~> 3.0)
rspec (~> 2.6.0)
rubyzip (0.9.5)
+ selenium-webdriver (2.19.0)
+ childprocess (>= 0.2.5)
+ ffi (~> 1.0.9)
+ multi_json (~> 1.0.4)
+ rubyzip
sequel (3.20.0)
shoulda (2.11.3)
sinatra (1.0)
@@ -119,12 +140,18 @@ GEM
tzinfo (0.3.29)
warden (1.0.4)
rack (>= 1.0)
+ watir-page-helper (1.0.0)
+ ripl
+ watir-webdriver
+ watir-webdriver (0.5.3)
+ selenium-webdriver (>= 2.12.0)
PLATFORMS
ruby
DEPENDENCIES
crummy
+ cucumber
devise (~> 1.1.7)
heroku
httparty
@@ -135,3 +162,5 @@ DEPENDENCIES
shoulda
sqlite3-ruby
taps
+ watir-page-helper
+ watir-webdriver
View
@@ -0,0 +1,2 @@
+default: -r features --tags ~@wip --color --format pretty --format html -o results.html
+wip: -r features --tags @wip --color --format pretty --format html -o results.html
@@ -0,0 +1,14 @@
+Feature: Camfed Surveys
+
+Scenario: Find a test survey in EPISurveyor, make sure it appears in Camfed, then delete it in Camfed
+ Given I am logged into EPISurveyor
+ And there is a 'test_form' survey in EPISurveyor
+
+ Given I am logged into Camfed
+ And there is no 'test_form' survey in Camfed
+
+ When I refresh the surveys list in Camfed
+ Then I should see the 'test_form' survey in Camfed
+
+ When I delete the 'test_form' survey in Camfed
+ Then I should not see the 'test_form' survey in Camfed
@@ -0,0 +1,7 @@
+Feature: Salesforce Objects
+
+Scenario: Enable a Salesforce object to be used in Camfed
+ Given I am logged into Camfed
+ And the 'School' Salesforce object is disabled
+ When I enabled the 'School' Salesforce object
+ Then the 'School' Salesforce object is enabled
@@ -0,0 +1,55 @@
+Given /^I am logged into Camfed$/ do
+ visit :camfed_signin_page do |page|
+ page.signin_to_camfed
+ end
+end
+
+Given /^there is no '(.+)' survey in Camfed$/ do |survey_name|
+ on :camfed_surveys_page do |page|
+ page.delete_survey(survey_name) if page.contains_survey?(survey_name)
+ end
+end
+
+When /^I refresh the surveys list in Camfed$/ do
+ on :camfed_surveys_page do |page|
+ page.refresh_surveys
+ end
+end
+
+When /^I delete the '(.+)' survey in Camfed$/ do |survey_name|
+ on :camfed_surveys_page do |page|
+ page.delete_survey(survey_name)
+ end
+end
+
+Then /^I should see the '(.+)' survey in Camfed$/ do |survey_name|
+ on :camfed_surveys_page do |page|
+ page.contains_survey?(survey_name).should be_true
+ end
+end
+
+Then /^I should not see the '(.+)' survey in Camfed$/ do |survey_name|
+ on :camfed_surveys_page do |page|
+ page.contains_survey?(survey_name).should be_false
+ end
+end
+
+Given /^the '(.+)' Salesforce object is disabled$/ do |name|
+ visit :camfed_salesforce_objects_page do |page|
+ page.disable_salesforce_object name
+ page.notice.should == "Successfully disabled #{name}"
+ end
+end
+
+When /^I enabled the '(.+)' Salesforce object$/ do |name|
+ visit :camfed_salesforce_objects_page do |page|
+ page.enable_salesforce_object name
+ page.notice.should == "Successfully enabled #{name}"
+ end
+end
+
+Then /^the '(.+)' Salesforce object is enabled$/ do |name|
+ visit :camfed_salesforce_objects_page do |page|
+ page.disable_salesforce_object_link(name).should exist
+ end
+end
@@ -0,0 +1,12 @@
+Given /^there is a '(.+)' survey in EPISurveyor$/ do |survey_name|
+ on :epi_surveyor_dashboard_page do |page|
+ page.upload_file(EpiSurveyor::create_survey_file(survey_name)) unless page.surveys.include?(survey_name)
+ page.surveys.should include survey_name
+ end
+end
+
+Given /^I am logged into EPISurveyor$/ do
+ visit :epi_surveyor_home_page do |page|
+ page.login_to_epi
+ end
+end
@@ -0,0 +1,26 @@
+$: << File.dirname(__FILE__)+'/../../lib'
+require 'epi_surveyor'
+
+require 'watir-webdriver'
+require 'watir-webdriver/extensions/alerts'
+require 'watir-page-helper/commands'
+
+World WatirPageHelper::Commands
+
+ENVIRONMENT = (ENV['ENVIRONMENT'] || 'local').to_sym
+raise "You need to create a configuration file named '#{ENVIRONMENT}.yml' under lib/config" unless File.exists? "#{File.dirname(__FILE__)}/../../lib/config/#{ENVIRONMENT}.yml"
+
+require 'env_config'
+World EpiSurveyor
+
+World EnvConfig
+
+WatirPageHelper.create
+
+After do
+ WatirPageHelper.browser.cookies.clear
+end
+
+at_exit do
+ WatirPageHelper.close
+end
@@ -0,0 +1,12 @@
+:camfed:
+ :url: http://localhost:3000/
+ :username: admin@example.com
+ :password: admin123
+:epi:
+ :url: http://www.episurveyor.org/
+ :username:
+ :password:
+:salesforce:
+ :url: https://test.salesforce.com/
+ :username:
+ :password:
@@ -0,0 +1,18 @@
+require 'yaml'
+
+module EnvConfig
+ @@config = YAML::load_file "#{File.dirname(__FILE__)}/config/#{ENVIRONMENT}.yml"
+
+ def self.get parent, child
+ parent = get_sub_tree @@config, parent
+ return get_sub_tree parent, child
+ end
+
+ private
+
+ def self.get_sub_tree root, item
+ sub_tree = root[item.to_sym]
+ raise "Could not locate '#{item}' in YAML config: '#{root}'" if sub_tree.nil?
+ sub_tree
+ end
+end
@@ -0,0 +1,15 @@
+module EpiSurveyor
+ def self.create_survey_file survey_name
+ source_directory_path = "#{File.dirname(__FILE__)}/input_files"
+ source_file_name = 'test_form'
+ source_file_extension = '.svy'
+ source_file_path = "#{source_directory_path}/#{source_file_name}#{source_file_extension}"
+ required_file_path = "#{source_directory_path}/#{survey_name}#{source_file_extension}"
+ FileUtils.cp(source_file_path, required_file_path) unless required_file_path == source_file_path
+ return required_file_path
+ end
+
+ def self.destroy_survey_file file_path
+ FileUtils.rm file_path, :force => true
+ end
+end
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><survey name="Another_Test_Form" version="1.0"><Survey Type="Normal"/><object type="info" ><name></name><prompt>Test form to be used in Brisbane codejam!</prompt><uniqueKeyFieldName></uniqueKeyFieldName><style></style><required>false</required><autofill>false</autofill><isUnique>false</isUnique><byIndex></byIndex><optionsListID></optionsListID><optionSet></optionSet><skipLogic enabled="false" operator="-1" operand="-1" skipTo="-1"/><Childsurvey></Childsurvey></object><object type="date" ><name>Date</name><prompt>Date Today</prompt><uniqueKeyFieldName></uniqueKeyFieldName><style>MDY</style><required>false</required><autofill>false</autofill><isUnique>false</isUnique><byIndex></byIndex><optionsListID></optionsListID><optionSet></optionSet><skipLogic enabled="false" operator="-1" operand="-1" skipTo="-1"/><Childsurvey></Childsurvey></object><object type="option" ><name>District</name><prompt>District you are entering data for</prompt><uniqueKeyFieldName></uniqueKeyFieldName><style>radio</style><required>true</required><autofill>false</autofill><isUnique>false</isUnique><byIndex>true</byIndex><optionsListID></optionsListID><optionSet>Bole~~Nyanga~~Chikomba West</optionSet><skipLogic enabled="false" operator="0" operand="-1" skipTo="-1"/><Childsurvey></Childsurvey></object><object type="option" ><name>School</name><prompt>What school are you entering data for?</prompt><uniqueKeyFieldName></uniqueKeyFieldName><style>radio</style><required>false</required><autofill>false</autofill><isUnique>false</isUnique><byIndex>true</byIndex><optionsListID></optionsListID><optionSet>Bole Primary~~Bole JHS~~Bole SHS</optionSet><skipLogic enabled="false" operator="0" operand="-1" skipTo="-1"/><Childsurvey></Childsurvey></object><object type="option" ><name>Aina_ya_Shule</name><prompt>What type of school is it?</prompt><uniqueKeyFieldName></uniqueKeyFieldName><style>radio</style><required>false</required><autofill>false</autofill><isUnique>false</isUnique><byIndex>true</byIndex><optionsListID></optionsListID><optionSet>Primary~~Secondary~~High</optionSet><skipLogic enabled="false" operator="0" operand="-1" skipTo="-1"/><Childsurvey></Childsurvey></object><object type="option" ><name>Term</name><prompt>What term is it?</prompt><uniqueKeyFieldName></uniqueKeyFieldName><style>radio</style><required>false</required><autofill>false</autofill><isUnique>false</isUnique><byIndex>true</byIndex><optionsListID></optionsListID><optionSet>Term 1~~Term 2~~Term 3</optionSet><skipLogic enabled="false" operator="0" operand="-1" skipTo="-1"/><Childsurvey></Childsurvey></object><object type="text" ><name>Teacher_Mentor</name><prompt>Name of Teacher</prompt><uniqueKeyFieldName></uniqueKeyFieldName><style>alpha</style><required>false</required><autofill>false</autofill><isUnique>false</isUnique><byIndex></byIndex><optionsListID></optionsListID><optionSet></optionSet><skipLogic enabled="false" operator="-1" operand="-1" skipTo="-1"/><Childsurvey></Childsurvey></object><object type="text" ><name>Members_SMC_M</name><prompt>How many male members on the School Management Committee?</prompt><uniqueKeyFieldName></uniqueKeyFieldName><style>numeric</style><required>false</required><autofill>false</autofill><isUnique>false</isUnique><byIndex></byIndex><optionsListID></optionsListID><optionSet></optionSet><skipLogic enabled="false" operator="0" operand="-1" skipTo="-1"/><Childsurvey></Childsurvey></object><object type="text" ><name>Members_SMC_F</name><prompt>How many female members on the School Management Committee?</prompt><uniqueKeyFieldName></uniqueKeyFieldName><style>numeric</style><required>false</required><autofill>false</autofill><isUnique>false</isUnique><byIndex></byIndex><optionsListID></optionsListID><optionSet></optionSet><skipLogic enabled="false" operator="0" operand="-1" skipTo="-1"/><Childsurvey></Childsurvey></object><object type="option" ><name>Trainings_Received</name><prompt>What trainings have been received at the school (mark all that apply)</prompt><uniqueKeyFieldName></uniqueKeyFieldName><style>check</style><required>false</required><autofill>false</autofill><isUnique>false</isUnique><byIndex>true</byIndex><optionsListID></optionsListID><optionSet>Guidance and Counselling~~Child Protection~~Community Mobilisation~~Reproductive Health~~Child Development~~Other</optionSet><skipLogic enabled="false" operator="-1" operand="-1" skipTo="-1"/><Childsurvey></Childsurvey></object><object type="info" ><name></name><prompt>Test Completed</prompt><uniqueKeyFieldName></uniqueKeyFieldName><style></style><required>false</required><autofill>false</autofill><isUnique>false</isUnique><byIndex></byIndex><optionsListID></optionsListID><optionSet></optionSet><skipLogic enabled="false" operator="-1" operand="-1" skipTo="-1"/><Childsurvey></Childsurvey></object></survey>
@@ -0,0 +1,24 @@
+require 'watir-page-helper'
+
+module WatirPageHelper::CamfedSalesforceObjectsPage
+ extend WatirPageHelper::ClassMethods
+
+ direct_url "#{EnvConfig.get :camfed, :url}/salesforce_objects"
+ div :notice, :class => 'notice'
+
+ def disable_salesforce_object_link name
+ browser.link(:text => name).parent.parent.link(:text => 'Disable')
+ end
+
+ def enable_salesforce_object_link name
+ browser.link(:text => name).parent.parent.link(:text => 'Enable')
+ end
+
+ def disable_salesforce_object name
+ disable_salesforce_object_link(name).click if disable_salesforce_object_link(name).exists?
+ end
+
+ def enable_salesforce_object name
+ enable_salesforce_object_link(name).click if enable_salesforce_object_link(name).exists?
+ end
+end
@@ -0,0 +1,19 @@
+require 'watir-page-helper'
+
+module WatirPageHelper::CamfedSigninPage
+ extend WatirPageHelper::ClassMethods
+
+ direct_url "#{EnvConfig.get :camfed, :url}/users/sign_in"
+
+ text_field :email, :id => 'user_email'
+ text_field :password, :id => 'user_password'
+ button :signin, :id => 'user_submit'
+
+ def signin_to_camfed
+ if self.email_text_field.exists?
+ self.email = EnvConfig.get :camfed, :username
+ self.password = EnvConfig.get :camfed, :password
+ signin
+ end
+ end
+end
@@ -0,0 +1,21 @@
+require 'watir-page-helper'
+
+module WatirPageHelper::CamfedSurveysPage
+ extend WatirPageHelper::ClassMethods
+
+ expected_title 'Camfed - Surveys'
+
+ link :refresh_surveys, :text => 'Refresh Surveys List from EpiSurveyor'
+ button :delete_selected, :value => 'Delete Selected'
+
+ def contains_survey? survey_name
+ browser.span(:text => survey_name).exists?
+ end
+
+ def delete_survey survey_name
+ browser.span(:text => survey_name).parent.checkbox.click
+ browser.confirm(true) do
+ delete_selected
+ end
+ end
+end
@@ -0,0 +1,34 @@
+require 'watir-page-helper'
+
+module WatirPageHelper::EpiSurveyorDashboardPage
+ extend WatirPageHelper::ClassMethods
+
+ direct_url "#{EnvConfig.get :epi, :url}/dashboard/index"
+ expected_title "DataDyne's EpiSurveyor: Dashboard"
+
+ button :import, :id => 'import'
+ button :delete, :id => 'delete'
+ file_field :file_location, :name => 'uploadsurveyfile'
+ button :upload, :text => 'Upload'
+ li :upload_ok, :text => 'Form uploaded successfully'
+
+ def upload_file file_path
+ import
+ self.file_location = file_path
+ upload
+ end
+
+ def surveys
+ browser.trs(:class => 'row').collect {|tr| tr.td.text}
+ end
+
+ def survey_td survey_name
+ browser.td(:text => survey_name)
+ end
+
+ def delete_survey
+ browser.confirm(true) do
+ delete
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 9851eaa

Please sign in to comment.