猎犬:visible_text / 1返回一个空字符串

问题描述 投票:0回答:1

我正在尝试用猎犬进行集成测试。测试看起来像这样:

defmodule RedBeardWeb.UserCanRegisterTest do
  use RedBeard.DataCase
  use ExUnit.Case
  use Hound.Helpers

  hound_session()

  ...

  name       = find_element(:class, "header__user_name")
  name_text  = visible_text(name)

  assert name_text   == "John D."
end

当我运行测试时,我收到以下错误:

1) test user can register with valid credentials (MyAppWeb.UserCanRegisterTest)
   test/red_beard_web/integration/user_can_register_test.exs:30
   Assertion with == failed
   code:  assert name_text == "John D."
   left:  ""
   right: "John D."
   stacktrace: test/red_beard_web/integration/user_can_register_test.exs:39: (test)

visible_text / 1返回一个空字符串。当我手动执行测试中的所有操作时,正确显示字符串。

Mozilla inspector

如果我从模板中删除元素.header__user_name并运行相同的测试,我得到以下错误** (Hound.NoSuchElementError) No element found for class 'header__user_name'。所以找到了元素。

为什么visble_text/1返回一个空字符串?

elixir phoenix-framework
1个回答
1
投票

该文本是否真的可见,或者是否有一些隐藏它的CSS?

如果你使用inner_text而不是visible_text怎么办?

© www.soinside.com 2019 - 2024. All rights reserved.