I'd like to use Cucumber with Capybara to test my Rails application's Facebook registration procedure by executing the following scenario:
@javascript
Scenario: Connect account
When I go to the home page
And I press "Connect your Facebook account"
And I fill in "test@address" for "Email"
And I fill in "test" for "Password"
And I press "Login"
And I press "Allow"
Then I should be on the dashboard page
How do folks approach the problem of integration testing browser-based Facebook integration? A web search turns up only a couple of blog posts that predate the graph API, and they only seem to discuss implementing a precondition that sets up an environment representing a user already logged in to Facebook.
Some specific issues to address:
How does one simulate clicking the <fb:login-button>
element? The best thing I've come up with (but have yet to test) is to manually fire a click event on the element.
Once the Facebook dialog comes up, does Capybara have access to it? How? This seems required in order to enter the email address and password of a test Facebook account and to install the Facebook app for the test account.
For that matter, how does one manage test accounts? http://developers.facebook.com/docs/test_users/ indicates that test users can be created and deleted with the Graph API, but the API doesn't look to to provide access to an email address or password for a test account, which seems to make them useless for testing this particular flow.
I'm sure I'm overlooking other important issues as well. I sure am curious how other folks have attacked this problem!
Best Answer
i'm currently using the omniauth gem to handle this type of authentication. FBML is deprecated, so I suggest moving to the JS SDK for client side FB interaction. Anyways, if you're using omniauth, you can stub out the response relatively easily by specifying some Before tags in your env folder like so:
Config Success case:
Config Failure Case
Cukes Feature