测试 Web 应用程序与 Cucumber 的 Facebook 集成 [英] Testing a web application's Facebook integration with Cucumber

查看:20
本文介绍了测试 Web 应用程序与 Cucumber 的 Facebook 集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Cucumber 和 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 来编排浏览器测试.我相信您可以通过删除 shared_context 块并在钩子之前/之后使用 Cucumber 来使其与 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 应用程序与 Cucumber 的 Facebook 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆