Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save martinrehfeld/3127442 to your computer and use it in GitHub Desktop.
Save martinrehfeld/3127442 to your computer and use it in GitHub Desktop.
Headless integration testing of facebook dialogs with capybara-webkit

## Most important settings

Create a new facebook app (1) and make sure the canvas url (2) in the basic tab matches the host and port configured with Capybara.server_port and Capybara.app_host. Activating sandbox mode (3) in the advanced tab enables you to roll without providing an SSL canvas url. You want to set the display mode (4) of your facebook dialogs to page, which is also the default.

  1. https://developers.facebook.com/apps
  2. http://screencast.com/t/lt6ORnb1sf
  3. http://screencast.com/t/tPSUyE6s
  4. https://developers.facebook.com/docs/reference/dialogs/

Other drivers

  • Rack-test is not able to open external urls and I needed to authenticate my test users at facebook first
  • Poltergeist does not support within_frame (yet)
  • Selenium randomly fails for some tests in general
  • Webkit is according to my tests the only driver that works for the given problem
require 'test_helper'
require 'capybara/rails'
# Always run the server on the same port
Capybara.server_port = 3001
Capybara.app_host = "http://localhost:%d" % Capybara.server_port
Capybara.default_driver = :webkit
Capybara.javascript_driver = :webkit
class ActionDispatch::IntegrationTest
# Make the Capybara DSL available in all integration tests
include Capybara::DSL
teardown do
Capybara.reset_sessions! # Forget the (simulated) browser state
Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
end
def send_dialog
iframe = find('.fb_dialog iframe')
within_frame(iframe[:name]) do
find('label#ok_clicked').click
end
has_no_selector?('.fb_dialog iframe') # wait for the dialog to disappear
end
def cancel_dialog
dialog_iframe_id = find('.fb_dialog iframe')[:name]
within_frame(dialog_iframe_id) do
find('label#cancel_clicked').click
end
has_no_selector?('.fb_dialog iframe') # wait for the dialog to disappear
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment