如何等待下一页加载。单击提交按钮(基本注册流程)后,测试用例失败,无法找到元素。我对此非常陌生,第一次使用黄瓜和水豚。
我在默认等待时间内给出了10秒,是否有任何方法可以使用capybara明确等待该元素。
错误:
Scenario: Register with valid credentials # features/Job_seeker_Registration.feature:6
Given I am on "/register" # features/step_definitions/web_steps.rb:2
Unable to find field "#jobseekerName"
When I have entered "Seeker1" into the "jobseekerName" field # features/step_definitions/web_steps.rb:6
Unable to find field "#jobseekerMobileOrEmail"
When I have entered "7812125899" into the "jobseekerMobileOrEmail" field # features/step_definitions/web_steps.rb:6
Then I wait for 1 seconds # features/step_definitions/web_steps.rb:33
When I pick "Driver" from "field-desiredcategory" # features/step_definitions/web_steps.rb:16
Unable to find field "#jobseekerPassword"
When I have entered "4679" into the "jobseekerPassword" field # features/step_definitions/web_steps.rb:6
And I click on "jobSeekerRegister" # features/step_definitions/web_steps.rb:11
Then I wait for 40 seconds # features/step_definitions/web_steps.rb:33
Then I should see "verificationButton" # features/step_definitions/web_steps.rb:25
expected to find text "verificationButton" in "SEARCH JOBS SEARCH CANDIDATES LOOKING TO HIRE? (RSpec::Expectations::ExpectationNotMetError)
features/Job_seeker_Registration.feature:15:in `Then I should see "verificationButton"'
And I click on "Seeker 1" # features/step_definitions/web_steps.rb:11
And I click on "Edit my Profile" # features/step_definitions/web_steps.rb:11
Then I wait for 1 seconds # features/step_definitions/web_steps.rb:33
HTML screenshot: ./screenshot/screenshot.html
Image screenshot: ./screenshot/screenshot.png
Failing Scenarios:
cucumber features/Job_seeker_Registration.feature:6 # Scenario: Register with valid credentials
1 scenario (1 failed)
12 steps (1 failed, 3 skipped, 8 passed)
0m55.271s
代码:
Then /^I should see "(.*?)"$/ do |text|
page.should have_content(text)
end
Then /^I should see title "(.*?)"$/ do |text|
page.should have_title?(text)
end
Given /^I wait for (\d+) seconds?$/ do |n|
sleep(n.to_i)
end
答案 0 :(得分:0)
您可能需要调整测试元素是否存在的方式。如果你正确地做了,Capybara会等到元素出现。
例如:
# this noes not wait until the element exists
first(".active").click
但是如果你使用find
# this this waits until an element with the class "active" is found
find(".active").click
Thoughtbot a great article就此提供了更多示例。