黄瓜和水豚:如何等待下一页加载.在我点击提交按钮后,测试用例失败,无法找到元素



如何等待下一页加载。在我点击提交按钮(基本注册流程)之后,测试用例失败,无法找到元素。我对这个很陌生,第一次用黄瓜和水豚。

我已经给出了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

您可能需要调整您测试元素存在的方式。如果操作正确,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有一篇很棒的文章给出了更多的例子。

最新更新