Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ee0b5b7
first test
AllisonQ Jul 14, 2015
9825ae2
Merge pull request #1 from AllisonQ/training_branch
Lorennie Jul 15, 2015
fccd08a
update test
AllisonQ Aug 27, 2015
604bdc8
Merge pull request #2 from AllisonQ/training_branch
AllisonQ Aug 27, 2015
e3bf9d4
added test and comments
AllisonQ Sep 9, 2015
64eb22e
tidying up code
AllisonQ Sep 9, 2015
f03c983
add further test
AllisonQ Sep 9, 2015
f1b1416
assignment 1 tests
AllisonQ Oct 9, 2015
c26af84
commiting docs
AllisonQ Oct 12, 2015
1408601
add word.docx
AllisonQ Oct 12, 2015
48664df
added JSON feature
AllisonQ Nov 17, 2015
e4a4782
Merge pull request #3 from AllisonQ/training_branch
AllisonQ Nov 17, 2015
1df50cd
created step definitions for testing JSON of GR504812
AllisonQ Nov 17, 2015
0d15853
tidying steps
AllisonQ Nov 17, 2015
2d7dd86
Merge pull request #4 from AllisonQ/training_branch
AllisonQ Nov 26, 2015
cc9fff5
added testing differences txt file
AllisonQ Nov 29, 2015
39fcfa7
Update get_json.rb
Lorennie Nov 30, 2015
8d5040b
Update get_json.rb
Lorennie Nov 30, 2015
93c7527
Update get_json.rb
Lorennie Nov 30, 2015
c64e2b0
Merge pull request #5 from AllisonQ/Lorennie-patch-1
Lorennie Dec 4, 2015
8bd9be8
Merge pull request #6 from AllisonQ/Lorennie-patch-2
Lorennie Dec 4, 2015
31ad264
Merge pull request #7 from AllisonQ/training_branch
Lorennie Dec 4, 2015
991f797
jenkins commented out
AllisonQ Dec 9, 2015
e763ff4
Merge pull request #8 from AllisonQ/training_branch
AllisonQ Dec 9, 2015
96ba1d2
add features and step definitions for all 5 title numbers
AllisonQ Dec 31, 2015
4fab767
remove superceded step definition
AllisonQ Dec 31, 2015
2f49b55
Complete Difference_testing-UI_JSON.txt
AllisonQ Jan 3, 2016
2f398a1
minor adjustments to Difference testing UI JSON.txt
AllisonQ Jan 3, 2016
ec52b2a
another minor adjustments to Difference testing UI JSON.txt
AllisonQ Jan 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ home/log.txt
!.jenkins_jobs/example/builds/3

.jenkins_jobs/example/workspace/
.png
28 changes: 14 additions & 14 deletions provision
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ echo "Installing Ruby Dev Kit"
apt-get update
apt-get install -y ruby2.2 ruby2.2-dev

echo "Installing Jenkins"

wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
apt-get update
apt-get -qy install jenkins

usermod -a -G vagrant jenkins
usermod -a -G jenkins vagrant
service jenkins start
sleep 240
java -jar /vagrant/.jenkins/jenkins-cli.jar -s http://localhost:8080 install-plugin git
java -jar /vagrant/.jenkins/jenkins-cli.jar -s http://localhost:8080 install-plugin xUnit
service jenkins restart
#echo "Installing Jenkins"

# wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
# sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
# apt-get update
# apt-get -qy install jenkins
#
# usermod -a -G vagrant jenkins
# usermod -a -G jenkins vagrant
# service jenkins start
# sleep 240
# java -jar /vagrant/.jenkins/jenkins-cli.jar -s http://localhost:8080 install-plugin git
# java -jar /vagrant/.jenkins/jenkins-cli.jar -s http://localhost:8080 install-plugin xUnit
# service jenkins restart

echo "Installing git command line tools"

Expand Down
11 changes: 6 additions & 5 deletions tests/Example1/features/steps/code.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
When(/^I create a user$/) do

data = {}
data['user_name'] = 'User' + Time.new().to_i.to_s + '@example.org' # Create a random user name
data['user_name'] = 'User' + Time.new().to_i.to_s + '@example.org' #Use Time.new create to create a random user name
data['user_password'] = 'password'

result = rest_post_call('http://localhost:4567/add_user', data)
result = rest_post_call('http://localhost:4567/add_user', data) #add user
puts data
$json_result = JSON.parse(result.body)
$json_result = JSON.parse(result.body) #json_result returns status as 'User Added'
end

Then(/^the user is successfully created$/) do
expect($json_result['status']).to eq('User Added')
expect($json_result['status']).to eq('User Added') #confirms status returned is 'User Added'
puts "status " + $json_result['status'].to_s
end

When(/^I create a user which already exists$/) do
Expand All @@ -24,5 +25,5 @@
end

Then(/^the user is not created$/) do
expect($json_result['status']).to eq('User Already Exists')
expect($json_result['status']).to eq('User Already Exists') #confirms 'User Already Exists'
end
2 changes: 1 addition & 1 deletion tests/Example2/features/steps/code.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Given(/^I have a user account$/) do
$data = {}
$data['user_name'] = 'User' + Time.new().to_i.to_s + '@example.org' # Create a random user name
$data['user_name'] = 'User' + Time.new().to_i.to_s + '@example.org' #Use Time.new to create a random user name
$data['user_password'] = 'password'

rest_post_call('http://localhost:4567/add_user', $data)
Expand Down
2 changes: 2 additions & 0 deletions tests/Example2/features/support/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, inspector: true, js_errors: true)
end
require 'test/unit'
include Test::Unit::Assertions

else

Expand Down
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions tests/Example3/features/invalid_login.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature:Invalid login

Scenario: incorrect user details
Given I visit the test site
When I login using incorrect details
Then an error message is displayed

Scenario: enter correct new user and login in without password
Given I have a user account
When I visit the test site
And login with username but no password
Then I receive an error message
11 changes: 11 additions & 0 deletions tests/Example3/features/lib/access_site_and_logout.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#access site
def access_login_page()
# Visit main page
visit('http://localhost:4567')
end

#Logout
def logout()
click_link ('Back to menu')
click_link ('Logout')
end
44 changes: 44 additions & 0 deletions tests/Example3/features/lib/data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#Function: improves maintainability of tests - details can be easily added to or amended
#can be called by many features

def set_details_1()
@details = Hash.new()
@details['first-name'] = "Rick"
@details['second-name'] = "Deckard"
@details['address'] = Hash.new()
@details['address']['house-number'] = "3"
@details['address']['street'] = "Tyrell Road"
@details['address']['city'] = "Plymouth"
@details['address']['postcode'] = "PL4 5AZ"
@details['sex'] = "html/body/div[1]/form/input[7]"
@details['interests'] = Hash.new()
@details['interests'][0] = "swimming"
@details['interests'][1] = "walking"
@details['interests'][2] = "cycling"
@details['car'] = Hash.new()
@details['car'][0] = "Volvo"
@details['car'][1] = "Saab"
@details['car'][2] = "Fiat"
@details['car'][3] = "Audi"
end

def set_details_2()
@details = Hash.new()
@details['first-name'] = "Allison"
@details['second-name'] = "Queen"
@details['address'] = Hash.new()
@details['address']['house-number'] = "3"
@details['address']['street'] = "High Street"
@details['address']['city'] = "Plymouth"
@details['address']['postcode'] = "PL4 7LX"
@details['sex'] = "html/body/div[1]/form/input[8]"
@details['interests'] = Hash.new()
@details['interests'][0] = "swimming"
@details['interests'][1] = "walking"
@details['interests'][2] = "cycling"
@details['car'] = Hash.new()
@details['car'][0] = "Volvo"
@details['car'][1] = "Saab"
@details['car'][2] = "Fiat"
@details['car'][3] = "Audi"
end
11 changes: 11 additions & 0 deletions tests/Example3/features/login_logout.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Login and logout

Scenario: Login to the web site and log out
Given I have a user account
And I am logged in
When I choose to logout
Then I am logged out of the system

Scenario: Access form without logging in
Given I try to access the Details Form without logging in
Then I will be prevented from accessing the website and an error message will be displayed
22 changes: 22 additions & 0 deletions tests/Example3/features/steps/invalid_login.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
When(/^I login using incorrect details$/) do
#add incorrect details ncorrect format
fill_in('username', :with => 'Incorrectuser@1234.com')
fill_in('password', :with => 'notapassword1')
click_button('Sign in')
end

Then(/^an error message is displayed$/) do
expect(page.body).to match('Unknown User')
end


When(/^login with username but no password$/) do
#enter user name only - no password
fill_in('username', :with => $data['user_name'])
click_button('Sign in')
end

Then(/^I receive an error message$/) do
#test currently fails - pop up not recognised and has no xpath - I would ask dev to amend this
expect(page.body).to match('Please fill in this field')
end
29 changes: 29 additions & 0 deletions tests/Example3/features/steps/login_logout.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Given(/^I am logged in$/) do
#use previous step code to take you fully into the application
step 'I have a user account'
step 'I visit the test site'
step 'I login using that user account and click on the Details Form'
click_button('Submit')
end

When(/^I choose to logout$/) do
#called from ../lib/access_site_and_logout.rb
logout()
end

Then(/^I am logged out of the system$/) do
expect(page.body).to have_content "Please sign in"
end

#Application can only be logged out of from initial menu - you cannot logout once inside the applcation only return to menu from final page

Given(/^I try to access the Details Form without logging in$/) do
#hit URL without going through login
visit('http://localhost:4567/form-details')
end

Then(/^I will be prevented from accessing the website and an error message will be displayed$/) do
#expect some kind of error message to be displayed as web page should only be accessible by logging on with valid username and password
expect(page).to have_text "Please enter valid user name and password" # this may not be the right response, I would have talk to dev to get find correct failure code and/or error message
#this step will fail as currently webpage can be hit directly without going through login
end
88 changes: 88 additions & 0 deletions tests/Example3/features/steps/submit_detail.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Given(/^I have a user account$/) do
$data = {}
$data['user_name'] = 'User' + Time.new().to_i.to_s + '@example.org' #Use Time.new to generate a random user name
$data['user_password'] = 'password'

rest_post_call('http://localhost:4567/add_user', $data) # add user
end

Given(/^I visit the test site$/) do
#called from ../lib/access_site_and_logout.rb
access_login_page()
end

When(/^I login using that user account and click on the Details Form$/) do
#Enter details into login screen and sign in
fill_in('username', :with => $data['user_name'])
fill_in('password', :with => $data['user_password'])
click_button('Sign in')

click_link('Details form')

end


Then(/^I can complete and submit the form with my details$/) do
#called from ../lib/data.rb to complete form details
set_details_1()

fill_in('first-name', :with => @details['first-name'])
fill_in('second-name', :with => @details['second-name'])
fill_in('house_number', :with => @details['address']['house-number'])
fill_in('street', :with => @details["address"]["street"])
fill_in('city', :with => @details["address"]["city"])
fill_in('postcode', :with => @details["address"]["postcode"])
find(@details["sex"]).click
check(@details["interests"][0])
select(@details["car"][0], :from => 'cars')
click_button('Submit')
end

Then(/^I can complete and submit the form with different details$/) do
#called from ../lib/data.rb to complete form details
set_details_2()

fill_in('first-name', :with => @details['first-name'])
fill_in('second-name', :with => @details['second-name'])
fill_in('house_number', :with => @details['address']['house-number'])
fill_in('street', :with => @details["address"]["street"])
fill_in('city', :with => @details["address"]["city"])
fill_in('postcode', :with => @details["address"]["postcode"])
find(@details["sex"]).click
check(@details["interests"][2])
select(@details["car"][3], :from => 'cars')
click_button('Submit')
end

Then(/^I confirm that the details are displayed correctly$/) do
#page is checked to see the correct text inputted in previous step is displayed on the results page
expect(page).to have_text "#{@details['first-name']} #{@details['second-name']}"
expect(page).to have_text "#{@details["address"]["house-number"]} #{@details["address"]["street"]} #{@details["address"]["city"]} #{@details["address"]["postcode"]}"
expect(page).to have_text "#{@details["car"][0]}".downcase
expect(page).to have_text "#{@details["interests"][0]}"
expect(find(:xpath, ".//*[@id='gender']/p")).to have_content "male"
end

Then(/^I confirm that the different details are displayed correctly$/) do
#page is checked to see the correct text inputted in previous step is displayed on the results page
expect(page).to have_text "#{@details['first-name']} #{@details['second-name']}"
expect(page).to have_text "#{@details["address"]["house-number"]} #{@details["address"]["street"]} #{@details["address"]["city"]} #{@details["address"]["postcode"]}"
expect(page).to have_text "#{@details["interests"][2]}"
expect(page).to have_text "#{@details["car"][3]}".downcase
expect(find(:xpath, ".//*[@id='gender']/p")).to have_content "female"
end


Then(/I submit without completing any details$/) do
click_button ('Submit')
end

Then(/^I confirm only the default values are present$/) do
#check to confirm defaults are displayed
expect(page).to have_content('volvo')
expect(page).to have_content('male')
#can also check to ensure things are not dispalyed
expect(page.body).to have_no_content('audi')
expect(page.body).to have_no_content('female')
expect(page.body).to have_no_content('walking')
end
22 changes: 22 additions & 0 deletions tests/Example3/features/submit_details.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Feature: Login in and submit details

Scenario: Submit details
Given I have a user account
And I visit the test site
When I login using that user account and click on the Details Form
Then I can complete and submit the form with my details
And I confirm that the details are displayed correctly

Scenario: Submit different details
Given I have a user account
And I visit the test site
When I login using that user account and click on the Details Form
Then I can complete and submit the form with different details
And I confirm that the different details are displayed correctly

Scenario: Create new user and complete the details form
Given I have a user account
When I visit the test site
And I login using that user account and click on the Details Form
Then I submit without completing any details
And I confirm only the default values are present
36 changes: 36 additions & 0 deletions tests/Example3/features/support/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'open-uri'
require 'net/http'
require 'rspec/expectations'
require 'json'

require 'capybara/cucumber'

### Allows you to use the page. commands
include Capybara::DSL


Capybara.default_selector = :xpath
Capybara.default_wait_time = 10
Capybara.app_host = 'http://localhost:4567'

Capybara.default_driver = :poltergeist
Capybara.javascript_driver = :poltergeist

if (ENV['webdriver'] == 'poltergeist') then

require 'capybara/poltergeist'

Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, inspector: true, js_errors: true)
end
require 'test/unit'
include Test::Unit::Assertions

else

require 'selenium-webdriver'

Capybara.default_driver = :selenium
Capybara.javascript_driver = :selenium

end
Loading