2 require 'capybara/rails'
3 require 'capybara/poltergeist'
7 Capybara.register_driver :poltergeist do |app|
8 Capybara::Poltergeist::Driver.new app, {
9 window_size: [1200, 800],
10 phantomjs_options: ['--ignore-ssl-errors=true'],
18 Capybara.default_wait_time = 5
20 Timeout.timeout(Capybara.default_wait_time) do
21 loop until finished_all_ajax_requests?
25 def finished_all_ajax_requests?
26 page.evaluate_script('jQuery.active').zero?
30 class ActionDispatch::IntegrationTest
31 # Make the Capybara DSL available in all integration tests
33 include ApiFixtureLoader
36 @@API_AUTHS = self.api_fixture('api_client_authorizations')
38 def page_with_token(token, path='/')
39 # Generate a page path with an embedded API token.
40 # Typical usage: visit page_with_token('token_name', page)
41 # The token can be specified by the name of an api_client_authorizations
42 # fixture, or passed as a raw string.
43 api_token = ((@@API_AUTHS.include? token) ?
44 @@API_AUTHS[token]['api_token'] : token)
45 sep = (path.include? '?') ? '&' : '?'
46 q_string = URI.encode_www_form('api_token' => api_token)
47 "#{path}#{sep}#{q_string}"
50 # Find a page element, but return false instead of raising an
51 # exception if not found. Use this with assertions to explain that
52 # the error signifies a failed test rather than an unexpected error
53 # during a testing procedure.
57 rescue Capybara::ElementNotFound
62 @@screenshot_count = 1
64 image_file = "./tmp/workbench-fail-#{@@screenshot_count}.png"
66 page.save_screenshot image_file
67 rescue Capybara::NotSupportedByDriverError
70 puts "Saved #{image_file}"
71 @@screenshot_count += 1
79 if Capybara.current_driver == :selenium
80 page.execute_script("window.localStorage.clear()")
82 Capybara.reset_sessions!