Testing with Floki
In this section, we will update our controller test written in the previous section to test HTML elements returned by the response body. This will allow us to better ensure that the final HTML rendered by the controller is correct. In order to do this, we will use floki
.
Floki
is an HTML parser written purely in Elixir. With floki
, we can parse an HTML string into a struct and search for notes using HTML and CSS selectors. It’s a great tool to programmatically interpret HTML in Elixir, such as web scraping. One of its other common uses is to test server-side rendered HTML in Phoenix and other Elixir web applications.
Let’s start by adding floki
to the mix.exs
dependencies:
mix.exs
defmodule ExampleServerHtmlEex.MixProject do # .. defp deps do [ {:goldcrest, "~> 0.0.1"}, {:floki, ">= 0.0.0", only...