Capybara/Selenium Capybara::ElementNotFound - 运行 @javascript 时
我一直在使用黄瓜和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
这是当我单击元素时我知道鉴于我已登录
,因为使用它的其他测试顺利通过。关于为什么找不到 #enter-combat 有什么想法吗?当我亲自登录时,我可以很好地看到它。
编辑:添加了其他步骤定义。
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
这是我运行时的输出:
(::) failed steps (::)
Unable to find '#enter-combat' (Capybara::ElementNotFound) ./features/step_definitions/combat_steps.rb:6:在 /^(?:|I )click 元素 "([^"]*)"$/' features/combat/combat.feature:9:in
当我单击元素“#enter-combat”'
编辑
时,我现在正在使用默认 Web 步骤之一:然后按“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"
仍然是同样的错误
I've been using Cucumber & Capybara for integration testing. Since the site uses a lot of javascript, i set the environment to use selenium as the javascript driver. However, it seems to keep failing at an element i know should be there. Is there something im missing?
Here's the feature:
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"
Here's the step definition for When I click element
When /^(?:|I )click element "([^"]*)"$/ do |id|
find(id).click
end
I know the Given I am logged in
works, as other tests that use it pass fine. Any ideas as to why #enter-combat cannot be found? When i physically login myself, i can see it just fine.
Edit: Added other step definitions.
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
Here's the output when i run:
(::) failed steps (::)
Unable to find '#enter-combat' (Capybara::ElementNotFound)
./features/step_definitions/combat_steps.rb:6:in /^(?:|I )click element "([^"]*)"$/'
When I click element "#enter-combat"'
features/combat/combat.feature:9:in
Edit
I am now using one of the default web step: And I press "enter-combat", so my feature now is:
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"
Still the same error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里还有另一个根本问题。我试图点击的进入战斗按钮会在有人登录后出现。现在,当我自己访问该网站时它工作正常,但登录实际上失败了。一旦我更正了那里的一些代码,它就开始工作了。
There was another underlying issue here. The enter combat button I was trying to click appears after someone logs in. Now while it was working fine when I would go on the site myself, the login was actually failing. Once i had corrected some of the code there, this proceeded to work.