2018-04-18 16:45:35 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-06 13:59:11 -04:00
|
|
|
Capybara::SpecHelper.spec Capybara::Selector do
|
|
|
|
before do
|
|
|
|
@session.visit('/form')
|
|
|
|
end
|
|
|
|
|
|
|
|
describe ":label selector" do
|
|
|
|
it "finds a label by text" do
|
|
|
|
expect(@session.find(:label, 'Customer Name').text).to eq 'Customer Name'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "finds a label by for attribute string" do
|
|
|
|
expect(@session.find(:label, for: 'form_other_title')['for']).to eq 'form_other_title'
|
|
|
|
end
|
|
|
|
|
2016-09-28 14:49:08 -04:00
|
|
|
it "finds a label from nested input using :for filter with id string" do
|
|
|
|
expect(@session.find(:label, for: 'nested_label').text).to eq 'Nested Label'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "finds a label from nested input using :for filter with element" do
|
2016-04-06 13:59:11 -04:00
|
|
|
input = @session.find(:id, 'nested_label')
|
|
|
|
expect(@session.find(:label, for: input).text).to eq 'Nested Label'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "finds the label for an non-nested element when using :for filter" do
|
|
|
|
select = @session.find(:id, 'form_other_title')
|
|
|
|
expect(@session.find(:label, for: select)['for']).to eq 'form_other_title'
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with exact option" do
|
|
|
|
it "matches substrings" do
|
|
|
|
expect(@session.find(:label, 'Customer Na', exact: false).text).to eq 'Customer Name'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't match substrings" do
|
|
|
|
expect { @session.find(:label, 'Customer Na', exact: true) }.to raise_error(Capybara::ElementNotFound)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-04-26 11:51:22 -04:00
|
|
|
|
2016-09-22 19:55:54 -04:00
|
|
|
describe "field selectors" do
|
2016-04-26 11:51:22 -04:00
|
|
|
it "can find specifically by id" do
|
|
|
|
expect(@session.find(:field, id: 'customer_email').value).to eq "ben@ben.com"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can find specifically by name" do
|
|
|
|
expect(@session.find(:field, name: 'form[other_title]')['id']).to eq "form_other_title"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can find specifically by placeholder" do
|
|
|
|
expect(@session.find(:field, placeholder: 'FirstName')['id']).to eq "form_first_name"
|
|
|
|
end
|
2016-08-18 16:27:35 -04:00
|
|
|
|
|
|
|
it "can find by type" do
|
|
|
|
expect(@session.find(:field, 'Confusion', type: 'checkbox')['id']).to eq 'confusion_checkbox'
|
|
|
|
expect(@session.find(:field, 'Confusion', type: 'text')['id']).to eq 'confusion_text'
|
|
|
|
expect(@session.find(:field, 'Confusion', type: 'textarea')['id']).to eq 'confusion_textarea'
|
|
|
|
end
|
2016-09-07 03:34:15 -04:00
|
|
|
|
|
|
|
it "can find by class" do
|
|
|
|
expect(@session.find(:field, class: 'confusion-checkbox')['id']).to eq 'confusion_checkbox'
|
|
|
|
expect(@session).to have_selector(:field, class: 'confusion', count: 3)
|
2018-02-28 19:11:41 -05:00
|
|
|
expect(@session.find(:field, class: ['confusion', 'confusion-textarea'])['id']).to eq 'confusion_textarea'
|
2016-09-07 03:34:15 -04:00
|
|
|
end
|
2016-04-26 11:51:22 -04:00
|
|
|
end
|
2018-02-28 19:11:41 -05:00
|
|
|
end
|