ChatGPT for Automated Testing: From Conversation to Code

Sauce AI for Test Authoring: Move from intent to execution in minutes.|xBack to ResourcesBlogPosted

April 23, 2026 · 9 min read · Testing Guide

Sauce AI for Test Authoring: Move from intent to execution in minutes.

|

x

Back to Resources

Blog

Posted December 21, 2022

ChatGPT for Automated Testing: From Conversation to Code

You & # x27; ve probably heard the buzz about what ChatGPT can fulfil but what testing chance are there for developers?

quote

You & # x27; ve probably heard ofChatGPT, the most late advance in Natural Language Processing that is taking the internet by storm with over one million user in just five days!

Released just a few week ago, the free AI chatbot & # x27; s overnight popularity is due to its ability to answer and explain conception patently, or perform complex tasks such as writing an article or telling a jest. For web and mobile app developer, there are broad implications for automated testing, since ChatGPT can write tryout event in a wide ambit of frameworks and languages. Let & # x27; s explore the possibility.

What is ChatGPT?

Created byOpenAI, ChatGPT is a large language model that was fine-tuned by supervised and reinforcement learning on tumid datasets. Using algorithms, ChatGPT analyzes the datum to find patterns that help it understand natural language and how words are used in context. It is a dialogue-based framework, which signify that it is designed for a dorsum and forth chat-like interaction. You can ask ChatGPT to say whatever you want that the scheme doesn & # x27; t study offensive.

ChatGPT can generate creative and on-topic responses, frequently provide item on why it generates a specific answer. It can too remember its former responses to have a (mostly) coherent conversation. ChatGPT has be asked to generate everything from answers to inquiry on stain physics to writing folk strain about beer!

ChatGPT and Automated Testing

One of the almost interesting features of ChatGPT to those of us in the software space is that it can generate properly formatted and relevant codification based on a simple natural language request. It can yield codification in many languages and can employ legion built-in packages across those languages. So, the natural question is, can ChatGPT be used to generate code for?

The answer at this point is, & quot; Yes, sort of. & quot; ChatGPT can compose Selenium in multiple languages, as demonstrated by Sauce Labs & # x27; ownNikolay Advolodkinin his video,ChatGPT Can Code Better Automation Than Me.

But be able to write codification that looks exact is simply the kickoff. In an idealistic world, one would provide ChatGPT with a description of the trial to generate, it would know all the item about the version of the website one is testing, and it would generate perfect, executable code that needs no modifications. ChatGPT currently can & # x27; t do that. What it can do is still quite impressive though.

Let & # x27; s start with a use case for ChatGPT, not to completely replace testing engineer, but alternatively as a new low-coding method.

What is Low-Code Testing?

Low-code development allows citizenry to write code with slight to no coding experience, using drag-and-drop development platform or plain English.Low-code testingsolutions lower barrier to writing test code by making it easy to scale development organizations. Since tests can be pen without a technical skillset, low-code is simpler for team to write test automation code, reducing test debt.

ChatGPT can be viewed as a powerful low-code tool for compose test cases. ChatGPT accepts natural language as stimulation, so users can write in their natural beat and notwithstanding be understood, unlike template-based models which much rely on particular language structure or key phrases. As we will show, ChatGPT does a remarkable job of generate test automation scripts, class, and functions.

A Language for Low-Code: Cucumber

While ChatGPT can generate many languages and libraries, its sweet place is its power to generateCucumbercode. Cucumber is a test framework that usesbehavior-driven development. Scenarios are indite in plain English, with some key terms like & quot; Given, & quot; & quot; When, & quot; and & quot; Then & quot; in a feature file. Then, in footstep definitions, these natural language phrases are associated with codification.

Test upkeep is one of Cucumber & # x27; s benefits since Cucumber scenario compound the natural language aim of a test with the automation code which implements it. This lets testers who aren & # x27; t as familiar with test codification understand the linkage between test purpose (in natural speech) and test code. This leans into ChatGPT & # x27; s posture of return natural speech with associated source code.

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

ChatGPT and Cucumber Test Case Example

Now let & # x27; s see what ChatGPT can do.

As you can see in the undermentioned example, ChatGPT & # x27; s ability to generate code is rather telling. With a simple prompt, it can yield the scenario and the pace definitions employ by Cucumber all at once. It even knows the different components Cucumber needs to run without being explicitly told.

Cucumber Example

The prompt is obscure about what to test on the website, but ChatGPT nevertheless generates a script to test one of the chief features of the Google website, its search functionality. In this example, it still correctly identifies the name of the search bar for Google, & quot; q. & quot;

A General and Manageable Script

While this is a full example of ChatGPT & # x27; s power to write codification in general, not all site are as ubiquitous as Google. Its accuracy in predicting the identifier & quot; q & quot; does not betoken it will always be correct. And, from testing ChatGPT, we know that if it doesn & # x27; t know an precise element locater, it will get one up.

Going through the generated code and finding and supercede all element locators is dull, but the problem can be made much easier by separating the codification about the page itself from the test cases. We do this by using a page object model. Using a page objective framework likewise allows us to update the code if element locators or the construction of the app changes between tests, improving the maintainability of the testing script.

In the following example using Cucumber in Python, we render a generic test for a login page of a website and instruct ChatGPT to use a page object model and grade variables for the element locators.

More specific ChatGPT cucumber python example

ChatGPT right generated the aptly named LoginPage objective which represents the element locator as class variables and has method for the common functionality on login pages, such as entering one & # x27; s username. The footstep definitions, at the bottom of the example, use the method in the LoginPage to interact with the website.

Now, using the page framework target and the step definition, it seems as though a user could either automate (with ChatGPT) or manually write scenario to test the website and have working test codification! But, will it actually work as-is?

Using ChatGPT to Change and Fix Code

If you look closely you can see all the input values for the test, such as the URL, username, and password, are all hard-coded into the step effectuation. It is unlikely that the website you are testing will be & quot; http: //www.example.com/login & quot; and that a working username and password combination will be & quot; username & quot; and & quot; password & quot; respectively. And these value do not ask to be hard-coded, Cucumber can conduct variables from the feature file in the scenario.

But what if you don & # x27; t know how this is format or don & # x27; t need to spend the time to update all the codification? Well, you can ask ChatGPT to fix it for you.

ChatGPT code change request

By requesting ChatGPT to update the previously give code, we can fix the problem. The updated step execution read in the values that we requested instead of hard coding the most likely incorrect values. That is one of the remarkable feature of ChatGPT: the conversational nature of the poser allows you to tell the system exactly what you want to change in the codification, and it is quite good at listening to and executing your requests.

ChatGPT and Sauce Labs

ChatGPT can generate test script that are compatible with Sauce Labs. Since lam your script on Sauce Labs requires completely updating how the exam is launched using, having ChatGPT write an accurate startup method could be vital to a user without much coding experience. By just adding & quot; and run the test on Sauce Labs & quot; to the prompt we can generate a playscript that includes an accurate method to start the test.

Start ChatGPT Test on Sauce Labs

The 3rd code cube includes the code to start testing using Sauce Labs. ChatGPT use the right URL, passes the necessary capabilities, and uses the correct driver method to start the test. While it arbitrarily decides which platform, browserName, and version to use, these are easily update either manually or by telling ChatGPT to update these features. It is that easy to run a test generated by ChatGPT on Sauce Labs!

The Downsides of ChatGPT for Automated Testing

While ChatGPT has a lot of possible to be a low-code solution for machine-driven testing, it even has issues. Users necessitate some understanding of the app under trial and the cryptography words and packages be used when generating codification since the system much needs to be recite to correct issues. ChatGPT make not run the code itself and so has no way to cognize if the codification give is truly runnable. One recurring issue is that the Xpaths or IDs need to be manually updated to accurately situate the correct element, as ChatGPT not only does not know these identifier, it will fill in random identifiers so that the output codification is as complete as possible.

Also, we found the model do not know what method have be deprecated. It repeatedly used the & quot; find_element_by_ * & quot; method to site elements on the blind, even though that method is no longer functional. Simply enquire ChatGPT to update the code with the right method is a authentic way to correct the problem, but it does require the power to realize what the issue is.

Another job with the above code is the step description do not always accurately reflect what is being try in the script. For example, the step & quot; I should see my username & quot; {username} & quot; is in the top right nook & quot; uses the method & quot; expected_conditions.presence_of_element_located (), & quot; which merely insure to make sure that the component is present on the DOM of the page, not that it is located in a particular part of the screen.

Finally, ChatGPT will assume some common page structures in its test code. The previous examples have both the username and password inscribe on the same page before submitting, but some websites have you first input the username, so click a button like & quot; Next & quot; and then input the password. A exploiter can use ChatGPT & # x27; s dialogic nature to rectify issues such as these, but, again, one must be able to recognize they are an issue to request an update corrected version.

Conclusions

ChatGPT is a very potent natural words model with enormous potential. What it can do is substantial and it likely will lead the way in low-code testing solutions to many problems. It has the voltage to do that for testing, but one still needs to have a reasonable understanding of both the language being used and the app under tryout to get use of ChatGPT as it is. But we shouldn & # x27; t underestimate its potential: ChatGPT is truly telling code contemporaries that wasn & # x27; t possible with previous natural language generation models.

Ready to start your automated prove journey?Sign up for a Sauce Labs gratuitous trial today.

Published:
Dec 21, 2022
Share this office
Copy Share Link
LinkedIn
© 2026 Sauce Labs Inc., all rightfield earmark. SAUCE and SAUCE LABS are registered earmark owned by Sauce Labs Inc. in the United States, EU, and may be registered in other jurisdictions.
robot
quote

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free