Skip to content

Commit

Permalink
Add request details test
Browse files Browse the repository at this point in the history
This adds a new page that when requested, will output the details of the
request. It was created as part of working on [Add ability to set
user-agent to use](DEFRA/quke#60) in **Quke**.

Along with it is a feature that provides an example of how you can then
test a page for specific content. Admittedly not an amazing addition as
an example, but it gives meaning for the page being there, and is a
working example nonetheless.
  • Loading branch information
Cruikshanks committed Jun 9, 2017
1 parent a41df6a commit 3041c3d
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 0 deletions.
6 changes: 6 additions & 0 deletions demo_app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@
@title = 'CSS selector'
erb :css_selector
end

get '/request' do
@title = 'Request details'
@results = request.env
erb :request_details
end
20 changes: 20 additions & 0 deletions demo_app/views/request_details.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
<h1><%= @title %></h1>
<p class="lead">This page can be used for checking that the request you formulated in <strong>Quke</strong> is as
expected. It will display the details for each item in the request.</p>
<p class="lead">There are examples of how to test against the data in this page, but essentially they are just
using <strong>Capybara's</strong> <code>find()</code> method.</p>
<ul>
<li><code>features/quke/request_details.feature</code></li>
<li><code>features/step_definitions/quke/request_details_steps.rb</code></li>
<li><code>quke_demo_app/views/request_details.erb</code></li>
</ul>
</div>

<div id="results">
<h2>Results</h2>
<% @results.each do | key, value | %>
<div><strong><%= key %></strong> <code id="<%= key %>"><%= value %></code></div>
<% end %>
</div>
4 changes: 4 additions & 0 deletions features/page_objects/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ def radio_button_page
def css_selectors_page
@last_page = CssSelectorsPage.new
end

def request_details_page
@last_page = RequestDetailsPage.new
end
end
10 changes: 10 additions & 0 deletions features/page_objects/request_details_page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Request details page
class RequestDetailsPage < SitePrism::Page
set_url '/request'

element :title, 'h1'
element :request_type, '#REQUEST_METHOD'
element :user_agent, '#HTTP_USER_AGENT'

elements :results, "div[class='result']"
end
16 changes: 16 additions & 0 deletions features/request_details.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Feature: Request details
To demonstrate how you can use Quke
As a user of Quke
I want to see that the request received matches what I configured in Quke

@wip
Scenario: Checking for custom user agent (page objects)
Given I am on the request details page
Then It should show we made a "GET" request
And the user agent was "Mozilla/5.0 (MSIE 10.0; Windows NT 6.1; Trident/5.0)"

@wip
Scenario: Checking for custom user agent (capybara)
Given I'm at the request details page
Then I should see we made a "GET" request
And that the user agent was "Mozilla/5.0 (MSIE 10.0; Windows NT 6.1; Trident/5.0)"
28 changes: 28 additions & 0 deletions features/step_definitions/request_details_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# The following steps use the page objects to drive the browser
Given(/^I am on the request details page$/) do
@app = App.new
@app.request_details_page.load
expect(@app.request_details_page.title.text).to eq('Request details')
end

Then(/^It should show we made a "([^"]*)" request$/) do |request_type|
expect(@app.request_details_page.request_type.text).to eq(request_type)
end

And(/^the user agent was "([^"]*)"$/) do |user_agent|
expect(@app.request_details_page.user_agent.text).to eq(user_agent)
end

# The following steps use capybara directly to drive the browser
Given(/^I'm at the request details page$/) do
visit 'http://localhost:4567/request'
expect(page).to have_content('Request details')
end

Then(/^I should see we made a "([^"]*)" request$/) do |request_type|
expect(find('#REQUEST_METHOD').text).to eq(request_type)
end

And(/^that the user agent was "([^"]*)"$/) do |user_agent|
expect(find('#HTTP_USER_AGENT').text).to eq(user_agent)
end

0 comments on commit 3041c3d

Please sign in to comment.