Testing for static text in integration tests

Hello all, I have a question relating to best practices for integration tests (I’m using Wallaby).

Is it a good idea to test for static text e.g. "My page title" in an integration test? If so, what’s the best way to avoid tests breaking anytime you change the text on a page? One solution I can see is to use e.g. gettext msg_id but this makes the templates less readable.

And if testing for static text is a bad idea, what is the best alternative? Test for CSS/HTML? Or just the URL?

Thanks. :slight_smile:

1 Like

@tyro - did you find a solution for this? I am looking at using gettext, in my test (.exs) files, b/c I am testing page localizations too.

I think the general recommendation is to avoid testing static text in feature tests, as doing so makes the tests rather brittle. We use gettext in some tests where absolutely necessary but only in a very few cases.

More often we’ll check dynamic text e.g. that the correct user name/date is rendered on a page.

understood, and thank you for feedback. In our case, we really have to test the localization support, in web pages, hence my hunt for feedback.

When you deal with static text (and gettext) are you extracting the text from your .exs files, and if yes, is there a way to set :gettext to parse the .exs files too, w/o mingling the test folder into the elixir compiler path?

Sorry, I’m not really following your question. Do you want to extract translations from your test files?

yes, sorry for the confusion, English is not my first language. I’d like to use mix gettext.extract --merge, against the test folder, if that’s possible?! Otherwise, I’d have to define the locales in a .pot file, and use the domain support. I am just trying to find if there is a better way.

Ah, sorry I don’t know if that’s possible. If you found a solution please post it here as it may help someone else. :slight_smile: