If you have ever been involved in automated testing of web applications, you have probably wondered which framework is the ideal one, and how to choose the most convenient tool to quickly and effectively evaluate the results of automated tests.
The answer is as simple as answering "what's two plus two?" Those who answered "5," "7," or "2" should continue reading this post. And those who answered "4" can also find something useful here. In this article, you won't see a single line of code, just my impressions from getting to know the JDI framework and the SauceLabs cloud platform for running tests. So let's dive in…
Getting closer to the topic, I worked on a project using Selenium WebDriver as the basis for building a test framework. There was also a useful tool developed in-house that analyzed test results with extensive functionality. Tests were run remotely on virtual machines on a dedicated server. Without going into details, using WebDriver to write test scenarios in practice helped me notice many nuances that could cause the framework to collapse like a house of cards. Another essential skill for a test automation engineer is not only the ability to write a stable test but also to quickly understand the reason for its failure and provide relevant, unambiguous feedback to a team of developers, or to make changes to the failed test itself. This requires understanding the logic of the tested application, properly setting up logging, and, of course, the ability to view the history of test runs over a certain period of time.
As a result, I disassembled the project application brick by brick and reassembled it like a Lego set. It seemed simple enough: use a similar model on other projects, and you'll be happy. But in IT, in my opinion, it doesn't work that way. Being in this field, you are constantly searching and discovering new technologies. And just two weeks ago, I came across an alternative test framework called JDI. More precisely, JDI-light, written above WebDriver. The first question that came to mind was "why?" What is the purpose of having an additional layer between myself as a tester and the well-regarded Selenium tool?
After a brief dive into JDI, my answer is as follows: if the technology allows for minimum costs and effort to perform the same work more effectively, it deserves to exist. Moreover, the market favors those who can adapt quickly to new conditions. However, it is worth considering that no matter how modern the hammer is, if you start hammering not nails but screws, it will be less effective than using a screwdriver.
So, how easy is it to get started with JDI?
If the project is new, simply add dependencies on JDI-light, the testing framework (such as pytest or JUnit), and the reporting tool, depending on preferences. By default, you'll have a ready-to-use WebDriver (Chrome) and pleasant built-in logging. You can make finer settings by uncommenting or replacing default values in the properties file.
If the project has been around for some time, you'll need to replace the Selenium dependency with JDI-light and change the import of the PageFactory pattern in your code from Selenium to JDI. Don't be too deceived – the project might launch on the first try, but to get all the benefits JDI provides, you'll need to work a bit harder – that's a topic for another post.
One drawback might be the introduction of additional typing for web elements. JDI typing offers several advantages, such as significantly reducing the amount of typed code, improving its readability, and providing a wide range of additional functionality "out of the box" that was previously implemented in the page object model manually. If you need to define a custom type or perform complex actions with an element, inheritance and polymorphism mechanisms still apply.
We could discuss JDI's features and benefits for much longer, but let's not dwell on this as the documentation and templates are available on GitHub in an easy-to-understand format.
One more tip: working with various tools is just as easy to set up. Integration of Selenium WebDriver with tools like Selenoid, BrowserStack, Applitools, and SauceLabs is straightforward and has many advantages.
I also recently had the opportunity to explore the capabilities of SauceLabs and can attest to its appeal, though the free trial period lasts only two weeks and has a limited total duration of running tests (1h 35min). Another downside is the frequent issues with user registration on the platform. I also encountered this problem, but a brief conversation with tech support helped resolve the issue and let me use the free trial period.
SauceLabs offers an extensive collection of operating system, browser, and device configurations, with the ability to run tests in parallel – up to 18 tests at a time and schedule new batches after completion. It provides logs, screenshots, and videos for your tests, with the possibility of executing failed tests manually, although I couldn't get this to work – this feature may only appear after purchasing a subscription.
So, how do you connect a JDI project to SauceLabs? It's very simple. Go to the properties file and uncomment the line 'remote.type=sauce' if you have registered your location with the European data center. If you're registered with the American data center, uncomment the 'driver.remote.url' line in the same file and replace the URL with the one in your SauceLabs profile. If you don't want to hard-code your access details in your project, you can set two environment variables, SAUCE_USERNAME and SAUCE_ACCESS_KEY, which can also be found in your profile. Now, you can click the start button in your favorite IDE and watch the test run online, or ask Maven to run the tests by passing the parameters '-DSAUCE_USERNAME={username} -DSAUCE_ACCESS_KEY={accessKey}' on the command line.
That wraps up my review of JDI and its integration with SauceLabs. My conclusion is that there are no perfect tools, but there are those that can significantly facilitate a programmer's work under certain circumstances. I have added JDI to my list of possible contenders for future test automation projects, and SauceLabs, as a cloud testing service, has also caught my attention.
Useful links:
Comments