AI programming: Get ChatGPT to Code and Test Your Next Web App

Muhammad Ali
March 7, 2023

As a software engineer, you're constantly looking for ways to streamline your coding process and improve the overall quality of your applications. So how exactly is AI used in programming?

AI is used in programming to generate code, write software tests, document code, explain complex code, and debug errors. AI cannot produce complex software applications on its own, but it can augment an engineer's workflow and speed up the development process.

The article examines two real-world examples of how developers use AI tools today.

Using plain english as your programming language

Clever Programmer is a popular channel on YouTube that offers tutorials on programming.

They discovered that you could get ChatGPT to code an entire functioning web app. Here are the prompts they used:

Prompt 1: Write me a todo list app with next js

This built an app for them that didn't have the function to add more tasks. So he gave another prompt to fix that.

Prompt 2: now add the ability to add todos

They further changed the way the app looks using another prompt.

Prompt 3: style it like Discord

This gave the app Discord's signature purple and dark grey theme. And this was the most impressive part because, without this, you would have a visual artist trying to figure out the exact RGB values of the Discord theme. However, with a 4-word prompt, you can get ChatGPT to style your app like Discord.

Basic to-do app
Basic to-do app

Then they used another prompt to test the AI's "intelligence."

Prompt 4: Add a feature, so every new todo I add adds an emoji to it

And sure enough, ChatGPT delivered. It came up with a script that added random emojis (from a list/array of select emojis) to every new todo added by the user. To be fair, we had to add the emojis to the array by modifying the script. Still, the fact that ChatGPT perfectly understood what was needed is impressive, especially regarding aesthetics.

This is an exciting example of how AI will now augment software development. Developers can type human language into the chatbox, and they will get an 80-90% working script that they can make functional with a few adjustments.

ChatGPT gets things wrong, for instance, how it created a to-do list app without the functionality of adding new items to it. Still, these are quick fixes, and these tools can come in handy for junior developers who want to debug their scripts or understand certain parts of the code.

Here's the YouTube video with the entire workflow:

Software Quality Testing using ChatGPT

Mayank Bhola is the co-founder and the head of product at LambdaTest. He wanted to explore the power of AI in automated software testing, and he did that using ChatGPT.

He used a series of prompts to generate scripts for Selenium and Java to perform automation testing using ChatGPT.

Prompt 1: Assume that I have a Selenium testing platform that allows users to point their Selenium tests on hub.lambdatest.com. This platform consists of 4 microservices responsible for the following details.

  1. The first microservice accepts Selenium tests and calls the second microservice to create a test entity in the database.

  2. The first service then connects with the third service, which provides it with a Linux docker container where Selenium jars and web browsers are present.

  3. Upon receiving the details for the docker container, the first service proxies the HTTP requests to the docker container.

  4. The fourth service collects test execution logs from the docker container and exposes APIs to return different logs for every Selenium test.

Let the first service be called a hub_service, the second service be called test_management_service, the third service is linux_container_service, and the fourth service is log_management_service. Write a Cucumber definition to test this platform.

And ChatGPT delivered! Despite the complex requirements, it came up with a script that can be used to generate the platform described above.

code box
Image credit to Mayank Bhola

Mayank then requested ChatGPT to create positive and negative test cases for all four scenarios from the first prompt.

Prompt 2: Write Cucumber tests for both positive and negative cases for all four services

Within a few seconds, Mayank had the Cucumber files for positive and negative testing scenarios, which usually took far more time.

code block
Image credit to Mayank Bhola

Now, Mayank wanted to see if ChatGPT could help him automate the test cases with the Playwright framework.

Prompt 3: Generate Playwright test implementation for the above Cucumber cases

And ChatGPT did precisely that. It generated a script that could be used to run the test cases it provided earlier.

However, Mayank wanted to run his tests on the cloud-based platform of  LambdaTest, and he wanted to modify the Playwright script so that it could authenticate the LambdaTest server. So, he asked ChatGPT to do it for him.

Prompt 4: Point the above Selenium tests to hub.lambdatest.com

This made his script specific for the LambdaTest platform. And now, he wanted to get this done for all four microservices requested in the first prompt.

Prompt 5: Modify the above test cases to query directly all four microservices

And just like that, with five simple prompts, Mayank got an entire workflow down within a few minutes that would have otherwise taken him at least several hours.

Of course, he ran into several challenges where he had to modify the script a little. And he admits that this made him realize that AI isn’t going to replace humans altogether just yet. Still, it did significantly help him decrease the time he would have spent working on a creating an automation testing pipeline. And it all got done in just five prompts is very cool.

Further reading about AI programming