Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize Chrome's window while using Capybara

I use Capybara (with selenium) and Chrome, and RSpec. But i would like to change width of browser in some tests. What is the solution in this case?

spec/spec_helper.rb

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

# Using chrome as browser to test in capybara.
Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app, :browser => :chrome)
end

# RSpec config.
RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller    
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = false

  # If true, the base class of anonymous controllers will be inferred
  # automatically. This will be the default behavior in future versions of
  # rspec-rails.
  config.infer_base_class_for_anonymous_controllers = false

  # Clean test database.
  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end
end
like image 556
ExiRe Avatar asked Jan 27 '13 17:01

ExiRe


People also ask

How do I resize my browser window to a specific size?

Chosen solutionPress Alt+Space to bring up the window menu, press S to choose the Size option, use the arrow keys to resize the window, and lastly Enter to confirm. Click the Maximize button in the top right corner of the window. Click the title bar and drag the window to the left, top, or right edge of the desktop.

How do I resize Chrome in selenium?

We can resize the browser window in Selenium webdriver. We can configure the size of the browser with the help of the set_window_size method in Python. The dimensions of the window size are passed as parameters to this method. Again, to get the size of the browser, we can use the method get_window_size.


1 Answers

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.

like image 96
Andrei Botalov Avatar answered Oct 15 '22 10:10

Andrei Botalov