2011-07-27 140 views
1

我一直在使用黄瓜&水豚进行集成测试。由于该网站使用了大量的JavaScript,我将环境设置为使用硒作为JavaScript驱动程序。然而,它似乎仍然在我认为应该在那里的元素失败。有什么我失踪?水豚/硒水豚:: ElementNotFound - 当运行@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作品,使用它的其他测试通过精细的步骤定义。关于为什么#进入战斗的任何想法都找不到?当我亲自登录时,我可以看到它很好。

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

Given /^I am logged in$/ do 
    email = '[email protected]' 
    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 

这里是当我运行的输出:

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

无法找到 '#进入战斗'(水豚:: ElementNotFound) ./功能/ step_definitions/combat_steps.rb:6:/^(?:|I)click element "([^"]*)"$/' features/combat/combat.feature:9:in当我点击元素 “#进入战斗””

编辑

现在我使用的是默认的Web步骤之一:我按“回车战斗”,所以我的功能现在是:

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" 

还是同样的错误

+0

你可以给出运行场景的输出吗? – efoo

+0

也可以提供'鉴于我已登录'步骤定义完成# – iafonov

+0

。多谢你们。 – agmcleod

回答

0

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