测试 Web 应用程序的 Facebook 与 Cucumber 的集成

发布于 2024-10-23 22:11:17 字数 962 浏览 1 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゃ懵逼小萝莉 2024-10-30 22:11:17

我目前正在使用omniauth gem 来处理这种类型的身份验证。 FBML 已弃用,因此我建议转向 JS SDK 进行客户端 FB 交互。无论如何,如果您使用omniauth,您可以通过在 env 文件夹中指定一些 Before 标签来相对轻松地删除响应,如下所示:

配置成功案例:

Before('@omniauth_test_success') do
  OmniAuth.config.test_mode = true

  OmniAuth.config.mock_auth[:facebook] = {
    "provider"  => "facebook",
    "uid"       => '12345',
    "user_info" => {
      "email" => "[email protected]",
      "first_name" => "John",
      "last_name"  => "Doe",
      "name"       => "John Doe"
      # any other attributes you want to stub out for testing
    }
  }
end

配置失败案例

Before('@omniauth_test_failure') do
  OmniAuth.config.test_mode = true
  [:default, :facebook, :twitter].each do |service|
    OmniAuth.config.mock_auth[service] = :invalid_credentials
    # or whatever status code you want to stub
  end
end

Cukes 功能

Scenario: A user unsuccessfully signs in with their email/password
    Given I am on the homepage
    When I follow "Login"
    And I "unsuccessfully" sign in with email and pass
    Then I should see "Failed."

@omniauth_test_success
  Scenario: A user successfully signs in with Facebook
    Given I am on the homepage
    And I follow "Login"
    When I follow "facebook"
    Then I should see "Login successful."

@omniauth_test_failure
  Scenario: A user unsuccessfully signs in with Facebook
    Given I am on the homepage
    And I follow "Login"
    When I follow "facebook"
    Then I should see "Failed."

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:

Before('@omniauth_test_success') do
  OmniAuth.config.test_mode = true

  OmniAuth.config.mock_auth[:facebook] = {
    "provider"  => "facebook",
    "uid"       => '12345',
    "user_info" => {
      "email" => "[email protected]",
      "first_name" => "John",
      "last_name"  => "Doe",
      "name"       => "John Doe"
      # any other attributes you want to stub out for testing
    }
  }
end

Config Failure Case

Before('@omniauth_test_failure') do
  OmniAuth.config.test_mode = true
  [:default, :facebook, :twitter].each do |service|
    OmniAuth.config.mock_auth[service] = :invalid_credentials
    # or whatever status code you want to stub
  end
end

Cukes Feature

Scenario: A user unsuccessfully signs in with their email/password
    Given I am on the homepage
    When I follow "Login"
    And I "unsuccessfully" sign in with email and pass
    Then I should see "Failed."

@omniauth_test_success
  Scenario: A user successfully signs in with Facebook
    Given I am on the homepage
    And I follow "Login"
    When I follow "facebook"
    Then I should see "Login successful."

@omniauth_test_failure
  Scenario: A user unsuccessfully signs in with Facebook
    Given I am on the homepage
    And I follow "Login"
    When I follow "facebook"
    Then I should see "Failed."
等风也等你 2024-10-30 22:11:17

我已设法使用以下代码在 rspec 接受规范中实现此功能:

https://gist.github.com/ 1084767

这使用 mogli 创建和销毁测试用户,并使用 capybara 来编排浏览器测试。我相信您可以通过删除shared_context块并使用Cucumber之前/之后挂钩来使其与Cucumber一起使用,例如:

Before '@fb_test_user' do
  @fb_user = create_test_user(installed: false)
end

After '@fb_test_user' do
  @fb_user.destroy
end

World(FacebookIntegrationHelpers) 

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:

Before '@fb_test_user' do
  @fb_user = create_test_user(installed: false)
end

After '@fb_test_user' do
  @fb_user.destroy
end

World(FacebookIntegrationHelpers) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文