Reputation: 3494
It seems incredibly difficult to achieve something simple like changing my browser window running Capybara + webdriver
I'm testing against an external website. What I want is to maximize my browser window. I found many hints on the web but nothing seems to work. The minimal code to reproduce is:
require 'capybara'
require 'selenium-webdriver'
session = Capybara::Session.new(:selenium)
window = Capybara.current_session.current_window
window.resize_to(1920,1080)
sleep(10)
result is
Traceback (most recent call last):
5: from C:/src/Ruby/Capybara/minimal.rb:5:in `<main>'
4: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/capybara-3.9.0/lib/capybara/session.rb:426:in `current_window'
3: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/capybara-3.9.0/lib/capybara/session.rb:102:in `driver'
2: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/capybara-3.9.0/lib/capybara.rb:519:in `block in <top (required)>'
1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/capybara-3.9.0/lib/capybara.rb:519:in `new'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/capybara-3.9.0/lib/capybara/rack_test/driver.rb:18:in `initialize': rack-test requires a rack application, but none was given (ArgumentError)
Any ideas?
Upvotes: 0
Views: 1271
Reputation: 49890
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)
Upvotes: 1