DEV Community

Discussion on: CodeceptJS: Testing made real fun 😎

Collapse
 
gwillz profile image
gwillz

The more readable the test; the more likely you are to maintain it.

CodeceptJS goes to great lengths to achieve this. It injects things and does a lot of things in the effort to keep those test files neat. Often at a cost of complexity in its helper tools.

But overall it's quite magical.

In that spirit, I would recommend to keep your locators as simple as possible. Tying yourself to the DOM structure will require more maintainence of your tests. (To be fair, Google doesn't make this easy, but then again, it's a production deployment).

For example:

I.fillField("#identifierId")
I.click("#identifierNext")
I.waitForElement("#password", 2)
I.fillField("input", "#password") // Second parameter is 'context'.
I.click("#passwordNext")

XPath is pretty cool, but it's also very OP. I'd only reach for it when form-name/context/CSS can't locate the elements I need.

But to be fair, if they can't - then a screen reader can't either. So maybe it just needs to be refactored anyway.

Great article. I wish more people got on to the CodeceptJS train. It's fantastic.