Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Metrics/ModuleLength:
Max: 602

Metrics/PerceivedComplexity:
Max: 14
Max: 15

plugins:
- rubocop-rake
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- Ferrum is bumped to `~> 0.19.0`

### Fixed
- `window_size: nil` raised `Ferrum::BrowserError: Invalid parameters` on every page instead of leaving the window
size to Chrome, so `start-maximized` couldn't be used [#278]
- `Driver#reset!` kept the page it had cached when the browser failed to reset, so every later example raised
`Session with given id not found` or `Browser is dead or given window is closed` instead of starting on a fresh
page [#274], [rubycdp/ferrum#641]
Expand Down
3 changes: 3 additions & 0 deletions docs/2-customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ Capybara::Cuprite::Driver.new(app, timeout: 15, process_timeout: 30)
# Connect to a remote browser
Capybara::Cuprite::Driver.new(app, url: "http://chrome:3333")

# Leave the window size to Chrome, e.g. to start maximized in headful mode
Capybara::Cuprite::Driver.new(app, headless: false, window_size: nil, browser_options: { "start-maximized" => nil })

# Emulate an iPhone 14
Capybara::Cuprite::Driver.new(app, emulate: :iphone_14)

Expand Down
3 changes: 2 additions & 1 deletion docs/9-windows-frames.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ Returns inner width and height of the window.
page.current_window.size # => [1024, 768]
```

The window size is reset to `:window_size` at the end of every test.
The window size is reset to `:window_size` at the end of every test. With `window_size: nil` Cuprite doesn't
set the size, so Chrome's own one, or `start-maximized`, applies.

## Frames

Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/cuprite/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def prepare_page
super

width, height = @options.window_size
resize(width: width, height: height)
width && height ? resize(width: width, height: height) : set_viewport
command("Network.setUserAgentOverride", userAgent: default_user_agent) if @options.device_user_agent

if @options.url_blacklist.any?
Expand Down
19 changes: 19 additions & 0 deletions spec/features/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,25 @@ def session_url(path)
driver&.quit
end

it "leaves the window size to the browser when the option is nil" do
Capybara.register_driver :cuprite_without_window_size do |app|
Capybara::Cuprite::Driver.new(app, window_size: nil)
end
driver = Capybara::Session.new(:cuprite_without_window_size, TestApp).driver
driver.visit(session_url("/"))
default_size = driver.evaluate_script("[window.innerWidth, window.innerHeight]")
expect(default_size).not_to eq([1024, 768])

driver.resize(800, 600)
expect(driver.evaluate_script("[window.innerWidth, window.innerHeight]")).to eq([800, 600])

driver.reset!
driver.visit(session_url("/"))
expect(driver.evaluate_script("[window.innerWidth, window.innerHeight]")).to eq(default_size)
ensure
driver&.quit
end

shared_examples "render screen" do
it "supports rendering the whole of a page that goes outside the viewport" do
@session.visit("/cuprite/long_page")
Expand Down
Loading