如何通过page.should have_content传递来自数据库的数据的黄瓜测试用例

时间:2022-08-23 12:37:48

I am getting the following error:

我收到以下错误:

expected there to be text "D87F1B373E528ECBE040D10A044A2E9A" in "Pending Forms to be completed Patient Medication Last Updated Prescription Id" (RSpec::Expectations::ExpectationNotMetError)
  ./features/step_definitions/get_pending_forms.rb:10:in `/^I should see formId as "([^"]*)"$/'
  features/get_pending_forms.feature:5:in `And I should see formId as "D87F1B373E528ECBE040D10A044A2E9A"'


Feature: List all pending forms in json
  Scenario: get pending forms
    Given I visits the get pending forms page with token "121cb4c8e9c5133b4046db3e81f91c0d03f4735949daf6e1c129d613531f3954"
    Then I should see pending forms with location_id "1234567890"
    And I should see formId as "D87F1B373E528ECBE040D10A044A2E9A"
    And I should see formCount as "5"

Step definition:

步骤定义:

Given /^I visits the get pending forms page with token "([^"]*)"$/ do |token|
  visit display_pending_forms_path(:authorization => "121cb4c8e9c5133b4046db3e81f91c0d03f4735949daf6e1c129d613531f3954")
end

Then /^I should see pending forms with location_id "([^"]*)"$/ do |location|
  #page.should have_content(location)
end

And /^I should see formId as "([^"]*)"$/ do |formId|
  page.should have_content(formId)
end

And /^I should see formCount as "([^"]*)"$/ do |formCount|
  page.should have_content(formCount)
end

2 个解决方案

#1


0  

You should use have_css instead of have_content when you are testing for HTML elements:

在测试HTML元素时,应该使用have_css而不是have_content:

page.should have_css("#form_id")

For more details see the Capybara documentation.

有关更多详细信息,请参阅Capybara文档。

#2


0  

Have some records in the database. and it works fine..

在数据库中有一些记录。它工作正常..

#1


0  

You should use have_css instead of have_content when you are testing for HTML elements:

在测试HTML元素时,应该使用have_css而不是have_content:

page.should have_css("#form_id")

For more details see the Capybara documentation.

有关更多详细信息,请参阅Capybara文档。

#2


0  

Have some records in the database. and it works fine..

在数据库中有一些记录。它工作正常..