HashNuke / hound

Elixir library for writing integration tests and browser automation
http://hexdocs.pm/hound
MIT License
1.36k stars 144 forks source link

Create custom strategy types? #171

Open sn3p opened 7 years ago

sn3p commented 7 years ago

We just released the first version of test_selector, a set of helpers to set/get test selectors to/from elements in a Phoenix app (when 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. The reason we created this is we prefer reserving classes for styling, and id's have limitations because they have to be unique.

My question:

Our test helpers currently use find_element(:xpath, ..., but is there a way to create a custom strategy type? For example:

find_element(:test, "user", user.id)

I tried:

def find_element(:test, view_module, retries \\ 5) do
  {:safe, test_selector} = view_module.test()
  find_element(:xpath, ~s|//*[@#{test_selector}]|, retries)
end

But this results in an error:

** (CompileError) lib/test_selector/test_helpers.ex:1: imported Hound.Helpers.Page.find_element/2 conflicts with local function

danhper commented 7 years ago

Hi, thanks for the proposal and sorry for the delay. I agree custom strategies could be helpful, but I do not have time to take care of it right now. If you would like to try implementing it, please feel free to send a PR. Thank you very much.