Skip to content
Advertisement

Best way to store locators

I’m following page object design pattern for Selenium automation and I can guess that many people store locators in .properties file and access them in code. It seems great to keep locators at separate place.

Since, I haven’t work on any big project for Selenium automation, I would like to know thoughts on following so that I can avoid problems that might raise in future:

  1. Is storing locators in properties file helpful in big projects(where test cases are more than 1000 or so)?

    a) If not helpful in big projects, what are the difficulties that make us not to store locators in properties file?

    b) If it’s helpful, what are the precautions if that are taken makes job easier?

  2. Is storing locators in page class itself is best way in comparison with properties file?

Advertisement

Answer

I would argue storing the files in the page class itself. Loading from properties file would incur additional overhead or parsing a large file. Maintaining such a file would also be harder, even with a good tool support you would be forced to use CTRL + F more than you should.

Even on a more conceptual level it feels wrong. A good fit for storing in properties files are configurable parameters, and especially the ones that are good candidates to be tweaked in runtime.

Locators don’t have this nature. If the benefit you’re seeking is declaring in a central place you should instead use dedicated constant class, which will give you much better refactoring options.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement