测试Web应用程序的Facebook与Cucumber的集成 [英] Testing a web application's Facebook integration with Cucumber
问题描述
我想使用Cucumber with Capybara通过执行以下场景来测试我的Rails应用程序的Facebook注册过程:
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
人们如何解决集成测试基于浏览器的Facebook集成的问题?网络搜索只会产生一些早于图形API的博客帖子,他们只是讨论实现一个前提条件,设置一个代表已经登录Facebook的用户的环境。
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:
如何模拟点击< fb:login-button>
元素?我想出的最好的事情(但尚未测试)是手动启动元素上的点击事件。
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.
Facebook对话框出现后,Capybara有权访问吗?怎么样?这似乎是必要的,以输入测试Facebook帐户的电子邮件地址和密码,并为测试帐户安装Facebook应用程序。
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.
管理测试帐户? http://developers.facebook.com/docs/test_users/ 表示可以创建和删除测试用户Graph API,但API似乎不提供对测试帐户的电子邮件地址或密码的访问,这似乎使它们无法用于测试此特定流程。
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!
推荐答案
我已经设法得到这个工作在rspec接受规范以下代码:
I've managed to get this working in rspec acceptance specs with the following code:
https://gist.github。 com / 1084767
这使用mogli来创建和销毁测试用户和capybara来协调浏览器测试。我相信你可以得到它与Cucumber通过删除shared_context块和使用Cucumber之前/之后挂钩,如:
This uses mogli to create and destroy test users and capybara to orchestrate the browser test. I believe you could get it working with Cucumber by removing the shared_context block and using Cucumber before/after hooks, like:
Before '@fb_test_user' do
@fb_user = create_test_user(installed: false)
end
After '@fb_test_user' do
@fb_user.destroy
end
World(FacebookIntegrationHelpers)
这篇关于测试Web应用程序的Facebook与Cucumber的集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!