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 support for input type=submit #24

Merged
merged 1 commit into from
Sep 18, 2023
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: 4 additions & 0 deletions lib/click_govuk_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def click
@buttons = page.all('a.govuk-button', text: button_text, exact_text: true)
end

if @buttons.empty?
@buttons = page.all("input[type=submit][value=\"#{Capybara::Selector::CSS.escape(button_text)}\"]")
end

if @buttons.size == 0
check_for_inexact_match
raise "Unable to find button \"#{button_text}\""
Expand Down
12 changes: 12 additions & 0 deletions spec/click_govuk_button_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@
end
end

context "where there is an input with type=submit" do
before do
TestApp.body = '<form action="/success" method="post"><input type="submit" class="govuk-button" data-module="govuk-button" value="Continue" /></form>'
visit('/')
end

it 'should submit the form' do
click_govuk_button('Continue')
expect(page.current_path).to eql("/success")
end
end

context "where there are 2 buttons with the same text" do
before do
TestApp.body = '<button>Continue</button> <button>Continue</button>'
Expand Down