diff --git a/tests/Example3/.DS_Store b/tests/Example3/.DS_Store new file mode 100644 index 0000000..8830149 Binary files /dev/null and b/tests/Example3/.DS_Store differ diff --git a/tests/Example3/Activity_one.pages b/tests/Example3/Activity_one.pages new file mode 100644 index 0000000..266022f Binary files /dev/null and b/tests/Example3/Activity_one.pages differ diff --git a/tests/Example3/features/.DS_Store b/tests/Example3/features/.DS_Store new file mode 100644 index 0000000..a3fa6ff Binary files /dev/null and b/tests/Example3/features/.DS_Store differ diff --git a/tests/Example3/features/example3.feature b/tests/Example3/features/example3.feature new file mode 100644 index 0000000..8ec25cf --- /dev/null +++ b/tests/Example3/features/example3.feature @@ -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 diff --git a/tests/Example3/features/steps/login.rb b/tests/Example3/features/steps/login.rb new file mode 100644 index 0000000..f9bcec3 --- /dev/null +++ b/tests/Example3/features/steps/login.rb @@ -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 diff --git a/tests/Example3/features/support/config.rb b/tests/Example3/features/support/config.rb new file mode 100644 index 0000000..c7250ef --- /dev/null +++ b/tests/Example3/features/support/config.rb @@ -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 diff --git a/tests/Example3/features/support/functions.rb b/tests/Example3/features/support/functions.rb new file mode 100644 index 0000000..2259560 --- /dev/null +++ b/tests/Example3/features/support/functions.rb @@ -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 diff --git a/tests/JSON/.DS_Store b/tests/JSON/.DS_Store new file mode 100644 index 0000000..ee74d1c Binary files /dev/null and b/tests/JSON/.DS_Store differ diff --git a/tests/JSON/features/.DS_Store b/tests/JSON/features/.DS_Store new file mode 100644 index 0000000..029fedf Binary files /dev/null and b/tests/JSON/features/.DS_Store differ diff --git a/tests/JSON/features/JSON.feature b/tests/JSON/features/JSON.feature new file mode 100644 index 0000000..c955043 --- /dev/null +++ b/tests/JSON/features/JSON.feature @@ -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 diff --git a/tests/JSON/features/step_definitions/.DS_Store b/tests/JSON/features/step_definitions/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/tests/JSON/features/step_definitions/.DS_Store differ diff --git a/tests/JSON/features/step_definitions/interogate.rb b/tests/JSON/features/step_definitions/interogate.rb new file mode 100644 index 0000000..a0cc914 --- /dev/null +++ b/tests/JSON/features/step_definitions/interogate.rb @@ -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 diff --git a/tests/JSON/features/support/.DS_Store b/tests/JSON/features/support/.DS_Store new file mode 100644 index 0000000..6589e32 Binary files /dev/null and b/tests/JSON/features/support/.DS_Store differ diff --git a/tests/JSON/features/support/env.rb b/tests/JSON/features/support/env.rb new file mode 100644 index 0000000..83ccb9b --- /dev/null +++ b/tests/JSON/features/support/env.rb @@ -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