mirror of
https://github.com/teampoltergeist/poltergeist.git
synced 2022-11-09 12:05:00 -05:00
94 lines
2.9 KiB
Ruby
94 lines
2.9 KiB
Ruby
require 'spec_helper'
|
|
require 'capybara/spec/driver'
|
|
require 'image_size'
|
|
|
|
module Capybara::Poltergeist
|
|
describe Driver do
|
|
before do
|
|
@driver = TestSessions::Poltergeist.driver
|
|
end
|
|
|
|
it_should_behave_like "driver"
|
|
it_should_behave_like "driver with javascript support"
|
|
it_should_behave_like "driver with frame support"
|
|
it_should_behave_like "driver without status code support"
|
|
it_should_behave_like "driver with cookies support"
|
|
|
|
it 'should support a custom phantomjs path' do
|
|
file = POLTERGEIST_ROOT + '/spec/support/custom_phantomjs_called'
|
|
path = POLTERGEIST_ROOT + '/spec/support/custom_phantomjs'
|
|
|
|
FileUtils.rm_f file
|
|
|
|
driver = Capybara::Poltergeist::Driver.new(nil, :phantomjs => path)
|
|
driver.browser
|
|
|
|
# If the correct custom path is called, it will touch the file. We allow at
|
|
# least 1 sec for this to happen before failing.
|
|
|
|
tries = 0
|
|
until File.exist?(file) || tries == 10
|
|
sleep 0.1
|
|
tries += 1
|
|
end
|
|
|
|
File.exist?(file).should == true
|
|
end
|
|
|
|
it 'should raise an error and restart the client, if the client dies while executing a command' do
|
|
lambda { @driver.browser.command('exit') }.should raise_error(DeadClient)
|
|
@driver.visit('/')
|
|
@driver.body.should include('Hello world')
|
|
end
|
|
|
|
it 'should have a viewport size of 1024x768 by default' do
|
|
@driver.visit('/')
|
|
@driver.evaluate_script('[window.innerWidth, window.innerHeight]').should == [1024, 768]
|
|
end
|
|
|
|
it 'should allow the viewport to be resized' do
|
|
begin
|
|
@driver.visit('/')
|
|
@driver.resize(200, 400)
|
|
@driver.evaluate_script('[window.innerWidth, window.innerHeight]').should == [200, 400]
|
|
ensure
|
|
@driver.resize(1024, 768)
|
|
end
|
|
end
|
|
|
|
it 'should support rendering the page' do
|
|
file = POLTERGEIST_ROOT + '/spec/tmp/screenshot.png'
|
|
FileUtils.rm_f file
|
|
@driver.visit('/')
|
|
@driver.render(file)
|
|
File.exist?(file).should == true
|
|
end
|
|
|
|
it 'should support rendering the whole of a page that goes outside the viewport' do
|
|
file = POLTERGEIST_ROOT + '/spec/tmp/screenshot.png'
|
|
@driver.visit('/poltergeist/long_page')
|
|
@driver.render(file)
|
|
|
|
File.open(file, 'rb') do |f|
|
|
ImageSize.new(f.read).size.should ==
|
|
@driver.evaluate_script('[window.innerWidth, window.innerHeight]')
|
|
end
|
|
|
|
@driver.render(file, :full => true)
|
|
|
|
File.open(file, 'rb') do |f|
|
|
ImageSize.new(f.read).size.should ==
|
|
@driver.evaluate_script('[document.documentElement.clientWidth, document.documentElement.clientHeight]')
|
|
end
|
|
end
|
|
|
|
it 'should support executing multiple lines of javascript' do
|
|
@driver.execute_script <<-JS
|
|
var a = 1
|
|
var b = 2
|
|
window.result = a + b
|
|
JS
|
|
@driver.evaluate_script("result").should == 3
|
|
end
|
|
end
|
|
end
|