Skip to content

Commit b4c1a21

Browse files
committed
#get_position, #set_position implemented, resolves #115
1 parent 7f38bf3 commit b4c1a21

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/ferrum/browser.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ def resize(**options)
108108
page.resize(**options)
109109
end
110110

111+
def get_position
112+
page.get_position
113+
end
114+
115+
def set_position(left, top)
116+
page.set_position(left, top)
117+
end
118+
111119
def crash
112120
command("Browser.crash")
113121
end

lib/ferrum/page.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ def resize(width: nil, height: nil, fullscreen: false)
107107
fitWindow: false)
108108
end
109109

110+
def get_position
111+
@window_id = @browser.command("Browser.getWindowForTarget", targetId: @target_id)["windowId"]
112+
@browser.command("Browser.getWindowBounds", windowId: @window_id).fetch("bounds").values_at("left", "top")
113+
end
114+
115+
def set_position(left, top)
116+
@window_id = @browser.command("Browser.getWindowForTarget", targetId: @target_id)["windowId"]
117+
@browser.command("Browser.setWindowBounds", windowId: @window_id, bounds: { left: left, top: top })
118+
end
119+
110120
def refresh
111121
command("Page.reload", wait: timeout, slowmoable: true)
112122
end

spec/browser_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ module Ferrum
9696
expect(browser.viewport_size).to eq([200, 400])
9797
end
9898

99+
it "allows the window to be positioned" do
100+
left, top = browser.get_position
101+
browser.set_position left + 10, top + 20
102+
expect(browser.get_position).to eq([left + 10, top + 20])
103+
end
104+
99105
it "allows the page to be scrolled" do
100106
browser.goto("/ferrum/long_page")
101107
browser.resize(width: 10, height: 10)

0 commit comments

Comments
 (0)