Test Automation Ruby、RSpec、Capybara:日期/时间选择器错误


   Failure/Error: expect(page).to have_selector("li:nth-child(1) > dl:nth-child(6) > dd")
   expected to find css "li:nth-child(1) > dl:nth-child(6) > dd" but there were no matches

以上是我的错误。我很难找到一种方法来验证用户登录时登录的日期和时间。我曾尝试验证选择器/xpath/css是否存在,但似乎找不到匹配项。以下是我试图继续验证的一些方法,但并不令人满意。有什么想法吗?

  expect(page).to have_selector("li:nth-child(1) > dl:nth-child(6) > dd")
  expect(page).to have_xpath("/html/body/main/ul[@class='visitors']/li[1]/dl[6]/dd")

以下是我试图验证的web应用程序的部分页面源代码。

<ul class='visitors'>
<li>
  <dl>
    <dt>Title</dt>
    <dd></dd>
  </dl>
  <dl>
    <dt>First name</dt>
    <dd>John</dd>
  </dl>
  <dl>
    <dt>Last name</dt>
    <dd>Doe</dd>
  </dl>
  <dl>
    <dt>Email</dt>
    <dd>johndoe@gmail.com</dd>
  </dl>
  <dl>
    <dt>Signed in at</dt>
    <dd>April 26, 2021 08:25</dd>
  </dl>
</li>

当你说"验证登录的日期和时间";目前还不清楚你是在试图验证一个特定的日期/时间,还是只是那个日期/时间存在。还不清楚您是试图验证所显示字段的顺序,还是只是验证日期-时间字段是否在某个地方。假设你只是想验证一个带有日期时间的字段是否存在,它可能是类似的东西

signed_in = find('.visitors dt', text: "Signed in at")
expect(signed_in).to have_sibling('dd', text: /^[A-Z][a-z]+ d+, d{4} d{2}:d{2}$/)

最新更新