How-To Leverage ChatGPT For Test Automation
How-To Leverage ChatGPT For Test Automation
Technologies like AI (Arti cial Intelligence), ML (Machine Learning), etc. can be easily
considered as one of the most in uential technologies that are having a monumental
impact on the technology ecosystem. Under the hood, AI-language models use complex
algorithms and learning techniques through which it understands and generates Natural
Language response.
ChatGPT by OpenAI is one of the most signi cant advancements in the eld of NLP
(Natural Language Processing). Such was the excitement around the product that close
to a million users signed up on ChatGPT in just ve days after the launch. As a user, you
can literally ask anything in a natural language to ChatGPT and the engine would provide
human-like answers based on the data trained on a massive dataset from the internet.
ChatGPT is super-powerful since it has the potential to write poems, construct emails,
craft social media content, and much more. Not to forget, ChatGPT can also be used in
various aspects related to automated testing, It can be used for test case generation, test
The fascinating thing about ChatGPT is its potential to craft human-readable, accurate,
working boilerplate code that can build the base for your test suite(s). It can leverage
popular test automation frameworks (e.g. Selenium, Cypress, Playwright, etc.) and
programming languages (e.g. Python, Java, etc.) to come up with the test code!
The icing on the cake is that ChatGPT can also create sample YAML les for running the
automation tests in a CI pipeline (e.g. Jenkins, CircleCI, etc.). In this blog, we deep dive
into the endless possibilities of harnessing ChatGPT for various activities related to test
What is ChatGPT?
Built by OpenAI, ChatGPT is a language model that is based on the GPT (Generative Pre-
has the capability to understand human-like questions and provide answers that can be
Since ChatGPT is pre-trained on a large corpus of data from the internet, it generates
responses that are ideally accurate and grammatically correct! In fact, OpenAI also offers
ChatGPT & Whisper APIs (Application Programming Interfaces), using which developers
A number of developers who signed up for the OpenAI API Beta Program managed to
create some useful applications using the APIs. For instance, a user created a fully-
The possibilities with ChatGPT and APIs offered by OpenAPI are endless but we would
restrict the discussion to ChatGPT and test automation. You can nd more such useful
applications here.
Pre-training stage
Fine-tuning stage
Reinforcement learning (or PPO optimization) is applied in the ne-tuning stage to ne-
tune the model so that ChatGPT provides a more accurate answer to the user(s).
As the name suggests, the response (or answer) is generated in the ‘Answer a prompt’
stage where the generated answer is shown to the user once it passes the safety and
moderation phase. We would recommend you to read How ChatGPT works to get more
Now that we have covered the essentials of ChatGPT, let’s look at some of the cases
where it can give a huge head start! Let’s look at the different types of testing (e.g. UI
like Selenium, Cypress, Playwright, etc. for testing interactions with elements in the DOM
(Document Object Model). Well, ChatGPT can be instrumental in generating the source
Here are some of the questions that we tried asking to ChatGPT, the answers were bang
on target!
As seen above, the code uses the CSS Selector for locating the elements in the DOM.
Though CSS Selector is a better selector than XPath, we still asked ChatGPT to provide us
with the code that uses the XPath selector for locating the WebElement.
Next we tried leveraging ChatGPT for creating an automation test that makes use of a
BDD (Behaviour-Driven Development) framework to perform the same task i.e. Search
“KiwiQA” on Google
Q. Can you provide the SpecFlow code which searches for “KiwiQA” on Google.
Shown below is the .feature le generated by ChatGPT. As seen in the snapshot, the le is
Feature File
Here is the step de nition le where the tool has created steps corresponding to the
Barring aside some minor issues that we listed earlier, the code looks perfectly ne. The
best part is that it also mentioned the dependencies that have to be installed as a part of
Note that in order to use SpecFlow with C#, you will need to install the appropriate
packages – SpecFlow, SpecFlow.NUnit, and SpecFlow.Tools.MsBuild.Generation. You will
also need to download and con gure the ChromeDriver executable le as well, similar to
the Java example.
We tried this after creating a project in Visual Studio and it worked like a charm! It also
gave the following note in the answer that acts as a “Word Of Caution”.
Many times, teams are confused on whether they should opt for BDD or TDD? Though
this opinion largely depends on the team’s expertise, ChatGPT can still be used to get
TDD.
In a nutshell, ChatGPT can provide you with code that can act as a good starting point for
kickstarting the activities in your automation project. Though the code needs to be
tweaked as per your project (or product) requirements, the boilerplate code provided by
ChatGPT can come handy in saving those extra hours that you (or your team) will
Since ChatGPT uses the information being inputted by the users to train their models, it
is recommended not to upload/ask any con dential information to the platform! You can
that you are able to accelerate the project delivery using the combination of AI and
human intelligence!
Travis CI, etc. to run automation tests in a continuous manner. There is extensive usage of
YAML les for de ning the pipelines with a speci c DSL (Domain Speci c Language).
We asked ChatGPT to create a Jenkins pipeline for running Selenium tests in parallel.
We upped the ante a bit and asked ChatGPT to port an existing Jenkins pipeline le to
CircleCI.
Here the con guration le (i.e. .circleci/con g.yml) was correctly identi ed as a YAML le.
The interesting part in the answer was ChatGPT recommending OpenJDK (instead of the
In a nutshell, ChatGPT can be used for creating pipelines for a range of CI tools like
developed as a collection of services that interact with each other using APIs. Here are
Microservices
C ontainers
Service mesh
Service discovery
API gateway
Since most of the software products are using microservices, we decided to try out
Q. We have three microservices running in our system. Can you please provide test code
to verify them out. The rst microservice comprises of Selenium tests, second test makes
entries into the MySQL database, and the third one does API testing using SoapUI
ChatGPT provided us with a Python test suite that uses Selenium, MySQL, and SoapUI to
ChatGPT also goes on to mention about the details of the tests and instructs to run the
In case your project is making use of the Microservices architecture, ChatGPT can provide
you with the base code for testing the respective microservice. It is important to reiterate
that the generated code for microservices testing can be used for educational or
reference purposes.
Now that we have looked into the broad usage of ChatGPT for test automation, let’s deep
dive into the Do’s & Don’ts of using this powerful tool/platform!
create test code for microservices testing, and more. Though inputs provided by
ChatGPT gives you the information on which you can further build your code, it needs to
be used with caution. First, let’s look at some of the major advantages of ChatGPT:
automation testing, DevOps, etc. Consider an example where you (as an automation
tester) is given the task to create a Jenkins pipeline to run those tests in a
continuous manner. In such cases, you can leverage ChatGPT to get high-level
information on creating Jenkins pipeline for running automation tests. The output
C reating scalable and reliable tests is an important factor that can play a huge role in
minimizing the efforts involved in test code maintenance. AS seen earlier in the UI
automation testing example, ChatGPT could quickly generate code that used a
more reliable locator like CSS Selector in the source code. This is where you can use
ChatGPT to generate test code that is more resilient, maintainable, and reliable in
Accuracy of ChatGPT
The accuracy level of ChatGPT is ~85 percent, a factor that should be enough to imbibe
con dence in this awesome tool! However, it is suggested not to upload any con dential
information (or code) to the tool; else it might have serious implications on your project &
organization.
Conclusion
ChatGPT has tremendous potential due to the depth in the answers provided by the
platform. If you are someone who wants to transition to automation testing/DevOps, etc.;
code on which you can further build the test cases (or test suite). Those worried about AI
taking away their QA jobs can relax, since an AI-tool like ChatGPT will help you in creating
AI can never replace human creativity which is why you should onboard an experienced
software QA consulting services company so that your make the best worlds – human