spec/druid/elements/element_spec.rb in druid-ts-1.2.4 vs spec/druid/elements/element_spec.rb in druid-ts-1.2.5
- old
+ new
@@ -54,56 +54,61 @@
it "should know its value" do
expect(we).to receive(:value).and_return('value')
expect(element.value).to eql 'value'
end
- it "should know how to retrieve the value of an attribute" do
- expect(we).to receive(:attribute_value).with('class').and_return('tim')
- expect(element.attribute('class')).to eql 'tim'
- end
-
it "should be clickable" do
expect(we).to receive(:click)
element.click
end
+ it "should check if the element is visible" do
+ expect(we).to receive(:visible?).and_return(false)
+ expect(we).to receive(:visible?).and_return(true)
+ expect(element.check_visible).to be true
+ end
+
+ it "should check if the element exists" do
+ expect(we).to receive(:exists?).and_return(false)
+ expect(we).to receive(:exists?).and_return(true)
+ expect(element.check_exist).to be true
+ end
+
it "should be able to block until it is present" do
- expect(we).to receive(:wait_until).with(timeout: 10, message: "Element not present in 10 seconds")
+ allow(we).to receive(:wait_until).with(timeout: 10, message: "Element not present in 10 seconds")
element.when_present(10)
end
it "should return the element when it is present" do
- expect(we).to receive(:wait_until).with(timeout: 10, message: "Element not present in 10 seconds")
- expect(element.when_present(10)).to eq element
+ allow(we).to receive(:wait_until).with(timeout: 10, message: "Element not present in 10 seconds")
+ new_element = element.when_present(10)
+ expect(new_element).to eql element
end
it "should use the overriden wait when set" do
Druid.default_element_wait = 20
- expect(we).to receive(:wait_until).with(timeout: 20, message: "Element not present in 20 seconds")
+ allow(we).to receive(:wait_until).with(timeout: 20, message: "Element not present in 20 seconds")
element.when_present
end
it "should be able to block until it is visible" do
allow(we).to receive(:wait_until).with(timeout: 10, message: "Element not present in 10 seconds")
- expect(we).to receive(:wait_until).with(timeout: 10, message: "Element not visible in 10 seconds")
- element.when_visible(10)
+ allow(we).to receive(:wait_until).with(timeout: 10, message: "Element not visible in 10 seconds")
+ allow(we).to receive(:displayed?).and_return(true)
+ new_element = element.when_visible(10)
+ expect(new_element).to eql element
end
- it "should return the element when it is visible" do
- allow(we).to receive(:wait_until).with(timeout: 10, message: "Element not present in 10 seconds")
- expect(we).to receive(:wait_until).with(timeout: 10, message: "Element not visible in 10 seconds")
- expect(element.when_visible(10)).to eq element
- end
-
it "should be able to block until it is not visible" do
allow(we).to receive(:wait_until).with(timeout: 10, message: "Element not present in 10 seconds")
- expect(we).to receive(:wait_while).with(timeout: 10, message: "Element still visible after 10 seconds")
+ allow(we).to receive(:wait_while).with(timeout: 10, message: "Element still visible after 10 seconds")
+ allow(we).to receive(:displayed?).and_return(false)
element.when_not_visible(10)
end
it "should be able to block until a user define event fires true" do
- expect(we).to receive(:wait_until).with(timeout: 10, message: "Element blah")
+ allow(we).to receive(:wait_until).with(timeout: 10, message: "Element blah")
element.wait_until(10, "Element blah") {true}
end
it "should send keys to the element" do
expect(we).to receive(:send_keys).with([:control, 'a'])
@@ -148,98 +153,92 @@
it "should be able to focus element" do
expect(we).to receive(:focus)
element.focus
end
- it "should check if the element is visible" do
- expect(we).to receive(:visible?).and_return(false)
- expect(we).to receive(:visible?).and_return(true)
- expect(element.check_visible).to be true
- end
-
- it "should check if the element exists" do
- expect(we).to receive(:exist?).and_return(false)
- expect(we).to receive(:exist?).and_return(true)
- expect(element.check_exist).to be true
- end
-
it "should know if the element is disabled" do
expect(we).to receive(:enabled?).and_return(false)
expect(element).to be_disabled
end
it "should be able to flash element" do
expect(we).to receive(:flash)
element.flash
end
- it "should scroll into view" do
- expect(we).to receive(:wd).and_return(we)
- expect(we).to receive(:location_once_scrolled_into_view)
- element.scroll_into_view
+ it "should return the outer html" do
+ expect(we).to receive(:outer_html).and_return("<div>blah</div>")
+ element.outer_html
end
- it "should know its location" do
- expect(we).to receive(:wd).and_return(we)
- expect(we).to receive(:location)
- element.location
+ it "should return the inner html" do
+ expect(we).to receive(:inner_html).and_return("blah")
+ element.inner_html
end
- it "should know its size" do
- expect(we).to receive(:wd).and_return(we)
- expect(we).to receive(:size)
- element.size
+ it "should know if it is stale" do
+ expect(we).to receive(:stale?).and_return(false)
+ expect(element.stale?).to be false
end
+ end
+ context 'walking the dom' do
+ let(:found) { double('found').as_null_object }
- it "should have a height" do
- expect(we).to receive(:wd).and_return(we)
- expect(we).to receive(:size).and_return({'width' => 30, 'height' => 20})
- expect(element.height).to eql 20
+ before do
+ allow(found).to receive(:tag_name).and_return(:span)
end
- it "should have a width" do
- expect(we).to receive(:wd).and_return(we)
- expect(we).to receive(:size).and_return({'width' => 30, 'height' => 20})
- expect(element.width).to eql 30
+ it 'should find the parent object' do
+ expect(we).to receive(:parent).and_return(found)
+ object = element.parent
+ expect(object).to be_a(Druid::Elements::Span)
+ expect(object.tag_name).to eql :span
end
- it "should have a centre" do
- allow(we).to receive(:wd).and_return(we)
- allow(we).to receive(:location).and_return({'y' => 80, 'x' => 40})
- allow(we).to receive(:size).and_return({'width' => 30, 'height' => 20})
- expect(element.centre).to include(
- 'y' => 90,
- 'x' => 55
- )
+ it 'should find the proceeding sibling' do
+ expect(we).to receive(:preceding_sibling).and_return(found)
+ object = element.preceding_sibling
+ expect(object).to be_a(Druid::Elements::Span)
+ expect(object.tag_name).to eql :span
end
- it "should have a centre greater than y position" do
- allow(we).to receive(:wd).and_return(we)
- allow(we).to receive(:location).and_return({'y' => 80, 'x' => 40})
- allow(we).to receive(:size).and_return({'width' => 30, 'height' => 20})
- expect(element.centre['y']).to be > element.location['y']
+ it 'should find the following sibling' do
+ expect(we).to receive(:following_sibling).and_return(found)
+ object = element.following_sibling
+ expect(object).to be_a(Druid::Elements::Span)
+ expect(object.tag_name).to eql :span
end
- it "should have a centre greater than x position" do
- allow(we).to receive(:wd).and_return(we)
- allow(we).to receive(:location).and_return({'y' => 80, 'x' => 40})
- allow(we).to receive(:size).and_return({'width' => 30, 'height' => 20})
- expect(element.centre['x']).to be > element.location['x']
+ it 'should find all of its siblings' do
+ expect(we).to receive(:siblings).and_return([found, found])
+ results = element.siblings
+ expect(results.size).to eql 2
+ expect(results[0]).to be_a(Druid::Elements::Span)
+ expect(results[1]).to be_a(Druid::Elements::Span)
end
- it "should return the outer html" do
- expect(we).to receive(:outer_html).and_return("<div>blah</div>")
- element.outer_html
+ it 'should find all of its children' do
+ expect(we).to receive(:children).and_return([found, found])
+ results = element.children
+ expect(results.size).to eql 2
+ expect(results[0]).to be_a(Druid::Elements::Span)
+ expect(results[1]).to be_a(Druid::Elements::Span)
end
- it "should return the inner html" do
- expect(we).to receive(:inner_html).and_return("blah")
- element.inner_html
+ it 'should find all of the preceding siblings' do
+ expect(we).to receive(:preceding_siblings).and_return([found, found])
+ results = element.preceding_siblings
+ expect(results.size).to eql 2
+ expect(results[0]).to be_a(Druid::Elements::Span)
+ expect(results[1]).to be_a(Druid::Elements::Span)
end
- it "should know if it is stale" do
- expect(we).to receive(:stale?).and_return(false)
- expect(element.stale?).to be false
+ it 'should find all of the following siblings' do
+ expect(we).to receive(:following_siblings).and_return([found, found])
+ results = element.following_siblings
+ expect(results.size).to eql 2
+ expect(results[0]).to be_a(Druid::Elements::Span)
+ expect(results[1]).to be_a(Druid::Elements::Span)
end
end
end