我正在对我的 Rails 应用程序进行一些测试。我正在使用关于某些形式的宝石茧。我在测试“日期选择”时遇到了一些麻烦。我想知道我做错了什么,非常感谢您的帮助!
请在下面找到我到目前为止所做的事情:
作业表单的嵌套字段(我正在尝试测试输入字段started_at)
.nested-fields
= f.input :company_name, label:'Nom de entreprise', input_html: {class: "form-control job-company-name"}
= f.input :title, label: 'Votre fonction', input_html: {class: "form-control job-title "}
= f.input :location, label: 'Lieu de travail', input_html: {class: "form-control job-location"}
= f.input :started_at, discard_day: true, order: [:month, :year], include_blank: true, label:'Date début',input_html: {class: "work-started-at job-started-at"}, start_year: 1970, end_year: 2016, :id => 'task_target_date'
= f.input :finished_at, discard_day: true, order: [:month, :year], label: 'Date fin ( mettre le mois en cours si c\'est votre emploi actuel)',input_html: {class: "work-finished-at end_date job-finished-at"},start_year: 1970, end_year: 2016, :default => Time.now
= f.input :description, label: 'Vos responsabilités',:input_html => {:rows => 9, style: 'max-width:100%;', class: ""}
.remove-experience.text-center
= link_to_remove_association "supprimer cette expérience", f, class: 'btn btn-delete form-button'
RSpec 和 Capybara
require 'rails_helper'
RSpec.feature "Edit Profile" do
scenario "Profile updated successfully ", js: true do
Given "user visits profile edit page"
When "user updates profile basic info"
When "user updates work experiences info"
When "user updates education info"
Then "user views profile updated"
end
def user_updates_work_experiences_info
click_link "Parcours professionnel"
click_link "Ajouter une expérience"
find(".job-company-name").set("Natixis")
find(".job-title").set("Contrôleur Financier")
find(".job-location").set("Paris")
select_date("2013,December,7", :from => "Date début")
end
def select_date(date, options = {})
field = options[:from]
base_id = find(:xpath, ".//label[contains(.,'#{field}')]")[:for]
year, month, day = date.split(',')
select year, :from => "#{base_id}_1i"
select month, :from => "#{base_id}_2i"
end
end
当我运行测试时,我收到以下消息:
Failure/Error: select year, :from => "#{base_id}_1i"
Capybara::ElementNotFound:
Unable to find select box "profile_experiences_attributes_1467917726232_started_at_2i_1i"
谢谢你们 ;)