为什么我的 Cucumber 测试在使用 Selenium 运行时会失败? [英] Why does my Cucumber test fail when run with Selenium?

查看:10
本文介绍了为什么我的 Cucumber 测试在使用 Selenium 运行时会失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Cucumber/Capybara 组合测试 Rails 3 应用程序.我也在尝试使用 Selenium 测试一些 JavaScript 特定场景,但遇到了我不理解的奇怪困难.

I am testing a Rails 3 app with a Cucumber/Capybara combo. I am also trying to use Selenium to test some JavaScript specific scenarios but am running into weird difficulties I don't understand.

我对 Cucumber/Capybara 的体验很低,我对 Selenium 的体验为零.

My experience with Cucumber/Capybara is pretty low, my experience with Selenium is zero.

这是场景:

Scenario: Browsing events
  Given many events exist
  And I am on the events page
  Then I should see a list of 15 events
  When I follow the first event
  Then I should be on the event page
  And I should see a google map
  And I should see the event details

当该场景在 RackTest 下运行时,它会一直传递到 Google Map 步骤,此时它会失败,因为没有 JavaScript.这是意料之中的.

When that scenario runs under RackTest, it passes all the way up to the Google Map step, at which point it fails because there's no JavaScript. This is expected.

当我使用默认 JavaScript 驱动程序 (Selenium) 运行测试时,它在第三步失败(我应该看到 15 个事件的列表).当我观察浏览器窗口时,确实事件列表中根本不包含任何事件——就好像它们不存在于数据库中一样.

When I run the test with the default JavaScript driver (Selenium) it fails on step three (I should see a list of 15 events). When I observe the browser window, indeed the list of events contains no events at all - almost as if they don't exist in the database.

顺便说一句,第一步(存在许多事件)使用 FactoryGirl 创建大量事件.

Incidentally, the first step (many events exist), uses FactoryGirl to create a load of events.

因为这对我来说都是新事物,我想知道我是否被一个典型的陷阱抓住了?除了来自 rails g cucumber:install 的标准安装之外,我没有进行任何配置更改.另外,如果相关的话,我使用的是 OSX.

As this is all pretty new to me, I wonder if I'm being caught out by a typical gotcha? I haven't made any configuration changes other than the standard install from rails g cucumber:install. Also, if it's relevant, I'm using OSX.

谢谢

推荐答案

我认为您正在尝试使用 Selenium 的事务性固定装置(默认行为),但这不起作用.当浏览器单独调用 Rails 应用程序时,测试中管理的事务超出范围,因此它看不到您的测试创建的任何未提交数据.

I presume you are trying to use transactional fixtures (the default behavior) with Selenium, but that won't work. The transaction that is managed within the test is out of scope when the browser invokes the Rails app separately, so it can't see any of the uncommitted data that your test has created.

您需要使用一种数据库清洁器 gem,而不是事务性装置.

Instead of transactional fixtures, you'll need to use one of the database cleaner gems.

https://github.com/bmabey/database_cleaner

我随后意识到 可以在 Selenium 测试中使用事务性固定装置,如果这样做,性能会更好(归功于 Kira Corina 的回答).详情请参阅 http://pastie.org/1745020.

I subsequently became aware that it is possible to use transactional fixtures with Selenium tests, and performance is better if you do (credit to Kira Corina's answer). See http://pastie.org/1745020 for details.

这篇关于为什么我的 Cucumber 测试在使用 Selenium 运行时会失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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