Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cucumber/Capybara have_选择器找不到使用JQuery添加的span_Jquery_Ruby On Rails_Cucumber_Capybara - Fatal编程技术网

Cucumber/Capybara have_选择器找不到使用JQuery添加的span

Cucumber/Capybara have_选择器找不到使用JQuery添加的span,jquery,ruby-on-rails,cucumber,capybara,Jquery,Ruby On Rails,Cucumber,Capybara,我遇到了一个令人沮丧的问题,这应该是一个非常简单的黄瓜测试。测试尝试在不输入任何表单数据的情况下提交简单表单,并希望看到错误消息: Given(/^a user visits the account confirmation page$/) do visit root_path end When(/^the user enters an improperly formatted email address$/) do click_button "START" end Then(/^t

我遇到了一个令人沮丧的问题,这应该是一个非常简单的黄瓜测试。测试尝试在不输入任何表单数据的情况下提交简单表单,并希望看到错误消息:

Given(/^a user visits the account confirmation page$/) do
  visit root_path
end

When(/^the user enters an improperly formatted email address$/) do
  click_button "START"
end

Then(/^the user should see an error message$/) do
  page.should have_selector("error")
end
错误消息元素由JQuery附加,并被赋予css类“error”。它所附加到的页面中的元素具有css类“Forms TextError”。此范围是基本html的一部分

<span id="email_error" class="Forms-TextError">
  <span class="error" for="email">Please provide your contact email</span>
</span>

请提供您的联系电子邮件
问题是have_选择器找不到错误范围。它也找不到其父范围。有人会认为它适用于这种情况,因为跨度是基本html的一部分

<span id="email_error" class="Forms-TextError">
  <span class="error" for="email">Please provide your contact email</span>
</span>

我做错了什么?

问题在于:

page.should have_selector("error")
这一行(或css选择器)表示页面应该有一个类型为“error”的元素,这是不可能存在的

您应该将css选择器更改为以下选项之一:

#Find a span with class error:
page.should have_selector("span.error")

#Find any element with class error:
page.should have_selector(".error")

您使用哪个驱动程序?无论默认驱动程序是什么。rack_test,我认为RackTest不会评估Javascript。如果您想以这种方式测试您的应用程序,您应该使用另一个驱动程序好的,我已经尝试为这个场景指定javascript,然后指定selenium。javascript出现了“Mysql2Adapter类的超类不匹配”,selenium导致了与我之前遇到的相同的失败,这很奇怪。请尝试按照这两项工作的设置和驱动程序部分进行操作(我假设您在第一个示例中的意思是“span.error”)好的,现在我明白了。我真的不明白选择器是怎么工作的