Skip to content

Commit e564871

Browse files
authored
Implement Capybara::Cuprite::Node#rect (#311)
Closes #276 The implementation's call to [toJSON][] is necessary since the object returned by [Element.getBoundingClientRect][] is an instance of [DOMRect][], and is therefore unable to have its keys iterated and serialized back to Cuprite on its own. [Element.getBoundingClientRect]: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect [DOMRect]: https://developer.mozilla.org/en-US/docs/Web/API/DOMRect [toJSON]: segment-boneyard/nightmare#723 (comment)
1 parent e0d70ab commit e564871

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Added
44
- Support time inputs [#245]
55
- Add initial support for shadow_root [#234]
6+
- Support `Capybara::Cuprite::Node#rect` [#276]
67

78
### Changed
89

lib/capybara/cuprite/node.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ def shadow_root
236236
root && self.class.new(driver, root.node)
237237
end
238238

239+
def rect
240+
driver.evaluate_script <<~JS, self
241+
arguments[0].getBoundingClientRect().toJSON()
242+
JS
243+
end
244+
239245
def inspect
240246
%(#<#{self.class} @node=#{@node.inspect}>)
241247
end

spec/features/driver_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,20 @@ def create_screenshot(file, *args)
14471447
end
14481448
end
14491449

1450+
context "find" do
1451+
before { @session.visit("/cuprite/click_coordinates") }
1452+
1453+
it "supports position filters" do
1454+
box = @session.find(:css, "#box")
1455+
log = @session.find(:css, "#log")
1456+
1457+
expect(@session).to have_element(id: "box", above: log)
1458+
expect(@session).to have_element(id: "log", below: box)
1459+
expect(@session).not_to have_element(id: "box", below: log)
1460+
expect(@session).not_to have_element(id: "log", above: box)
1461+
end
1462+
end
1463+
14501464
context "set" do
14511465
before { @session.visit("/cuprite/set") }
14521466

0 commit comments

Comments
 (0)