Search code examples
elixirwallaby

How to get html page in wallaby


I try to run fin function but for some reason I get back nil. The item I search for have to be there, how can I get the html to see what went wrong?


Solution

  • I have two helper functions that receive the wallaby session.

    The first prints the visible text to STDOUT:

      def print_page_text(session) do
        session |> Wallaby.Browser.text() |> IO.inspect()
        session
      end
    

    The second function prints the complete HTML page source to STDOUT:

      def print_page_source(session) do
        session |> Wallaby.Browser.page_source() |> IO.inspect()
        session
      end
    

    By returning the session these functions can be used between the usual wallaby queries/assertions:

    session
    |> visit("/example/page")
    |> print_page_text()
    |> assert_text("Hello World!")
    

    Another helpful function is Wallaby.Browser.take_screenshot/2