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
Time_Ago_In_Words and Localize
Using Named Captures with Regex Match in Ruby's Case...When
Constants or Class Variables in Ruby
How to Iterate Through an Array Starting from the Last Element? (Ruby)
How to Make Rake Tasks Run Under My Sinantra App/Environment
Ruby on Rails - Differentiating Plural VS Singular Resource in a Rest API
How to Recursively Require All Files in a Directory in Ruby
Rails: Why Images Are Not Showing in My Rails Basic App
How to Run My Ruby Code After Rails Server Start
How to Run Irb.Start in Context of Current Class
How to Convert String to Bytes in Ruby
In Ruby, Should I Use ||= or If Defined? for Memoization
Deleting While Iterating in Ruby
Generating a Short Uuid String Using Uuidtools in Rails
Certificate Verify Failed in "Gem Install Foundation"
Ruby: Build Failed (Macos 11.2 Using Ruby-Build 20210119) MAC Big Sur
How to Prevent Pipe Character from Causing a Bad Uri Error in Rails 3/Ruby 1.9.2
How to Load Some Activerecord Models from a Yaml File and Save Them to the Db