测试 Web 应用程序的 Facebook 与 Cucumber 的集成
我想使用 Cucumber 和 Capybara 来通过执行以下场景来测试我的 Rails 应用程序的 Facebook 注册过程:
@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 的用户的环境。
需要解决的一些具体问题:
如何模拟单击
元素?我想出的最好的办法(但尚未测试)是手动触发元素上的单击事件。
一旦 Facebook 对话框出现,水豚可以访问它吗?如何?这似乎是输入测试 Facebook 帐户的电子邮件地址和密码以及为测试帐户安装 Facebook 应用程序所必需的。
就此而言,如何管理测试帐户? http://developers.facebook.com/docs/test_users/ 表示可以使用以下命令创建和删除测试用户Graph API,但该 API 并不打算提供对测试帐户的电子邮件地址或密码的访问,这似乎使它们对于测试此特定流程毫无用处。
我确信我也忽略了其他重要问题。我确实很好奇其他人是如何解决这个问题的!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我目前正在使用omniauth gem 来处理这种类型的身份验证。 FBML 已弃用,因此我建议转向 JS SDK 进行客户端 FB 交互。无论如何,如果您使用omniauth,您可以通过在 env 文件夹中指定一些 Before 标签来相对轻松地删除响应,如下所示:
配置成功案例:
配置失败案例
Cukes 功能
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
我已设法使用以下代码在 rspec 接受规范中实现此功能:
https://gist.github.com/ 1084767
这使用 mogli 创建和销毁测试用户,并使用 capybara 来编排浏览器测试。我相信您可以通过删除shared_context块并使用Cucumber之前/之后挂钩来使其与Cucumber一起使用,例如:
I've managed to get this working in rspec acceptance specs with the following code:
https://gist.github.com/1084767
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: