Having trouble injecting a script in Capybara. Take a look at the code below:
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, :phantomjs_options => ['--debug=no', '--ignore-ssl-errors=yes'], :js_errors => false)
end
Capybara.configure do |c|
c.javascript_driver = :poltergeist
c.default_driver = :poltergeist
c.app_host = "http://www.google.com"
c.default_wait_time = 120
end
Capybara.current_session.driver.headers = {
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
}
visit('/')
Capybara.current_session.driver.execute_script("alert('Working!');")
sleep(1)
system('rm /tmp/screenshot.png')
Capybara.current_session.driver.save_screenshot('/tmp/screenshot.png')
When injecting this script, it should make some ajax calls and change the dom. However, after taking a snapshot, no changes are visible on the page. Even adding a simple alert doesn't show up in the snapshot. What could be causing this issue?