spec/watirspec/elements/element_spec.rb in watir-6.19.1 vs spec/watirspec/elements/element_spec.rb in watir-7.0.0.beta1
- old
+ new
@@ -18,16 +18,10 @@
it 'raises ArgumentError if given the wrong number of arguments' do
container = double('container').as_null_object
expect { Watir::Element.new(container, 1, 2, 3, 4) }.to raise_error(ArgumentError)
expect { Watir::Element.new(container, 'foo') }.to raise_error(ArgumentError)
end
-
- it 'throws deprecation warning when combining element locator with other locators' do
- element = double Selenium::WebDriver::Element
- allow(element).to receive(:enabled?).and_return(true)
- expect { browser.text_field(class_name: 'name', index: 1, element: element) }.to have_deprecated_element_cache
- end
end
describe '#element_call' do
it 'handles exceptions when taking an action on a stale element' do
browser.goto WatirSpec.url_for('removed_element.html')
@@ -38,17 +32,15 @@
expect(element).to be_stale
expect { element.text }.to_not raise_error
end
- compliant_on :relaxed_locate do
- it 'relocates stale element when taking an action on it' do
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
- element = browser.text_field(id: 'new_user_first_name').locate
- browser.refresh
- expect { element.click }.not_to raise_exception
- end
+ it 'relocates stale element when taking an action on it' do
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
+ element = browser.text_field(id: 'new_user_first_name').locate
+ browser.refresh
+ expect { element.click }.not_to raise_exception
end
end
describe '#eq and #eql?' do
before { browser.goto WatirSpec.url_for('definition_lists.html') }
@@ -227,60 +219,10 @@
browser.text_field(id: 'new_user_occupation').fire_event('onfocus')
expect(browser.div(id: 'onfocus_test').text).to eq 'changed by onfocus event'
end
end
- describe '#visible?' do
- it 'returns true if the element is visible' do
- msg = /WARN Watir \["visible_element"\]/
- expect {
- expect(browser.text_field(id: 'new_user_email')).to be_visible
- }.to output(msg).to_stdout_from_any_process
- end
-
- it 'raises UnknownObjectException exception if the element does not exist' do
- msg = /WARN Watir \["visible_element"\]/
- expect {
- expect { browser.text_field(id: 'no_such_id').visible? }.to raise_unknown_object_exception
- }.to output(msg).to_stdout_from_any_process
- end
-
- it 'handles staleness' do
- element = browser.text_field(id: 'new_user_email').locate
-
- allow(element).to receive(:stale?).and_return(true)
-
- expect(element).to be_visible
- end
-
- it "returns true if the element has style='visibility: visible' even if parent has style='visibility: hidden'" do
- msg = /WARN Watir \["visible_element"\]/
- expect {
- expect(browser.div(id: 'visible_child')).to be_visible
- }.to output(msg).to_stdout_from_any_process
- end
-
- it "returns false if the element is input element where type eq 'hidden'" do
- expect(browser.hidden(id: 'new_user_interests_dolls')).to_not be_visible
- end
-
- it "returns false if the element has style='display: none;'" do
- msg = /WARN Watir \["visible_element"\]/
- expect {
- expect(browser.div(id: 'changed_language')).to_not be_visible
- }.to output(msg).to_stdout_from_any_process
- end
-
- it "returns false if the element has style='visibility: hidden;" do
- expect { expect(browser.div(id: 'wants_newsletter')).to_not be_visible }
- end
-
- it 'returns false if one of the parent elements is hidden' do
- expect { expect(browser.div(id: 'hidden_parent')).to_not be_visible }
- end
- end
-
describe '#cache=' do
it 'bypasses selector location' do
browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
wd = browser.div.wd
@@ -305,18 +247,40 @@
describe '#exists?' do
before do
browser.goto WatirSpec.url_for('removed_element.html')
end
- it 'handles staleness in a collection' do
+ it 'element from a collection is re-looked up after it becomes stale' do
element = browser.divs(id: 'text').first.locate
- allow(element).to receive(:stale?).and_return(true)
+ browser.refresh
+ expect(element).to be_stale
expect(element).to exist
end
+ it 'element from a selenium element throws an exception when relocated' do
+ div = browser.div.locate
+ element = browser.element(element: div.wd)
+
+ browser.refresh
+ expect(element).to be_stale
+
+ msg = 'Can not relocate a Watir element initialized by a Selenium element'
+ expect { element.exists? }.to raise_exception(Watir::Exception::LocatorException, msg)
+ end
+
+ it 'element from a selenium element with other locators throws an exception' do
+ div = browser.div.locate
+ element = browser.element(element: div.wd, id: 'foo')
+
+ browser.refresh
+
+ msg = 'Can not relocate a Watir element initialized by a Selenium element'
+ expect { element.exists? }.to raise_exception(Watir::Exception::LocatorException, msg)
+ end
+
it 'returns false when tag name does not match id' do
watir_element = browser.span(id: 'text')
expect(watir_element).to_not exist
end
end
@@ -372,10 +336,19 @@
browser.refresh
expect(element).to be_stale
end
+ it 'returns true the second time if the element is stale' do
+ element = browser.div.locate
+
+ browser.refresh
+
+ expect(element).to be_stale
+ expect(element).to be_stale
+ end
+
it 'returns false if the element is not stale' do
element = browser.button(name: 'new_user_submit_disabled').locate
expect(element).to_not be_stale
end
@@ -672,28 +645,9 @@
it 'selects text and returns selected text' do
browser.goto WatirSpec.url_for('non_control_elements.html')
element = browser.element(visible_text: 'all visible')
element.select_text('all visible')
expect(element.selected_text).to eq 'all visible'
- end
- end
-
- describe '#scroll_into_view' do
- it 'scrolls element into view' do
- initial_size = browser.window.size
- browser.window.resize_to(initial_size.width, 800)
-
- el = browser.button(name: 'new_user_image')
- element_center = el.center['y']
-
- bottom_viewport_script = 'return window.pageYOffset + window.innerHeight'
- expect(browser.execute_script(bottom_viewport_script)).to be < element_center
-
- expect {
- expect(el.scroll_into_view).to be_a Selenium::WebDriver::Point
- }.to have_deprecated_scroll_into_view
-
- expect(browser.execute_script(bottom_viewport_script)).to be > element_center
end
end
describe '#location' do
it 'returns coordinates for element location' do