GenAI has proven to be a game-changer for complex coding tasks, simplifying processes that were once labor-intensive and time-consuming. In this article, we’ll share how GenAI GPT-4 helped us rewrite our entire test automation framework from C# to Java in just six hours—a task that would have otherwise taken months to complete manually. This showcases the powerful potential of GenAI in transforming how we approach software development.
At First Line Software, we originally built our test automation framework in C#, using Selenium and SpecFlow, to align with the .NET development environments of our key clients. While this ensured consistency between development and testing, it also posed challenges. C# is not widely adopted within the Selenium community, which meant we had to create custom code and wrappers over time to streamline our automation processes. These custom components helped us overcome C#’s limited adoption in Selenium, but they added complexity and made maintaining the framework more difficult over time.
The most valuable feature of our framework—and the driving factor for switching to Java, a more popular and supported language for Selenium—was a custom module that automatically recognized web page selectors using Gherkin common steps. This eliminated the need to manually write selectors or build a Page Object Model. With this module, testers could simply specify the text next to the element, and the framework would automatically detect it during test execution.
For example:
However, adapting this framework to Java seemed like a monumental task due to the complexity and scale of our existing C# codebase. The C# framework had grown to over 5,500 lines of code over the course of five years, and manually rewriting this code seemed like an insurmountable task. That’s where GenAI came in, rewriting our framework from C# to Java in just six hours. By gradually feeding portions of our code to GenAI, it converted the logic into Java syntax using standard Java libraries for Selenium, drastically simplifying the process and saving us months of manual work.
In short, GenAI not only transformed how we adapted our framework but also demonstrated how it can simplify and accelerate large-scale development tasks, offering immense value for future projects.
Best Practices for Using GenAI in Test Automation Framework
When using GenAI for a task like rewriting a codebase, it’s important to follow a few key practices:
- Provide Code in Order of Dependencies: Start by feeding GenAI the final methods and then move on to the methods those depend on, ensuring that the model understands the project’s structure.
- Maintain Context: GenAI can sometimes lose track of context, especially when it comes to initializing names for dependent methods, so it’s important to monitor this closely.
- Submit Code in Small Parts: To prevent GenAI from missing important details, submit code in smaller sections. We found that sending 100 lines at a time worked best, as larger chunks led to errors or incomplete conversions.
- Preserve Method Names: Instruct GenAI not to change method names. This is crucial for maintaining consistency across the codebase and making sure the final project can be pieced together seamlessly.
Challenges with GenAI-Generated Code
While GenAI significantly speeds up the process, the generated code isn’t flawless. It requires careful inspection and refactoring by a specialist to address issues and ensure the final product works as expected.
One of the biggest challenges we encountered was aligning our custom C# framework with Java’s Selenide framework. Selenide provides built-in methods for handling implicit waits, exception handling, and detailed error logging, which meant some of the custom functionality we developed for C# became redundant. For example, GenAI rewrote our method for clicking on elements, but Selenide already has an efficient XPATH-based element locator and a built-in click() method.
For example, GenAI rewrote the method for clicking on elements as follows:
However, Selenide already includes built-in functionality for implicit waits, exception handling, and detailed error logging. As a result, the method can be simplified by using Selenide’s XPATH-based element locator and its click() method, as shown in the following representation:
Additionally, because of the syntax differences between the SpecFlow BDD framework in C# and Cucumber in Java, it was necessary to identify and correct issues in the AI-generated code, such as the inclusion of unnecessary quotation marks.
There were also more subtle challenges related to Java-specific syntax and code style. For instance, GenAI sometimes generated inconsistent names for classes, methods, and interfaces, which required manual refactoring to align with Java’s conventions.
Another issue was the presence of unnecessary brackets in some method and class implementations. Since the brackets were correctly paired, neither the IDE nor the AI flagged them as errors, making them harder to detect and resolve.
In conclusion, using GenAI significantly reduces the time required to rewrite code in a different programming language and minimizes routine tasks. At First Line Software, we actively leverage this to optimize processes, including test automation. However, human oversight and thorough code review remain essential to account for the nuances and specific details that AI cannot always handle correctly. While GenAI is an incredible tool for accelerating large-scale development tasks, it’s important to ensure that human expertise remains a critical part of the process.
Ready to transform your software development processes? Let’s discuss how GenAI can streamline your next project. Contact us today!
Alexander Meshkov
Gen AI QA Director at First Line Software
Alexander Meshkov is QA Delivery Director at FLS. Alexander has over 10 years of experience in software testing, organization of the testing process, and test management. A frequent attendee and speaker of diverse testing conferences, actively engages in discussions and keeps up-to-date with the latest trends and advancements in the field.
Konstantin Loginov
Senior QA Automation Engineer at First Line Software.
With seven years of experience in quality assurance and test automation, Konstantin Loginov excels as a facilitator and advocate for automating software testing processes. His focus is on reducing product delivery time, minimizing the impact of human factors, and increasing process efficiency.
With a PhD in Computer Science, specializing in corporate education, he strives to accumulate and disseminate best practices in QA automation. His goal is to ensure foolproof and reliable test automation processes within the company.