1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00
capybara-webkit/spec/driver_resize_window_spec.rb
Tom Lea 04fde02ad7 Add a resize_window method to the driver.
Allow users to resize the webkit viewport via
Capybara::Driver::Webkit#resize_window(width, height).

This can be called before or after page load, and fires resize events as expected.
2012-04-03 18:54:12 -04:00

52 lines
1.3 KiB
Ruby

require 'spec_helper'
require 'capybara/driver/webkit'
describe Capybara::Driver::Webkit, "#resize_window(width, height)" do
before(:all) do
app = lambda do |env|
body = <<-HTML
<html>
<body>
<h1 id="dimentions">UNKNOWN</h1>
<script>
window.onload = window.onresize = function(){
document.getElementById("dimentions").innerHTML = "[" + window.innerWidth + "x" + window.innerHeight + "]";
};
</script>
</body>
</html>
HTML
[
200,
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
[body]
]
end
@driver = Capybara::Driver::Webkit.new(app, :browser => $webkit_browser)
end
DEFAULT_DIMENTIONS = "[1680x1050]"
it "resizes the window to the specified size" do
@driver.visit("/")
@driver.resize_window(800, 600)
@driver.body.should include("[800x600]")
@driver.resize_window(300, 100)
@driver.body.should include("[300x100]")
end
it "resizes the window to the specified size even before the document has loaded" do
@driver.resize_window(800, 600)
@driver.visit("/")
@driver.body.should include("[800x600]")
end
after(:all) { @driver.reset! }
end