user1354934 user1354934 - 3 months ago 7
Javascript Question

Is it a bad idea to use locator names in templates to write easier E2E tests?

I am finding it really hard to locate stuff I am testing when its deep nested, etc.

Is it a bad idea to use something

<h1 name="test-main-title">About Us</h1>


and just use

element(by.name('test-main-title'));?


Later, for the prod build, I can remove
name="test-*"
from my HTML files. Just want to knwo if that is a terrible idea before I start doing it.

Answer

The idea itself is similar to modifying application or a specific application build for testing or staging to make the testing easier. The idea itself is quite common and has its pros and cons. I don't though particularly like the idea of changing existing attribute values for that. Instead, think about adding meaningful ids and data-oriented classes or other attributes.

ids specifically have multiple advantages - they are less likely to be changed, they are unique (at least they should in theory), they are data-oriented (meaning, you probably would not have an id equal to col-sm-6) and they are the fastest way to locate elements.

Also, here are the related threads with more ideas:

Comments