Change Default Capybara Browser Window Size

Change default Capybara browser window size

You could define that under before(:all)

describe "Test" do
before(:all) do
...
...
page.driver.browser.manage.window.resize_to(x,y) #Mention it here
end

it "should find everything" do
...
end

after(:all) do
...
end
end

Capybara: How to change window size?

You're creating a session, but then calling resize on a window from a different session. That other session is an auto-generated session using the default driver (rack-test) which doesn't support windows at all. If you want to do this with your manually created session it would just be

session = Capybara::Session.new(:selenium)
session.current_window.resize_to(1920,1080)

Resize Chrome's window while using Capybara

There is resize_to function in Selenium Webdriver that you can use:

page.driver.browser.manage.window.resize_to(1024, 768)

Window has some other methods that may be useful.

How to set Browser Window size in Rspec (Selenium)

You can use the resize_to(width, height) method that is part of the selenium webdriver.

For example, the following would make the browser 100px wide and 200px tall:

page.driver.browser.manage.window.resize_to(100,200)

Rails4/Capybara - use the value of the test window width/dimensions inside a test

You shouldn't be using driver specific methods for any of this (any time you're using Capybara.current_session.driver. you're probably doing something wrong). Rather you should be using Capybara's window api - http://www.rubydoc.info/gems/capybara/Capybara/Window

To get the size of the current window

Capybara.current_session.current_window.size

To set the size of the current window

Capybara.current_session.current_window.resize_to(width, height)

How to set screen size for chrome headless system test in rails 5.1?

You simply need to redefine the driver which passes the headless and screen size arguments.

Capybara.register_driver :selenium_chrome_headless do |app|
options = Selenium::WebDriver::Chrome::Options.new

[
"headless",
"window-size=1280x1280",
"disable-gpu" # https://developers.google.com/web/updates/2017/04/headless-chrome
].each { |arg| options.add_argument(arg) }

Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end

RSpec.configure do |config|
config.before(:each, type: :system, js: true) do
driven_by :selenium_chrome_headless
end
end


Related Topics



Leave a reply



Submit