【问题标题】:Unable to find field (Capybara::ElementNotFound) on rails无法在轨道上找到字段 (Capybara::ElementNotFound)
【发布时间】:2017-02-23 17:31:32
【问题描述】:

我从黄瓜开始,我正在尝试做一个测试,在我的轨道上创建一部新电影。所以在我的 teste1.feature

Feature: É possivel acessar a pagina de Novo Filme



Scenario: É possivel visitar paginas
  Given I visit "/articles"
  And I press the "Novo Filme" button
  Then I should see the "/articles/new" page



Scenario: Add a movie

  Given I visit "/articles"
  And I press the "Novo Filme" button
  Then I should see the "/articles/new" page
  Given I am on a new movies page
  When I fill in "article_title" with "Sta Uors"
  And I fill in "f.number_field" with "10.5"
  And I press "Salvar Novo Filme"
  Then I should see "/articles"
  Then I should see the "Sta Uors" at "tabelafilme"

在我的 teste1.step 我有

#Given(/^I visit "([^"]*)"$/) do 


# visit article_path # Write code here that turns the phrase above into concrete actions
#end
Given (/^I visit "(.*)"/) do |place|
 visit place
end

And(/^I press the "([^"]*)" button$/) do |arg|
  click_on( arg ) # Write code here that turns the phrase above into concrete actions
end


Then(/^I should see the "([^"]*)" page$/) do |place|
  visit "/articles/new"
end




Given (/^I am on a new movies page/) do
    visit "/articles/new"
end

When (/^I fill in "(.*)" with "(.*)"/) do |field , content|
 fill_in (field), :with => (content), visible: false
end

And(/^I press "([^\"]*)"/) do |button|
    click_button(button)
end

Then (/^I should see "([^\"]*)"/) do |arg|
    page.find_by_id('notice').text == arg
end

Then (/^I should see the "([^\"]*)" at "([^\"]*)"/) do |film, table|
    expect(page).to have_css("#tebelafilme", :text => table)
    find('td', text: film)
end

但我仍然收到此错误

When I fill in "article_Titulo" with "Sta Uors"   # features/step_definitions/teste1.rb:24
  Unable to find field "article_Titulo" (Capybara::ElementNotFound)
  ./features/step_definitions/teste1.rb:25:in `/^I fill in "(.*)" with "(.*)"/'
  features/teste1.feature:18:in `When I fill in "article_Titulo" with "Sta Uors"'

所以,我去运行的项目并点击我的article_title在html页面上检查黄瓜的名称是什么,id名称是“article_text”,标签是“article_Titulo”,黄瓜找不到场地。 有人可以帮我吗?

【问题讨论】:

    标签: ruby-on-rails cucumber


    【解决方案1】:

    首先,就 fill_in 的the documentation 而言,它看起来像是期待一个专门针对这两个参数的字符串。您可以尝试使用fill_in "#{field}", :with => "#{content}", visible: false 来确定您正在给它提供字符串。

    但是,如果您使用 text_field 辅助方法创建字段,this answer 应该这样做。看起来在名称中使用下划线创建的元素在到达 DOM 时已经去掉了下划线。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多