Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable JavaScript testing with Poltergeist #230

Merged
merged 2 commits into from
Feb 7, 2017
Merged
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
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ gem "rake", "0.9.2.2"
gem "rspec", "2.11.0"
gem "minitest", "5.8.4"
gem "cucumber", "1.3.20"
gem "capybara", "~> 2.0"
gem "capybara-mechanize"
gem "capybara", "~> 2.12.0"
gem "poltergeist", "1.13.0"

gem "rest-client", "1.6.7"
gem "nokogiri", "1.5.5"
41 changes: 14 additions & 27 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,49 +1,37 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.4.0)
addressable (2.5.0)
public_suffix (~> 2.0, >= 2.0.2)
builder (3.2.2)
capybara (2.10.1)
capybara (2.12.0)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
capybara-mechanize (1.5.0)
capybara (~> 2.4, >= 2.4.4)
mechanize (~> 2.7.0)
cliver (0.3.2)
cucumber (1.3.20)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.12)
multi_json (>= 1.7.5, < 2.0)
multi_test (>= 0.1.2)
diff-lcs (1.1.3)
domain_name (0.5.20160826)
unf (>= 0.0.5, < 1.0.0)
gherkin (2.12.2)
multi_json (~> 1.3)
http-cookie (1.0.3)
domain_name (~> 0.5)
mechanize (2.7.3)
domain_name (~> 0.5, >= 0.5.1)
http-cookie (~> 1.0)
mime-types (~> 2.0)
net-http-digest_auth (~> 1.1, >= 1.1.1)
net-http-persistent (~> 2.5, >= 2.5.2)
nokogiri (~> 1.4)
ntlm-http (~> 0.1, >= 0.1.1)
webrobots (>= 0.0.9, < 0.2)
mime-types (2.99.3)
minitest (5.8.4)
multi_json (1.12.1)
multi_test (0.1.2)
net-http-digest_auth (1.4)
net-http-persistent (2.9.4)
nokogiri (1.5.5)
ntlm-http (0.1.1)
plek (1.11.0)
poltergeist (1.13.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
websocket-driver (>= 0.2.0)
public_suffix (2.0.5)
rack (2.0.1)
rack-test (0.6.3)
rack (>= 1.0)
Expand All @@ -58,23 +46,22 @@ GEM
rspec-expectations (2.11.3)
diff-lcs (~> 1.1.3)
rspec-mocks (2.11.3)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
webrobots (0.1.2)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
xpath (2.0.0)
nokogiri (~> 1.3)

PLATFORMS
ruby

DEPENDENCIES
capybara (~> 2.0)
capybara-mechanize
capybara (~> 2.12.0)
cucumber (= 1.3.20)
minitest (= 5.8.4)
nokogiri (= 1.5.5)
plek (= 1.11.0)
poltergeist (= 1.13.0)
rake (= 0.9.2.2)
rest-client (= 1.6.7)
rspec (= 2.11.0)
Expand Down
4 changes: 2 additions & 2 deletions features/asset_manager.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ Feature: Asset Manager
Scenario: check an asset can be loaded
Given I am testing "asset-manager"
And I am an authenticated API client
When I visit "/assets/513a0efbed915d425e000002"
When I request "/assets/513a0efbed915d425e000002"
Then I should get a 200 status code
And I should see "120613_Albania_Travel_Advice_WEB_Ed2_jpeg.jpg"

@normal
Scenario: check an asset can be served
Given I am testing "static"
When I visit "/media/513a0efbed915d425e000002/120613_Albania_Travel_Advice_WEB_Ed2_jpeg.jpg"
When I request "/media/513a0efbed915d425e000002/120613_Albania_Travel_Advice_WEB_Ed2_jpeg.jpg"
Then I should get a 200 status code
And I should get a content length of "212880"
2 changes: 1 addition & 1 deletion features/assets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Feature: Assets
@high
Scenario: Assets are being served
Given I am testing "assets"
When I visit "/__canary__"
When I request "/__canary__"
Then I should get a 200 status code
6 changes: 4 additions & 2 deletions features/calculators.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Feature: Calculators app
Scenario: Accessing the child benefit tax calculator
Given I am testing through the full stack
And I force a varnish cache miss

When I visit "/child-benefit-tax-calculator"
Then I should get a 200 status code
Then I should see "Child Benefit tax calculator"

When I visit "/child-benefit-tax-calculator/main"
Then I should get a 200 status code
Then I should see "Child Benefit tax calculator"
3 changes: 2 additions & 1 deletion features/calendars.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ Feature: Calendars
@normal
Scenario: check bank holidays JSON format is consistent
Given I am testing through the full stack
Then I should see a consistent JSON format for the path "/bank-holidays.json"
When I request "/bank-holidays.json"
Then JSON is returned
2 changes: 1 addition & 1 deletion features/content_api.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Feature: Content API
Scenario: (Public) Content API availability
Given I am testing through the full stack
And I force a varnish cache miss
When I visit "/api/vehicle-tax.json"
When I request "/api/vehicle-tax.json"
Then I should get a 200 status code
And I should see "Tax your vehicle"
6 changes: 3 additions & 3 deletions features/frontend.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Frontend

@normal
Scenario: check robots.txt
When I visit "/robots.txt"
When I request "/robots.txt"
Then I should get a 200 status code
Then I should see "User-agent:"

Expand All @@ -32,7 +32,7 @@ Feature: Frontend

@normal
Scenario: check homepage content type & charset
When I visit "/"
When I request "/"
Then I should get a "Content-Type" header of "text/html; charset=utf-8"

@normal
Expand Down Expand Up @@ -67,7 +67,7 @@ Feature: Frontend
@normal
Scenario: check campaign pages load
When I visit "/workplacepensions"
Then I should get a 200 status code
Then I should be at a location path of "/workplace-pensions"

@normal
Scenario: check browse page load, and links
Expand Down
5 changes: 5 additions & 0 deletions features/javascript_errors.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: Smokey Javascript Error detection

@normal
Scenario: Smokey detects JS errors
When I inject a JavaScript error on the page, Smokey raises an exception
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clever!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done!

2 changes: 1 addition & 1 deletion features/licensing.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Feature: Licensing
And I am benchmarking
And I am testing through the full stack
And I force a varnish cache miss
When I visit "/apply-for-a-licence/forms/bury/test-licence/9999-7-1,0-1"
When I request "/apply-for-a-licence/forms/bury/test-licence/9999-7-1,0-1"
Then the elapsed time should be less than 10 seconds

@normal @notintegration
Expand Down
7 changes: 2 additions & 5 deletions features/private_frontend.feature
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
Feature: Private Frontend

Background:
Given I am testing "private-frontend"
And I am not an authenticated user

@normal
Scenario: check private frontend requires auth
When I try to visit "/"
Given I am testing "private-frontend"
When I visit "/" without authentication
Then I should get a 401 status code
13 changes: 4 additions & 9 deletions features/step_definitions/ab_testing_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,17 @@
end

Then(/^I am assigned to a test bucket$/) do
ab_cookies = @response.headers[:set_cookie]
.select { |h| h.start_with? "ABTest-Example=" }
assert_equal 1, ab_cookies.length,
"Expected response to set exactly one A/B test cookie"

ab_cookie = ab_cookies[0]
@ab_cookie_value = /ABTest-Example=([^;]*);/.match(ab_cookie)[1]
ab_cookie = page.driver.cookies["ABTest-Example"]
@ab_cookie_value = ab_cookie.value

assert @ab_cookie_value == "A" || @ab_cookie_value == "B",
"Expected A/B cookie to have value 'A' or 'B' but got '#{@ab_cookie_value}'"

assert ab_cookie.include?("expires="), "A/B cookie has no expiry time"
refute_nil ab_cookie.expires, "A/B cookie has no expiry time"
end

Then(/^I can see the bucket I am assigned to$/) do
bucket = ab_bucket(@response.body)
bucket = ab_bucket(page.body)
assert bucket == "A" || bucket == "B",
"Expected A/B bucket to be 'A' or 'B', but got '#{bucket}'"

Expand Down
11 changes: 2 additions & 9 deletions features/step_definitions/calendar_steps.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
require 'json'

Then /^I should see a consistent JSON format for the path "([^"]*)"$/ do |path|
json = get_request "#{@host}#{path}", cache_bust: @bypass_varnish
json = JSON.parse(json)
assert json["england-and-wales"]
assert json["england-and-wales"]["events"]
assert json["england-and-wales"]["events"].length
result = json["england-and-wales"]["events"].first
assert result["title"]
assert result["date"]
Then /^JSON is returned$/ do
JSON.parse(@response.body).class.should == Hash
end
4 changes: 2 additions & 2 deletions features/step_definitions/cookie_steps.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Then /^I should receive a "([a-z0-9_]+)" cookie which is "([a-zA-Z]+)"$/ do |cookie_name, cookie_property|
header = page.response_headers['set-cookie']
assert header.start_with?(cookie_name), "No cookie called #{cookie_name} is being set"
header = page.response_headers['Set-Cookie']
assert header.to_s.start_with?(cookie_name), "No cookie called #{cookie_name} is being set"

property_matches = header.match /; #{cookie_property}(;|$)/
assert !property_matches.nil?, "The cookie #{cookie_name} does not have property #{cookie_property}"
Expand Down
8 changes: 4 additions & 4 deletions features/step_definitions/draft_environment_steps.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
When /^I attempt to go to a case study$/ do
visit "government/case-studies/epic-cic"
visit_path "government/case-studies/epic-cic"
end

When /^I attempt to visit "(.*?)"$/ do |path|
visit path
visit_path path
end

When /^I attempt to visit a CMA case$/ do
visit "cma-cases/japan-tobacco-international-e-lites"
visit_path "cma-cases/japan-tobacco-international-e-lites"
end

When /^I attempt to visit a manual$/ do
visit "guidance/content-design"
visit_path "guidance/content-design"
end

Then /^I should be prompted to log in$/ do
Expand Down
9 changes: 4 additions & 5 deletions features/step_definitions/efg_steps.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
Given /^I am testing in an EFG context$/ do
# Not sure if there is a better way to do this?
page.driver.browser.agent.add_auth(efg_base_url, ENV['AUTH_USERNAME'], ENV['AUTH_PASSWORD'])
# TODO: remove me
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this forgotten?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure - @tijmenb ?

end

When /^I try to access the list of lenders$/ do
visit "#{efg_base_url}/lenders"
visit_path "#{efg_base_url}/lenders"
end

When /^I try to login as a valid EFG user$/ do
assert ENV["EFG_USERNAME"] && ENV["EFG_PASSWORD"], "Please ensure that the EFG user credentials are available in the environment"

# Need to do it this way to comply with CSRF protection
visit "#{efg_base_url}/users/sign_in"
visit_path "#{efg_base_url}/users/sign_in"
fill_in "Username", :with => ENV["EFG_USERNAME"]
fill_in "Password", :with =>ENV["EFG_PASSWORD"]
click_button "Sign In"
end

When /^I visit the EFG home page$/ do
visit "#{efg_base_url}"
visit_path "#{efg_base_url}"
end

Then /^I should be on the EFG home page$/ do
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/finder_frontend_steps.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Then /^I should see an input field to search$/ do
@response.body.should have_field('keywords')
page.body.should have_field('keywords')
end
4 changes: 2 additions & 2 deletions features/step_definitions/frontend_steps.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
When /^I click on the section "(.*?)"$/ do |section_name|
link_href = Nokogiri::HTML.parse(@response.body).at_xpath("//h3[text()='#{section_name}']/../@href")
link_href = Nokogiri::HTML.parse(page.body).at_xpath("//h3[text()='#{section_name}']/../@href")
link_href.should_not == nil
step "I visit \"#{link_href.value}\""
end

Then /^I should see an input field for postcode$/ do
@response.body.should have_field('postcode')
page.body.should have_field('postcode')
end
2 changes: 1 addition & 1 deletion features/step_definitions/licensing.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
When /^I login to Licensify$/ do
visit "https://licensify-admin.#{ENV['GOVUK_APP_DOMAIN']}/login"
visit_path "https://licensify-admin.#{ENV['GOVUK_APP_DOMAIN']}/login"
click_button 'Login'
end
13 changes: 13 additions & 0 deletions features/step_definitions/search_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
When /^I search for "(.*)"$/ do |term|
visit_path "/search?q=#{term}"
end

Then /^I should see some search results$/ do
result_links = page.all(".results-list li a")
result_links.count.should >= 1
end

Then /^I should see organisations in the organisation filter$/ do
organisation_options = page.all("#organisations-filter input")
organisation_options.count.should >= 10
end
2 changes: 1 addition & 1 deletion features/step_definitions/sitemap_steps.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
When /^I get the sitemap index$/ do
step "I visit \"/sitemap.xml\""
@sitemap_doc = Nokogiri.XML(@response.body)
@sitemap_doc = Nokogiri.XML(page.body)
@sitemap_links = @sitemap_doc.xpath("/xmlns:sitemapindex/xmlns:sitemap/xmlns:loc")
end

Expand Down
Loading