Capybara / Selenium Capybara :: ElementNotFound - 运行@javascript时

时间:2011-07-27 22:55:08

标签: ruby-on-rails selenium cucumber capybara

我一直在使用Cucumber& Capybara用于集成测试。由于该网站使用了大量的javascript,我将环境设置为使用selenium作为javascript驱动程序。但是,它似乎一直在失败,我知道应该在那里。有什么东西我不见了吗?

这是功能:

Feature: Combat
  In order to engage in combat
  As a registered user
  I want to be able to kill enemy ships
  @javascript
  Scenario: Initialize combat
    Given I am logged in
    # When I go to the homepage
    When I click element "#enter-combat"
    Then the page should contain a section with the class "map"

这是我单击元素

时的步骤定义
When /^(?:|I )click element "([^"]*)"$/ do |id|
  find(id).click
end

我知道Given I am logged in有效,因为其他使用它的测试都很好。关于为什么#enter-combat无法找到的任何想法?当我亲自登录时,我可以很好地看到它。

编辑:添加了其他步骤定义。

Given /^I am logged in$/ do
  email = 'murray@monkeyisland.com'
  password = 'demonic'

  steps %Q{
    Given the following user exists:
            | first_name | last_name | email    | password    | password_confirmation |
            | Murray     | Skull     | #{email} | #{password} | #{password}           |
        And I login as "#{email}" with the password "#{password}"
  }
end

Given /^I login as "([^\"]*)" with the password "([^\"]*)"$/ do |email, password|
  steps %Q{
    Given I am not logged in
    When I go to the login page
        And I fill in "user_email" with "#{email}"
        And I fill in "user_password" with "#{password}"
        And I press "Login"
  }
end

这是我跑步时的输出:

(::)失败的步骤(::)

无法找到'#enter-combat'(Capybara :: ElementNotFound) ./features/step_definitions/combat_steps.rb:6:in /^(?:|I )click element "([^"]*)"$/' features/combat/combat.feature:9:in当我点击元素“#enter-combat”'

修改

我现在正在使用其中一个默认网页步骤:我按“输入战斗”,所以我的功能现在是:

Feature: Initialize Combat
  In order to engage in combat
  As a registered user
  I want to be able to initialize it

  @javascript
  Scenario: Initialize combat
    Given I am logged in
    When I go to the homepage
    And I press "enter-combat"
    Then the page should contain a section with the class "map" 

仍然是同样的错误

1 个答案:

答案 0 :(得分:0)

这里还有另一个潜在的问题。有人登录后,我试图点击的输入战斗按钮出现。现在,当我自己去网站时工作正常,登录实际上是失败的。一旦我纠正了那里的一些代码,这就开始工作了。