Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added tests/Example3/.DS_Store
Binary file not shown.
Binary file added tests/Example3/Activity_one.pages
Binary file not shown.
Binary file added tests/Example3/features/.DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions tests/Example3/features/example3.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@28
Feature: User logs in and fills in details


Scenario: Log in and complete details
Given i have logged in
When i enter my details
Then my details are displayed
48 changes: 48 additions & 0 deletions tests/Example3/features/steps/login.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Given(/^i have logged in$/) do
$data = {}
$data['user_name'] = 'User' + Time.new().to_i.to_s + '@example.org' # Create a random user name
$data['user_password'] = 'password'

rest_post_call('http://localhost:4567/add_user', $data)

visit('http://localhost:4567')

fill_in('username', :with => $data['user_name'])
fill_in('password', :with => $data['user_password'])
click_button('Sign in')

expect(page.body).to match('Logged in')

find('html/body/div[2]/ul/li[2]/a').click
sleep 3
end

When(/^i enter my details$/) do

page.has_content?('Please enter details')
fill_in(id='first-name', :with => 'John')
fill_in(id="second-name", :with => 'Smith')
fill_in(id="house-number", :with => '34')
fill_in(id="street", :with => 'Smith Street')
fill_in(id="city", :with => 'Bath')
fill_in(id="postcode", :with => 'BA1 1QL')
find(:xpath,'html/body/div[1]/form/input[8]').click
check('walking')
check('cycling')
check('swimming')
select('Audi', :from=>'cars')
sleep 4
click_button('Submit')

end


Then(/^my details are displayed$/) do
#page.should have_content?('John')
expect(page).to have_text 'Smith'
#page.has_content 'Bath'
#page.should have_content?('34 Smith Street Bath BA1 1QL')
#page.should have_content('I am a catnip')
#expect(page).have_content'Joe'
#assert_match('I drive a banana',page.body,'No banana')
end
40 changes: 40 additions & 0 deletions tests/Example3/features/support/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'open-uri'
require 'net/http'
require 'rspec/expectations'
require 'json'

require 'capybara/cucumber'
#require 'minitest/autorun'
#require 'test/unit'

require "minitest/autorun"
World(MiniTest::Assertions)

### Allows you to use the page. commands
#include Test::Unit::Assertions
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

else

require 'selenium-webdriver'

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

end
48 changes: 48 additions & 0 deletions tests/Example3/features/support/functions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#######
# Function: rest_get_call
# Description: This function should be used to do all get requests
# Inputs:
# - url = The url that the web service is calling
# Outputs:
# - curl response
######
def rest_get_call(url)
uri = URI.parse(url)

http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.path, initheader = {'Content-Type' =>'application/json'})
request.basic_auth $http_auth_name, $http_auth_password
response = http.request(request)

return response
end

#######
# Function: rest_post_call
# Description: This function should be used to do all post requests
# Inputs:
# - url = The url that the web service is calling
# - data = The data post for the post
# - body = The body for the post
# Outputs:
# - curl response
######
def rest_post_call(url, data = nil, body = nil)
uri = URI.parse(url)

http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
request.basic_auth $http_auth_name, $http_auth_password

if (!data.nil?) then
request.set_form_data(data)
end

if (!body.nil?) then
request.body = body
end

response = http.request(request)

return response
end
Binary file added tests/JSON/.DS_Store
Binary file not shown.
Binary file added tests/JSON/features/.DS_Store
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/JSON/features/JSON.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: Json file investigation

Scenario: Looking up json information

Given I have entered a title number

When the output is returned

Then i can confirm the data
Binary file not shown.
21 changes: 21 additions & 0 deletions tests/JSON/features/step_definitions/interogate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# $ creates a global variable in order to store the json object for use elsewhere

Given(/^I have entered a title number$/) do
$structure= getstubjson("DT160760")
end

When(/^the output is returned$/) do
$structure_hash = JSON.parse($structure)
end

Then(/^i can confirm the data$/) do
puts $structure_hash['uprns'][0].to_s + " uprns"
expect($structure_hash['uprns'][0]).to eq(26241363)

#abr validation
puts $structure_hash['application_reference'] + " application reference"
if ($structure_hash['application_reference'])==('UPD0019')
then puts 'correct'
else puts'fails'
end
end
Binary file added tests/JSON/features/support/.DS_Store
Binary file not shown.
29 changes: 29 additions & 0 deletions tests/JSON/features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'rubygems'
require 'net/http'

require 'json'


#These are web service call passwords that can be set or default to ''

$http_auth_name = (ENV['HTTPAUTH_USERNAME'] || '')
$http_auth_password = (ENV['HTTPAUTH_PASSWORD'] || '')

#List of URLs to access its defaulted but then possible to export a different address so it points to the cloud instead

$STUBJSON = (ENV['http://localhost:5000'] || '')
$STUBJSON = 'http://localhost:5000/'

#This function gets the json object

def getstubjson(title_number)
uri = URI.parse($STUBJSON)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new('/' + title_number)
request.basic_auth $http_auth_name, $http_auth_password
response = http.request(request)
if (response.code != '200') then
raise "Error in getting JSON for: " + title_number
end
return response.body
end