我一直在使用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
可以工作,因为使用它的其他测试通过得很好。关于为什么不能找到#进入战斗的原因有什么想法吗?当我亲自登录的时候,我可以很好地看到它。
编辑:添加其他步骤定义。
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
以下是我运行时的输出:
(*)失败步骤(::)
当我单击元素“进入-战斗”时,无法找到‘进入战斗’(Capybara::ElementNotFound) ./features/step_definitions/combat_steps.rb:6:in /^(?:|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"
仍然是同样的错误
发布于 2011-09-08 12:41:36
这里还有另一个潜在的问题。我试图点击的“进入战斗”按钮出现在有人登录后。现在,当我自己去网站的时候,它运行的很好,但登录实际上是失败的。一旦我纠正了其中的一些代码,它就开始工作了。
https://stackoverflow.com/questions/6852216
复制相似问题