spec/support/shared_examples/element_dsl.rb in howitzer-2.0.1 vs spec/support/shared_examples/element_dsl.rb in howitzer-2.0.2
- old
+ new
@@ -73,75 +73,80 @@
let(:web_page_object) { web_page_class.new }
let(:kontext) { double(:kontext) }
before do
allow(Capybara).to receive(:current_session) { kontext }
klass.class_eval do
- element :foo, :xpath, ->(title, name) { "//a[.='#{title}']/*[@name='#{name}']" }
- element :bar, '.someclass'
- element :top_panel, '.top'
+ element :foo, :xpath,
+ ->(title, name) { "//a[.='#{title}']/*[@name='#{name}']" }, text: 'original', match: :first
+ element :bar, '.someclass', text: 'origin', match: :first
+ element :top_panel, '.top', text: 'origin', match: :first
end
end
describe '#name_element' do
context 'when simple selector' do
- subject { klass_object.send(:bar_element, wait: 10) }
+ subject { klass_object.send(:bar_element, text: 'new', wait: 10) }
after { subject }
- it { expect(klass_object.capybara_context).to receive(:find).with('.someclass', wait: 10) }
+ it do
+ expect(klass_object.capybara_context).to receive(:find)
+ .with('.someclass', wait: 10, text: 'new', match: :first)
+ end
end
context 'when lambda selector' do
- subject { klass_object.send(:foo_element, 'Hello', 'super', wait: 10) }
+ subject { klass_object.send(:foo_element, 'Hello', 'super', text: 'new', wait: 10) }
after { subject }
it do
- expect(
- klass_object.capybara_context
- ).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10)
+ expect(klass_object.capybara_context).to receive(:find)
+ .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
end
context 'when several execution with different data' do
it 'does not cache previous data' do
- expect(
- klass_object.capybara_context
- ).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10).at_least(:once)
- klass_object.send(:foo_element, 'Hello', 'super', wait: 10)
+ expect(klass_object.capybara_context).to receive(:find)
+ .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first).at_least(:once)
+ klass_object.send(:foo_element, 'Hello', 'super', text: 'new', wait: 10)
- expect(
- klass_object.capybara_context
- ).to receive(:find).with(:xpath, "//a[.='Bye']/*[@name='puper']", wait: 15).at_least(:once)
- klass_object.send(:foo_element, 'Bye', 'puper', wait: 15)
+ expect(klass_object.capybara_context).to receive(:find)
+ .with(:xpath, "//a[.='Bye']/*[@name='puper']", wait: 15, text: 'new', match: :first).at_least(:once)
+ klass_object.send(:foo_element, 'Bye', 'puper', text: 'new', wait: 15)
end
end
end
end
describe '#name_elements' do
after { subject }
context 'when simple selector' do
- subject { klass_object.send(:bar_elements, wait: 10) }
- it { expect(klass_object.capybara_context).to receive(:all).with('.someclass', wait: 10) }
+ subject { klass_object.send(:bar_elements, text: 'new', wait: 10) }
+ it do
+ expect(klass_object.capybara_context).to receive(:all)
+ .with('.someclass', wait: 10, text: 'new', match: :first)
+ end
end
context 'when lambda selector' do
- subject { klass_object.send(:foo_elements, 'Hello', 'super', wait: 10) }
+ subject { klass_object.send(:foo_elements, 'Hello', 'super', text: 'new', wait: 10) }
it do
expect(
klass_object.capybara_context
- ).to receive(:all).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10)
+ ).to receive(:all).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
end
end
end
describe '#wait_for_name_element' do
context 'when simple selector' do
- subject { klass_object.send(:wait_for_bar_element, wait: 10) }
+ subject { klass_object.send(:wait_for_bar_element, text: 'new', wait: 10) }
it do
- expect(klass_object.capybara_context).to receive(:find).with('.someclass', wait: 10)
+ expect(klass_object.capybara_context).to receive(:find)
+ .with('.someclass', wait: 10, text: 'new', match: :first)
is_expected.to eq(nil)
end
end
context 'when lambda selector' do
- subject { klass_object.send(:wait_for_foo_element, 'Hello', 'super', wait: 10) }
+ subject { klass_object.send(:wait_for_foo_element, 'Hello', 'super', text: 'new', wait: 10) }
it do
expect(
klass_object.capybara_context
- ).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10)
+ ).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
is_expected.to eq(nil)
end
end
end
describe '#within_name_element' do
@@ -149,80 +154,88 @@
after { subject }
context 'not nested' do
context 'when simple selector' do
subject do
klass_object.instance_eval do
- within_bar_element(wait: 10) do
- foo_element('Hello', 'super', wait: 10)
+ within_bar_element(wait: 5, text: 'new') do
+ foo_element('Hello', 'super', wait: 10, text: 'new')
end
end
end
it do
- expect(klass_object.capybara_context).to receive(:find).with('.someclass', wait: 10) { within_scope }
- expect(within_scope).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10)
+ expect(klass_object.capybara_context).to receive(:find)
+ .with('.someclass', wait: 5, text: 'new', match: :first) { within_scope }
+ expect(within_scope).to receive(:find)
+ .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
end
end
context 'when lambda selector' do
subject do
klass_object.instance_eval do
- within_foo_element('Hello', 'super', wait: 10) do
- bar_element(wait: 10)
+ within_foo_element('Hello', 'super', wait: 10, text: 'new') do
+ bar_element(wait: 10, text: 'new')
end
end
end
it do
- expect(
- klass_object.capybara_context
- ).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10) { within_scope }
- expect(within_scope).to receive(:find).with('.someclass', wait: 10)
+ expect(klass_object.capybara_context).to receive(:find)
+ .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first) { within_scope }
+ expect(within_scope).to receive(:find).with('.someclass', wait: 10, text: 'new', match: :first)
end
end
end
context 'nested' do
let(:nested_within_scope) { double }
subject do
klass_object.instance_eval do
- within_top_panel_element(wait: 10) do
- within_bar_element(wait: 10) do
- foo_element('Hello', 'super', wait: 10)
+ within_top_panel_element(wait: 10, text: 'new') do
+ within_bar_element(wait: 10, text: 'new') do
+ foo_element('Hello', 'super', wait: 10, text: 'new')
end
end
end
end
it do
- expect(klass_object.capybara_context).to receive(:find).with('.top', wait: 10) { within_scope }
- expect(within_scope).to receive(:find).with('.someclass', wait: 10) { nested_within_scope }
- expect(nested_within_scope).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10)
+ expect(klass_object.capybara_context).to receive(:find)
+ .with('.top', wait: 10, text: 'new', match: :first) { within_scope }
+ expect(within_scope).to receive(:find)
+ .with('.someclass', wait: 10, text: 'new', match: :first) { nested_within_scope }
+ expect(nested_within_scope).to receive(:find)
+ .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
end
end
end
describe '#has_name_element?' do
after { subject }
context 'when simple selector' do
- subject { klass_object.send(:has_bar_element?, wait: 10) }
- it { expect(klass_object.capybara_context).to receive(:has_selector?).with('.someclass', wait: 10) }
+ subject { klass_object.send(:has_bar_element?, wait: 10, text: 'new') }
+ it do
+ expect(klass_object.capybara_context).to receive(:has_selector?)
+ .with('.someclass', wait: 10, text: 'new', match: :first)
+ end
end
context 'when lambda selector' do
- subject { klass_object.send(:has_foo_element?, 'Hello', 'super', wait: 10) }
+ subject { klass_object.send(:has_foo_element?, 'Hello', 'super', wait: 10, text: 'new') }
it do
- expect(
- klass_object.capybara_context
- ).to receive(:has_selector?).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10)
+ expect(klass_object.capybara_context).to receive(:has_selector?)
+ .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
end
end
end
describe '#has_no_name_element?' do
after { subject }
context 'when simple selector' do
- subject { klass_object.send(:has_no_bar_element?, wait: 10) }
- it { expect(klass_object.capybara_context).to receive(:has_no_selector?).with('.someclass', wait: 10) }
+ subject { klass_object.send(:has_no_bar_element?, wait: 10, text: 'new') }
+ it do
+ expect(klass_object.capybara_context).to receive(:has_no_selector?)
+ .with('.someclass', wait: 10, text: 'new', match: :first)
+ end
end
context 'when lambda selector' do
- subject { klass_object.send(:has_no_foo_element?, 'Hello', 'super', wait: 10) }
+ subject { klass_object.send(:has_no_foo_element?, 'Hello', 'super', wait: 10, text: 'new', match: :first) }
it do
- expect(
- klass_object.capybara_context
- ).to receive(:has_no_selector?).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10)
+ expect(klass_object.capybara_context).to receive(:has_no_selector?)
+ .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
end
end
end
end
end