TestSelector
A set of Elixir and Hound helpers to set/get test selectors to/from elements in a Phoenix app (when Mix.env == :test). These selectors are hashed (scoped to the view module they are used in) for accurate selection and "leakage" prevention. See our Wiki for examples.
Why? Because we prefer reserving classes for styling, and id's have limitations because they have to be unique.
Dependencies
Installation
def deps do
[{:test_selector, "~> 0.3.0"}]
end
Use TestSelector.HTML.Helpers to your web.ex.
-
In phoenix 1.2.0 at
web/web.ex -
In newer Phoenix versions
lib/your_project/web/web.ex
Add somewhere along:
def view(opts \\ []) do
quote do
...
use Phoenix.HTML
use TestSelector.HTML.Helpers
...
end
endTesting with Floki
In the tests import the TestSelector.Test.HoundHelpers :
defmodule Project.Web.MyTest do
...
use Hound.Helpers
import TestSelector.Test.FlokiHelpers
...
endTesting with Hound
In the tests import the TestSelector.Test.HoundHelpers :
defmodule Project.Web.MyTest do
...
use Hound.Helpers
import TestSelector.Test.HoundHelpers
...
endTests
To run tests you need to install PhantomJS.
brew install phantomjsRun the webdriver:
phantomjs -wRun the tests:
mix test