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

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

问题描述

我正在测试一个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

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.

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.

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

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