spec/watirspec/elements/checkbox_spec.rb in watir-7.2.0 vs spec/watirspec/elements/checkbox_spec.rb in watir-7.2.1

- old
+ new

@@ -1,11 +1,11 @@ # frozen_string_literal: true require 'watirspec_helper' describe 'CheckBox' do - before :each do + before do browser.goto(WatirSpec.url_for('forms_with_input_elements.html')) end # Exists method @@ -26,20 +26,21 @@ expect(browser.checkbox(class: /fun/)).to exist expect(browser.checkbox(index: 0)).to exist expect(browser.checkbox(xpath: "//input[@id='new_user_interests_books']")).to exist end - # TODO: More of this for text & labels somewhere central - it 'handles text_regexp deprecations for label locators' do - expect(browser.checkbox(label: /some visible/)).to exist - expect(browser.checkbox(label: /some (visible|Jeff)/)).to exist - expect(browser.checkbox(label: /none visible/)).to exist - expect(browser.checkbox(label: /this will not match/)).to_not exist - end + context 'when some text hidden' do + it 'locates matching hidden text' do + expect(browser.checkbox(label: /some visible/)).to exist + expect(browser.checkbox(label: /some (visible|Jeff)/)).to exist + expect(browser.checkbox(label: /none visible/)).to exist + expect(browser.checkbox(label: /some visible some hidden/)).to exist + end - it 'handles text_regexp deprecation in spite of hidden text' do - expect(browser.checkbox(label: /some visible some hidden/)).to exist + it 'does not locate when matches without hidden text' do + expect(browser.checkbox(label: /some visible$/)).not_to exist + end end it 'returns true if the checkbox button exists (search by name and value)' do expect(browser.checkbox(name: 'new_user_interests', value: 'cars')).to exist browser.checkbox(xpath: "//input[@name='new_user_interests' and @value='cars']").set @@ -48,29 +49,29 @@ it 'returns the first checkbox if given no args' do expect(browser.checkbox).to exist end it 'returns false if the checkbox button does not exist' do - expect(browser.checkbox(id: 'no_such_id')).to_not exist - expect(browser.checkbox(id: /no_such_id/)).to_not exist - expect(browser.checkbox(name: 'no_such_name')).to_not exist - expect(browser.checkbox(name: /no_such_name/)).to_not exist - expect(browser.checkbox(value: 'no_such_value')).to_not exist - expect(browser.checkbox(value: /no_such_value/)).to_not exist - expect(browser.checkbox(text: 'no_such_text')).to_not exist - expect(browser.checkbox(text: /no_such_text/)).to_not exist - expect(browser.checkbox(class: 'no_such_class')).to_not exist - expect(browser.checkbox(class: /no_such_class/)).to_not exist - expect(browser.checkbox(index: 1337)).to_not exist - expect(browser.checkbox(xpath: "//input[@id='no_such_id']")).to_not exist + expect(browser.checkbox(id: 'no_such_id')).not_to exist + expect(browser.checkbox(id: /no_such_id/)).not_to exist + expect(browser.checkbox(name: 'no_such_name')).not_to exist + expect(browser.checkbox(name: /no_such_name/)).not_to exist + expect(browser.checkbox(value: 'no_such_value')).not_to exist + expect(browser.checkbox(value: /no_such_value/)).not_to exist + expect(browser.checkbox(text: 'no_such_text')).not_to exist + expect(browser.checkbox(text: /no_such_text/)).not_to exist + expect(browser.checkbox(class: 'no_such_class')).not_to exist + expect(browser.checkbox(class: /no_such_class/)).not_to exist + expect(browser.checkbox(index: 1337)).not_to exist + expect(browser.checkbox(xpath: "//input[@id='no_such_id']")).not_to exist end it 'returns false if the checkbox button does not exist (search by name and value)' do - expect(browser.checkbox(name: 'new_user_interests', value: 'no_such_value')).to_not exist - expect(browser.checkbox(xpath: "//input[@name='new_user_interests' and @value='no_such_value']")).to_not exist - expect(browser.checkbox(name: 'no_such_name', value: 'cars')).to_not exist - expect(browser.checkbox(xpath: "//input[@name='no_such_name' and @value='cars']")).to_not exist + expect(browser.checkbox(name: 'new_user_interests', value: 'no_such_value')).not_to exist + expect(browser.checkbox(xpath: "//input[@name='new_user_interests' and @value='no_such_value']")).not_to exist + expect(browser.checkbox(name: 'no_such_name', value: 'cars')).not_to exist + expect(browser.checkbox(xpath: "//input[@name='no_such_name' and @value='cars']")).not_to exist end it 'returns true for checkboxes with a string value' do expect(browser.checkbox(name: 'new_user_interests', value: 'books')).to exist expect(browser.checkbox(name: 'new_user_interests', value: 'cars')).to exist @@ -157,21 +158,32 @@ expect(browser.checkbox(index: 0)).to respond_to(:type) expect(browser.checkbox(index: 0)).to respond_to(:value) end end + describe '#tabindex' do + it 'finds tab index' do + expect(browser.checkbox(tabindex: '4').tabindex).to eq 4 + end + + it 'finds element with boolean' do + expect(browser.checkbox(tabindex: false).id).to eq 'toggle_button_checkbox' + expect(browser.checkbox(tabindex: true).id).to eq 'new_user_interests_books' + end + end + # Access methods describe '#enabled?' do it 'returns true if the checkbox button is enabled' do expect(browser.checkbox(id: 'new_user_interests_books')).to be_enabled expect(browser.checkbox(xpath: "//input[@id='new_user_interests_books']")).to be_enabled end it 'returns false if the checkbox button is disabled' do - expect(browser.checkbox(id: 'new_user_interests_dentistry')).to_not be_enabled - expect(browser.checkbox(xpath: "//input[@id='new_user_interests_dentistry']")).to_not be_enabled + expect(browser.checkbox(id: 'new_user_interests_dentistry')).not_to be_enabled + expect(browser.checkbox(xpath: "//input[@id='new_user_interests_dentistry']")).not_to be_enabled end it "raises UnknownObjectException if the checkbox button doesn't exist" do expect { browser.checkbox(id: 'no_such_id').enabled? }.to raise_unknown_object_exception expect { browser.checkbox(xpath: "//input[@id='no_such_id']").enabled? }.to raise_unknown_object_exception @@ -182,11 +194,11 @@ it 'returns true if the checkbox is disabled' do expect(browser.checkbox(id: 'new_user_interests_dentistry')).to be_disabled end it 'returns false if the checkbox is enabled' do - expect(browser.checkbox(id: 'new_user_interests_books')).to_not be_disabled + expect(browser.checkbox(id: 'new_user_interests_books')).not_to be_disabled end it "raises UnknownObjectException if the checkbox doesn't exist" do expect { browser.checkbox(index: 1337).disabled? }.to raise_unknown_object_exception end @@ -194,25 +206,25 @@ # Manipulation methods describe '#clear' do it 'raises ObjectDisabledException if the checkbox is disabled' do - expect(browser.checkbox(id: 'new_user_interests_dentistry')).to_not be_set + expect(browser.checkbox(id: 'new_user_interests_dentistry')).not_to be_set expect { browser.checkbox(id: 'new_user_interests_dentistry').clear } .to raise_object_disabled_exception expect { browser.checkbox(xpath: "//input[@id='new_user_interests_dentistry']").clear } .to raise_object_disabled_exception end it 'clears the checkbox button if it is set' do browser.checkbox(id: 'new_user_interests_books').clear - expect(browser.checkbox(id: 'new_user_interests_books')).to_not be_set + expect(browser.checkbox(id: 'new_user_interests_books')).not_to be_set end it 'clears the checkbox button when found by :xpath' do browser.checkbox(xpath: "//input[@id='new_user_interests_books']").clear - expect(browser.checkbox(xpath: "//input[@id='new_user_interests_books']")).to_not be_set + expect(browser.checkbox(xpath: "//input[@id='new_user_interests_books']")).not_to be_set end it "raises UnknownObjectException if the checkbox button doesn't exist" do expect { browser.checkbox(name: 'no_such_id').clear }.to raise_unknown_object_exception expect { browser.checkbox(xpath: "//input[@id='no_such_id']").clear }.to raise_unknown_object_exception @@ -231,11 +243,11 @@ end it 'fires the onclick event' do expect(browser.button(id: 'disabled_button')).to be_disabled browser.checkbox(id: 'toggle_button_checkbox').set - expect(browser.button(id: 'disabled_button')).to_not be_disabled + expect(browser.button(id: 'disabled_button')).not_to be_disabled browser.checkbox(id: 'toggle_button_checkbox').clear expect(browser.button(id: 'disabled_button')).to be_disabled end it "raises UnknownObjectException if the checkbox button doesn't exist" do @@ -257,18 +269,18 @@ it 'returns true if the checkbox button is set' do expect(browser.checkbox(id: 'new_user_interests_books')).to be_set end it 'returns false if the checkbox button unset' do - expect(browser.checkbox(id: 'new_user_interests_cars')).to_not be_set + expect(browser.checkbox(id: 'new_user_interests_cars')).not_to be_set end it 'returns the state for checkboxes with string values' do - expect(browser.checkbox(name: 'new_user_interests', value: 'cars')).to_not be_set + expect(browser.checkbox(name: 'new_user_interests', value: 'cars')).not_to be_set browser.checkbox(name: 'new_user_interests', value: 'cars').set expect(browser.checkbox(name: 'new_user_interests', value: 'cars')).to be_set browser.checkbox(name: 'new_user_interests', value: 'cars').clear - expect(browser.checkbox(name: 'new_user_interests', value: 'cars')).to_not be_set + expect(browser.checkbox(name: 'new_user_interests', value: 'cars')).not_to be_set end it "raises UnknownObjectException if the checkbox button doesn't exist" do expect { browser.checkbox(id: 'no_such_id').set? }.to raise_unknown_object_exception expect { browser.checkbox(xpath: "//input[@id='no_such_id']").set? }.to raise_unknown_object_exception