5 Selenium Test Automation “Hacks” You Will Probably Learn Only From StackOverflow
First is installing One Dark Pro theme on IntelliJ IDEA and Visual Studio Code. Kidding! Although One Dark Pro is both beautiful and useful for night owls like myself, this post is not going to focus on that. Let’s look at some things your university may not teach you therefore you have to learn it the hard way at work by Googling and skimming through Stack Overflow/ SQA - Stack Exchange.
Some might argue that these hacks are not best practices. Nevertheless, if you want to just get it done, it’s up to you. I’m a bad programmer and feel free to correct if there are mistakes here.
1. JavaScript Executor
Element not interactable. Very confusing at first. You double-check the XPath or CSS Selector just to make sure and don’t see anything wrong. You may even insert a shameless Thread.sleep(😴) and end up with nothing but the “Element not interactable” exception when you run your test. JavaScript Executor might save your arse in this case.
2. Disable Site Isolation Trails on Chromium
This is a tricky one and I didn’t even bother to understand why. You can read more about it here: https://bugs.chromium.org/p/chromedriver/issues/detail?id=2660
It occurred to me when working with a page with an iframe. Switching to iframe and thereafter switching back to default gave me headaches by failing to continue tests. Adding the following arguments to ChromeOptions magically fixed the issue.
3. Faker
This is a gold mine. When there are tests you must enter names, addresses, etc. this library will automagically generate fake data. Faker has a collection of information from popular movies and tv shows as well. Your test data doesn’t have to be lackluster anymore.
Faker: https://github.com/DiUS/java-faker
4. WebDriverManager
This one is no secret to many. WebDriverManager manages drivers for web browsers, so you don’t have to download Selenium drivers and place them in a hard coded path of your project, especially when there are big updates to web browsers.
WebDriverManager: https://github.com/bonigarcia/webdrivermanager
5. Jason’s friend “Gson”
Very helpful when it’s required to fetch input from a JSON file and also when required to write to a JSON file. When used in combination with get()/ set() methods in a POJO file, it’s possible to achieve a kick-ass, dynamic automation suite.