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

Add example of interacting with radio-buttons #15

Merged
merged 1 commit into from
Jun 28, 2016
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
22 changes: 22 additions & 0 deletions features/quke/radio_buttons.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Feature: Radio buttons
To demonstrate how you can use Quke
As a user of Quke
I want to see how to interact with radio buttons and check the results

Scenario: Confirming number of radio buttons (page objects)
Given I am on the radio button page
Then I should see 5 options

Scenario: Confirming number of radio buttons (capybara)
Given I'm at the radio button page
Then I should get 5 options

Scenario: Confirming I can select a radio button (page objects)
Given I am on the radio button page
And I select an option
Then I should see a confirmation of my selection

Scenario: Confirming I can select a radio button (capybara)
Given I'm at the radio button page
And I select one of the options
Then I should my selection confirmed
50 changes: 50 additions & 0 deletions features/step_definitions/quke/radio_button_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# The following steps use the page objects to drive the browser
Given(/^I am on the radio button page$/) do
@app = QukeApp.new
@app.radio_button_page.load
expect(@app.radio_button_page.title.text).to eq('Radio button')
end

Then(/^I should see (\d+) options$/) do |num_of_results|
expect(@app.radio_button_page.options.size).to eq(Integer(num_of_results))
end

Given(/^I select an option$/) do
# This demonstrates reuse of a step. We want to ensure we can see options
# before trying to select one, but rather than repeat the same expectation
# we instead reuse the step that does this.
step 'I should see 5 options'

# rubocop: disable LineLength
@app.radio_button_page.options.find { |btn| btn.value == 'WasteExemptionsShared::OrganisationType::Partnership' }.click
# rubocop: enable LineLength

@app.radio_button_page.confirm_button.click
end

Then(/^I should see a confirmation of my selection$/) do
expect(@app.radio_button_page.result.text).to end_with('Partnership')
end

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

Then(/^I should get (\d+) options$/) do |num_of_results|
expect(page.all('input[type=radio]').size).to eq(Integer(num_of_results))
end

Given(/^I select one of the options$/) do
# This demonstrates reuse of a step. We want to ensure we can see options
# before trying to select one, but rather than repeat the same expectation
# we instead reuse the step that does this.
step 'I should get 5 options'
choose('organisation_partnership')
click_button('commit')
end

Then(/^I should my selection confirmed$/) do
expect(find('span[id=result]').text).to end_with('Partnership')
end
4 changes: 4 additions & 0 deletions features/support/page_objects/quke/quke_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ def home_page
def search_page
@last_page = QukeSearchPage.new
end

def radio_button_page
@last_page = QukeRadioButtonPage.new
end
end
10 changes: 10 additions & 0 deletions features/support/page_objects/quke/quke_radio_button_page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Radio button page
class QukeRadioButtonPage < SitePrism::Page
set_url 'http://localhost:4567/radiobutton'

element :title, 'h1'
element :confirm_button, "input[name='commit']"
element :result, "span[id='result']"

elements :options, "input[name='enrollment[organisation_attributes][type]']"
end
15 changes: 15 additions & 0 deletions quke_demo_app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
end

post '/search' do
@title = 'Search'

@query = params['search_input']

# rubocop:disable Metrics/LineLength
Expand All @@ -48,3 +50,16 @@

erb :search
end

get '/radiobutton' do
@title = 'Radio button'
erb :radio_button
end

post '/radiobutton' do
@title = 'Radio button'
@selection = params['enrollment']['organisation_attributes']['type']
@result = @selection.match(/OrganisationType::([^"]*)/)[1]

erb :radio_button
end
3 changes: 2 additions & 1 deletion quke_demo_app/views/index.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
<h1><%= @title %> <img src="/assets/images/quke.png" width="65px" align="middle" /></h1>
<p class="lead">Use this document as a way to quickly start any new project.<br /> All you get is this text and a mostly barebones HTML document.</p>
<p class="lead">This demo app is what the example features run against.<br /> Use it along with the features to explore how to interact with your web sites using Quke.</p>
</div>

<ul>
<li><a href="/search">Search</a></li>
<li><a href="/radiobutton">Radio buttons</a></li>
</ul>

<%= erb '_partial_example'.to_sym %>
43 changes: 43 additions & 0 deletions quke_demo_app/views/radio_button.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<header>
<h1><%= @title %></h1>
</header>

<form id="radio_button_example" action="/radiobutton" accept-charset="UTF-8" method="post">
<fieldset>

<div id="form_group_organisation_type" role="group" aria-labelledby="groupLabel" class="form">
<label class="radio" for="organisation_limited_company">
<input id="organisation_limited_company" type="radio" value="WasteExemptionsShared::OrganisationType::LimitedCompany" name="enrollment[organisation_attributes][type]" />
Limited company
</label>
<label class="radio" for="organisation_limited_liability_partnership">
<input id="organisation_limited_liability_partnership" type="radio" value="WasteExemptionsShared::OrganisationType::LimitedLiabilityPartnership" name="enrollment[organisation_attributes][type]" />
Limited liability partnership
</label>
<label class="radio" for="organisation_partnership">
<input id="organisation_partnership" type="radio" value="WasteExemptionsShared::OrganisationType::Partnership" name="enrollment[organisation_attributes][type]" />
Partnership
</label>
<label class="radio" for="organisation_other">
<input id="organisation_other" type="radio" value="WasteExemptionsShared::OrganisationType::Other" name="enrollment[organisation_attributes][type]" />
Other (trust, club or public body)
</label>
<label class="radio" for="organisation_not_known">
<input id="organisation_not_known" type="radio" value="WasteExemptionsShared::OrganisationType::NotKnown" name="enrollment[organisation_attributes][type]" />
I don’t know
</label>
</div>
</fieldset>

<div class="actions">
<input type="submit" id="commit" name="commit" value="Continue" class="button"/>
</div>
</form>
<% if @result %>
<div id="results">
<h2>Results</h2>
<div id="selected-option" class="result">
<p class="result-desc"><span id="result">You selected <strong><%= @result %></strong></span></p>
</div>
</div>
<% end %>