Enforcing best practices throughe the library itself

Skip to first unread message

Ireneusz Pastusiak

May 27, 2022, 1:30:59 PM5/27/22
to Selenium Developers

It has been around 10 years since I first used Selenium. I can remember it was quite common at that time to see code using Thread.sleep(), very long absolute XPath locators, as well as some other anti-patterns. Since then I have used Selenium on a number of different projects and witnessed endless conversations on how to use (or not to use) Selenium properly. Sometimes people develop their own bespoke frameworks trying to prevent others from common anti-patterns. Sometimes people resort to open source frameworks that other people created. Today I can still see many of the underlaying problems haven't been addressed, despite the proliferation of Selenium-wrapping frameworks.

I think we don't need yet another Selenium wrapper. What we need is the ability of Selenium itself to detect misuse when possible and log a warning or throw an exception when people are doing it wrong. Even if not all misuse can be prevented, some of it can be detected.

There are certainly limitations to what can and cannot be done. There certainly would have to be a discussion about what is or is not right, should there be an override possible for people to disable the checks etc.

For me, one of the most obvious candidates would be an absolute XPath locator longer than X characters or X levels. If user passed that in, IllegalArgumentException or the like could be a potential candidate. Or at least the user could get a warning logged. This is obviously just scratching the surface in order to indicated potential direction.

What do you think?

Reply all
Reply to author
0 new messages