Inspired by Kat Tornwall’s talk about integration tests with Elixir and Phoenix I did some clean up in my integration tests of my current Elixir project. Look how much more readable they are now.

so much cleaner

Page modules for navigation

Instead of using all this navigation stuff like

find_element(:id, "get-state-button")
|> click()

I can simply write StartPage.click_check_backend() now.

Customized assertions

Using assert Regex.match?(...) inlined will end up in assert messages like expected true but was false which is really annoying and won’t tell me the real error. So, I wrote a macro, thus I can use assert_regex(expected,text) which will tell me exactely what was searched for but not found in which text.

The test above is so much more readable now, isn’t it.

And the effort wasn’t a big deal. Here is what I had to extract into helpers.

StartPage Helper


Assertion Macro