Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions rb/lib/selenium/webdriver/bidi/browsing_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ def create(type: nil, context_id: nil)
result = @bidi.send_cmd('browsingContext.create', type: type.to_s, referenceContext: context_id)
result['context']
end

def set_viewport(context_id: nil, width: nil, height: nil, device_pixel_ratio: nil)
context_id ||= @bridge.window_handle
params = {context: context_id, viewport: {width:, height:}, device_pixel_ratio:}
@bidi.send_cmd('browsingContext.setViewport', **params)
end
end
end # BiDi
end # WebDriver
Expand Down
2 changes: 2 additions & 0 deletions rb/sig/lib/selenium/webdriver/bidi/browsing_context.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module Selenium

def navigate: (String url, String? context_id) -> void

def set_viewport: (String context_id, Integer width, Integer height, Float device_pixel_ratio) -> Hash[nil, nil]

def traverse_history: (Integer delta, String? context_id) -> void

def reload: (String? context_id, ?ignore_cache: bool) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ class BiDi
expect(handles).to include(window1)
expect(handles).not_to include(window2)
end

it 'sets the viewport' do
reset_driver!(web_socket_url: true) do |driver|
browsing_context = described_class.new(driver)
browsing_context.set_viewport(width: 800, height: 600, device_pixel_ratio: 2.0)
expect(driver.execute_script('return [window.innerWidth, window.innerHeight]')).to eq([800, 600])
expect(driver.execute_script('return window.devicePixelRatio')).to eq(2.0)
end
end
end
end # BiDi
end # WebDriver
Expand Down
Loading