spec/watirspec/elements/element_spec.rb in watir-6.16.5 vs spec/watirspec/elements/element_spec.rb in watir-6.17.0
- old
+ new
@@ -102,28 +102,34 @@
it 'finds elements by visible text' do
browser.goto WatirSpec.url_for('non_control_elements.html')
expect(browser.element(visible_text: 'all visible')).to exist
expect(browser.element(visible_text: /all visible/)).to exist
- expect(browser.element(visible_text: 'some visible')).to exist
expect(browser.element(visible_text: /some visible/)).to exist
- expect(browser.element(visible_text: 'none visible')).not_to exist
- expect(browser.element(visible_text: /none visible/)).not_to exist
-
expect(browser.element(visible_text: 'Link 2', class: 'external')).to exist
expect(browser.element(visible_text: /Link 2/, class: 'external')).to exist
end
+ bug 'Safari is not filtering out hidden text', :safari do
+ it 'finds elements by visible text in spite of hidden text' do
+ browser.goto WatirSpec.url_for('non_control_elements.html')
+
+ expect(browser.element(visible_text: 'some visible')).to exist
+ expect(browser.element(visible_text: 'none visible')).not_to exist
+ expect(browser.element(visible_text: /none visible/)).not_to exist
+ end
+ end
+
it 'raises exception unless value is a String or a RegExp' do
browser.goto WatirSpec.url_for('non_control_elements.html')
- msg = /expected one of \[String, Regexp\], got 7\:(Fixnum|Integer)/
+ msg = /expected one of \[String, Regexp\], got 7:Integer/
expect { browser.element(visible_text: 7).exists? }.to raise_exception(TypeError, msg)
end
it 'raises exception unless key is valid' do
browser.goto WatirSpec.url_for('non_control_elements.html')
- msg = /Unable to build XPath using 7:(Fixnum|Integer)/
+ msg = /Unable to build XPath using 7:Integer/
expect { browser.element(7 => /foo/).exists? }.to raise_exception(Watir::Exception::Error, msg)
end
end
describe 'finding with unknown tag name' do
@@ -223,47 +229,44 @@
end
end
describe '#visible?' do
it 'returns true if the element is visible' do
- msg = /WARN Watir \[\"visible_element\"\]/
+ 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\"\]/
+ 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 'raises UnknownObjectException exception if the element is stale' do
+ it 'handles staleness' do
element = browser.text_field(id: 'new_user_email').locate
- browser.refresh
+ allow(element).to receive(:stale?).and_return(true)
- expect(element).to be_stale
- expect {
- expect { element.visible? }.to raise_unknown_object_exception
- }.to have_deprecated_stale_visible
+ 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\"\]/
+ 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\"\]/
+ 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
@@ -293,30 +296,25 @@
wd = browser.div.wd
element = Watir::Element.new(browser, id: 'not_valid')
element.cache = wd
browser.refresh
- expect {
- expect(element).to_not exist
- }.to have_deprecated_stale_exists
+ expect(element).to_not exist
end
end
describe '#exists?' do
before do
browser.goto WatirSpec.url_for('removed_element.html')
end
- it 'element from a collection returns false when it becomes stale' do
+ it 'handles staleness in a collection' do
element = browser.divs(id: 'text').first.locate
- browser.refresh
+ allow(element).to receive(:stale?).and_return(true)
- expect(element).to be_stale
- expect {
- expect(element).to_not exist
- }.to have_deprecated_stale_exists
+ expect(element).to exist
end
it 'returns false when tag name does not match id' do
watir_element = browser.span(id: 'text')
expect(watir_element).to_not exist
@@ -338,40 +336,15 @@
it 'returns false if the element does not exist' do
expect(browser.div(id: 'should-not-exist')).to_not be_present
end
- it 'returns false if the element is stale' do
+ it 'handles staleness' do
element = browser.div(id: 'foo').locate
- browser.refresh
+ allow(element).to receive(:stale?).and_return(true)
- expect(element).to be_stale
-
- expect {
- expect(element).to_not be_present
- }.to have_deprecated_stale_present
- end
-
- it 'does not raise staleness deprecation if element no longer exists in DOM' do
- element = browser.div(id: 'foo').locate
- browser.goto(WatirSpec.url_for('iframes.html'))
-
- expect { element.present? }.to_not have_deprecated_stale_present
- end
-
- # TODO: Documents Current Behavior, but needs to be refactored/removed
- it 'returns true the second time if the element is stale' do
- element = browser.div(id: 'foo').locate
-
- browser.refresh
-
- expect(element).to be_stale
-
- expect {
- expect(element).to_not be_present
- }.to have_deprecated_stale_present
expect(element).to be_present
end
end
describe '#enabled?' do
@@ -533,12 +506,12 @@
receiver.send_keys 'hello', 'world'
expect(receiver.value).to eq 'helloworld'
expect(events).to eq 10
end
- bug 'http://code.google.com/p/chromium/issues/detail?id=93879', :chrome do
- not_compliant_on :safari, :firefox do
+ bug 'http://code.google.com/p/chromium/issues/detail?id=93879', %i[chrome macosx] do
+ bug 'special keys are not working correctly', :safari, :firefox do
it 'performs key combinations' do
receiver.send_keys 'foo'
receiver.send_keys [@c, 'a']
receiver.send_keys :backspace
expect(receiver.value).to be_empty
@@ -560,18 +533,18 @@
end
end
end
describe '#click' do
- bug 'https://github.com/mozilla/geckodriver/issues/1375', :firefox do
- it 'accepts modifiers' do
- begin
+ bug 'Element has been located but Safari does not recognize it', :safari do
+ bug 'https://bugs.chromium.org/p/chromedriver/issues/detail?id=2732', :w3c do
+ it 'accepts modifiers' do
browser.a.click(:shift)
+ browser.wait_until { |b| b.windows.size > 1 }
expect(browser.windows.size).to eq 2
ensure
browser.windows.reject(&:current?).each(&:close)
- expect(browser.windows.size).to eq 1
end
end
end
end
@@ -595,16 +568,17 @@
expect(h2.flash(:long)).to eq h2
end
end
describe '#hover' do
- not_compliant_on :internet_explorer, :safari do
+ not_compliant_on :internet_explorer do
it 'should hover over the element' do
browser.goto WatirSpec.url_for('hover.html')
link = browser.a
expect(link.style('font-size')).to eq '10px'
+ link.scroll.to
link.hover
link.wait_until { |l| l.style('font-size') == '20px' }
expect(link.style('font-size')).to eq '20px'
end
end
@@ -701,23 +675,26 @@
element.select_text('all visible')
expect(element.selected_text).to eq 'all visible'
end
end
- not_compliant_on %i[remote firefox] do
- describe '#scroll_into_view' do
- it 'scrolls element into view' do
- el = browser.button(name: 'new_user_image')
- element_center = el.center['y']
+ describe '#scroll_into_view' do
+ it 'scrolls element into view' do
+ initial_size = browser.window.size
+ browser.window.resize_to(initial_size.width, 800)
- bottom_viewport_script = 'return window.pageYOffset + window.innerHeight'
- expect(browser.execute_script(bottom_viewport_script)).to be < element_center
+ 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
+ expect(browser.execute_script(bottom_viewport_script)).to be > element_center
end
end
describe '#location' do
it 'returns coordinates for element location' do
@@ -900,35 +877,38 @@
end
describe '#obscured?' do
before { browser.goto WatirSpec.url_for('obscured.html') }
- it 'returns false if element\'s center is not covered' do
+ it 'returns false if element center is not covered' do
btn = browser.button(id: 'not_obscured')
expect(btn).not_to be_obscured
expect { btn.click }.not_to raise_exception
end
- it 'returns false if element\'s center is covered by its descendant' do
+ it 'returns false if element center is covered by its descendant' do
btn = browser.button(id: 'has_descendant')
expect(btn).not_to be_obscured
expect { btn.click }.not_to raise_exception
end
- it 'returns true if element\'s center is covered by a non-descendant' do
+ it 'returns true if element center is covered by a non-descendant' do
btn = browser.button(id: 'obscured')
expect(btn).to be_obscured
- not_compliant_on :chrome do
+ not_compliant_on :chrome, :safari do
expect { btn.click }.to raise_exception(Selenium::WebDriver::Error::ElementClickInterceptedError)
end
compliant_on :chrome do
- expect { btn.click }.to raise_exception(Selenium::WebDriver::Error::UnknownError)
+ expect { btn.click }.to raise_exception(Selenium::WebDriver::Error::ElementClickInterceptedError)
end
+ compliant_on :safari do
+ expect { btn.click }.to raise_exception(Selenium::WebDriver::Error::WebDriverError)
+ end
end
not_compliant_on %i[firefox appveyor] do
- it 'returns false if element\'s center is surrounded by non-descendants' do
+ it 'returns false if element center is surrounded by non-descendants' do
btn = browser.button(id: 'surrounded')
expect(btn).not_to be_obscured
expect { btn.click }.not_to raise_exception
end
end
@@ -943,13 +923,15 @@
div = browser.div(id: 'requires_scrolling_container')
expect(div).not_to be_obscured
expect { div.click }.not_to raise_exception
end
- it 'returns true if element cannot be scrolled into view' do
- btn = browser.button(id: 'off_screen')
- expect(btn).to be_obscured
- expect { btn.click }.to raise_unknown_object_exception
+ bug 'Safari is throwing click intercepted here', :safari do
+ it 'returns true if element cannot be scrolled into view' do
+ btn = browser.button(id: 'off_screen')
+ expect(btn).to be_obscured
+ expect { btn.click }.to raise_unknown_object_exception
+ end
end
it 'returns true if element is hidden' do
btn = browser.button(id: 'hidden')
expect(btn).to be_obscured