In the rapidly evolving world of software testing, where faster and more efficient software delivery continues to rise, automation testing must evolve to keep the pace. Faced with these challenges, for one of our projects at SourceFuse we decided to revamp our approach by adopting CodeceptJS, an end-to-end testing framework. And we didn’t stop there!
We further enhanced it by integrating artificial intelligence (AI) to tackle complex scenarios. AI-powered capabilities built into CodeceptJS provided us with innovative flexibility, self-healing testing, and intelligent decision-making – perfect for scaling the testing needs of our project.
In this blog, we explore the role of AI in test automation, CodeceptJS capabilities, and how to integrate the two in order to enhance automation testing.
Why CodeceptJS?
CodeceptJS is the open-source test automation framework that has AI features to improve the testing experience. Before diving into the AI aspect, let’s understand why CodeceptJS stands out in the automation landscape and why we have chosen this for our project.
- Multiple Framework Support
CodeceptJS tools can be integrated easily with popular frameworks like WebDriver, Puppeteer, Playwright, and TestCafe that provide the flexibility to work with existing frameworks. - BDD-Style Syntax
Writing the test cases in Gherkin Language, which is a plain English language in BBD style, makes it more suitable to work with since all team members (developers and testers) can easily read and understand the test cases. - Parallel Execution
Parallel Execution is also one feature which enhances the test speed in large projects and helps to meet critical deadlines. - Modular Structure
While setting up the tool, CodeceptJS automatically creates the modular structure for projects that improve code maintainability and the reusability of test components.
The Need for AI in Test Automation
Manual testing is often time-consuming, repetitive, and error-inducing. Even with automation frameworks like CodeceptJS, maintenance of automation scripts is quite difficult and this is where AI comes into the picture. We can leverage the AI driven methods in our test automation through:
- Test Data Generation: With AI, based on previous runs we can generate unique and distinctive types of data dynamically which ensures better test coverage.
- Script Creation: Scripts can be effortlessly and quickly generated with AI by the usage of plain English language which saves a lot of the manual efforts.
- Self-Healing Test: AI can self-heal the test cases by way of correcting the locator at run time. This reduces the fake failures and ensures smooth execution of the test, even with minor UI changes.
- Enhanced Error Detection: AI can compare the webpage styling, patterns, and the results of any early defects which improves the overall quality of the product.
Implementing AI in CodeceptJS
We have integrated OpenAI with CodeceptJS in our SourceFuse project to harness its powerful AI capabilities. It simplifies test automation by leveraging the AI to create, maintain, and develop the test script.
- Self-Healing Tests: With AI, tests will not break on a change in UI. AI can mechanically identify changed factors, regulate the locators, and update tests in run time.
- AI-Driven Locator Strategy: AI tools can examine the whole Document Object Model, recognize context, and create resilient locators which are less likely to break during application modifications.
- Auto-Generated Tests: AI can autonomously analyze the application, track behavior, and generate test scripts.
- AI-Generated Test Data: AI can generate dynamic data and take a look at records that adapt to the application’s needs.
- Visual Regression Testing: By integrating visual AI tools, such as Applitools Eyes, AI can compare the UI and ensure that both functional and visual aspects of the application are tested thoroughly.
How to Configure CodeceptJS AI
To configure the CodeceptJS AI first we need to install below plugin and follow the below steps:
- Install CodeceptJS AI
- npm install @codecept-ai/ai –save
- Configure CodeceptAI
- Open Codecept.conf.js file and below plugin configurations:
- Now add pause() in your script from where you want AI to write script on behalf of you and run the command: npx codeceptjs run
- Script will stop at a pause point. After that you can give the instructions in plain English language to write the following code on behalf of you, e.g. I am at the login page and I want to enter my username and password to proceed next.
If BDD framework is used in your framework, AI will give you code in Steps definitions.
Configure Self-Healing
To configure Auto-healing, setup the auto-heal plugin in codecept.conf.js file as shown:
Once the plugin is set up, execute the test. In case of any UI change, script will be auto-healed and at the end of execution, and the locators which were healed during the execution will be listed.
Key Benefits of Using CodeceptAI in Our project
The benefits of incorporating CodeceptAI in our SourceFuse project were immense:
- Quick Scripting: AI feature in CodeceptJS enabled us to provide quick solutions, automate the feature quickly, and reduce the significant number of manual efforts.
- Reduced Maintenance: Automatic test healing and AI-based strategies reduce the need to manually fix the broken test and significantly reduce maintenance costs.
- Smarter Test Execution: AI-powered test selection optimizes test execution, performing high-impact tests based solely on code changes.
- Improved Testing Accuracy: By using AI for dynamic test data generation, visual regression, and a smarter locator, testing becomes more robust and accurate.
- Faster Releases: Â As UI changes can be handled with AI, it thereby reduces the maintenance efforts shortening development cycles and enabling faster deployment.
Conclusion
Integrating artificial intelligence into CodeceptJS transformed our test automation strategy at SourceFuse. Not only did it make our automation extra efficient, it also made it smarter. By leveraging self-healing tests, AI-pushed locators, smarter check selection, and visual AI tools, we reduced the manual efforts, increased the test accuracy and made our automation resilient in the face of rapid change. This experience has proven to us that with the right use of AI, CodeceptJS is not just a tool, but a game-changer for modern test automation.