Skip to content

Instantly share code, notes, and snippets.

@natew
Created December 30, 2013 22:49
Show Gist options
  • Save natew/8189544 to your computer and use it in GitHub Desktop.
Save natew/8189544 to your computer and use it in GitHub Desktop.
Poltergeist TimeoutError when using within_window
# Helpers module we will use to share common code
# Anything that should be re-used between multiple tests
module Helpers
# last_window will grab the last window opened
# helpful for getting a popup window
def last_window
page.driver.window_handles.last
end
end
describe 'notify me' do
before :each do
visit @products[:shoe]
@notify_link = find('#notifyMePopupLink')
end
it 'shows notify me' do
@notify_link.should be_visible
@notify_link.click
within_window(last_window) do
title.should == 'Zappos.com - Notify Me!'
end
end
end
require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
require_relative './helpers'
@endpoint = ENV['ENDPOINT']
Spork.prefork do
require 'capybara/rspec'
require 'capybara/poltergeist'
require 'launchy'
require 'syntax'
$: << '.' # Add current directory to the lib path
# Register a custom Poltergeist driver.
Capybara.register_driver :poltergeist do |app|
# https://github.com/jonleighton/poltergeist#customization
Capybara::Poltergeist::Driver.new(
app,
debug: false, # Set this to 'true' for Poltergeist-level debugging.
# Load up Firefox when 'page.driver.debug' is used for debugging. You can
# learn more about remote debugging here:
# http://jonathanleighton.com/articles/2012/poltergeist-0-6-0/
inspector: 'firefox',
# Learn more about available PhantomJS command-line options here:
# https://github.com/ariya/phantomjs/wiki/API-Reference
phantomjs_options: ['--ignore-ssl-errors=yes',
'--local-to-remote-url-access=yes',
'--debug=no',
'--web-security=no']
#, phantomjs_logger: STDERR
)
end
# Run examples headlessly using poltergeist.
Capybara.default_driver = :poltergeist
Capybara.javascript_driver = :poltergeist
# Turn off Capybara's rack server since we're running against a remote
# application.
Capybara.run_server = false
# Wait X seconds to check for ajax request results
Capybara.default_wait_time = 2
# The "app_host" should point to the remote web server. (In the Rakefile the
# remote web server is assigned to the ENDPOINT environment variable.)
unless @endpoint
raise "\n*** ERROR: Unable to determine the proper endpoint to hit; please ensure " +
"that ENDPOINT is set to the appropriate value. ***\n\n"
end
Capybara.app_host = @endpoint
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
#config.filter_run :focus # See the RSpec docs on filtering.
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = 'random'
# Instead of having to specify ":type => :acceptance" everywhere, we include
# the Capybara libraries here since every example will use Capybara.
config.include Capybara::DSL
config.include Capybara::RSpecMatchers
# Helpers module to share code between tests easily
config.include Helpers
config.before :all do
@products = {
shoe: '/product/108000',
long_description: '/product/108000',
with_reviews: '/product/108000',
with_zoom: '/product/108000',
low_stock: '/product/108000',
fit_survey: '/product/108000',
oos: '/product/7161124',
video: '/product/108000'
}
@dimensions = {
oos: {
color: 249267,
d3: 112422,
d4: 112162
}
}
end
config.before :each do
page.driver.resize(1024, 1280)
end
config.after :each do
page.driver.reset! #tried with and without this line
# Capture a screenshot at the end of each example if there was a failure.
unless example.exception.nil?
screenshot_path =
"./build/brazil-unit-tests/screenshots/" +
"#{example.example_group.display_name.gsub(' ', '_')}/" +
"#{example.description.gsub(' ', '_')}.png"
$stderr.puts " Screenshot: #{screenshot_path}"
page.driver.render(screenshot_path, :full => true)
end
end
end
end
Spork.each_run do
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment