开发者

Capybara/Selenium Capybara::ElementNotFound - when running @javascript

开发者 https://www.devze.com 2023-03-23 22:14 出处:网络
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 fai

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

开发者_JAVA技巧
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 = '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

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 "([^"]*)"$/' features/combat/combat.feature:9:inWhen I click element "#enter-combat"'

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消