首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Capybara/Selenium Capybara::ElementNotFound -在运行@javascript时

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

Stack Overflow用户
提问于 2011-07-27 22:55:07
回答 1查看 907关注 0票数 1

我一直在使用Cucumber & Capybara进行集成测试。由于站点使用了大量的javascript,所以我将环境设置为使用selenium作为javascript驱动程序。然而,它似乎一直失败在一个元素,我知道应该在那里。我遗漏了什么吗?

以下是其特点:

代码语言: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"

以下是我单击元素时的步骤定义

代码语言:javascript
运行
复制
When /^(?:|I )click element "([^"]*)"$/ do |id|
  find(id).click
end

我知道Given I am logged in可以工作,因为使用它的其他测试通过得很好。关于为什么不能找到#进入战斗的原因有什么想法吗?当我亲自登录的时候,我可以很好地看到它。

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

代码语言:javascript
运行
复制
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步骤之一:我按下“进入战斗”键,所以我现在的功能是:

代码语言:javascript
运行
复制
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" 

仍然是同样的错误

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-08 12:41:36

这里还有另一个潜在的问题。我试图点击的“进入战斗”按钮出现在有人登录后。现在,当我自己去网站的时候,它运行的很好,但登录实际上是失败的。一旦我纠正了其中的一些代码,它就开始工作了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6852216

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档