ChatGPT x Cypress.io API tests [shorts]

Good morning!

As I was basking in the sun on this Himalayan winter morning, it hit me what if I could generate all my test scenarios (which I often write in Cypress.io) using OpenAI ChatGPT. Following is the documentation of what I have found (TL;DR QA Automation engineers are safe for now 😉)

For those of you who have been living under a rock, OpenAI ChatGPT is a conversation language model which can answerquestions,  followup questions, admit its mistakes, challenge incorrect premises, and reject inappropriate requests.

more info: https://openai.com/blog/chatgpt/

Starting point

I wanted to do minimal work, as I didn't want to explain everything first to the ChatGPT language model, so I took the liberty of finding a simple OpenAPI CRUD swagger spec https://gist.github.com/Daniyal-Javani/5b91ed8c492d62a528ebb7d61ceeb419 and converted it to following swagger.json with little modification

I started with a basic question:

I followed up with

Attempt #1:

Pretty good test scenario recommendations

Attempt #2:

meh!!

Attempt #3:

I would say much better!!

The Ultimate Question:

ChatGPT generated a sample code in cypress:

After fixing some Syntax issues in this generated Code and adding a mocked baseUrl

you can use Mockoon an excellent tool to create a mock server based on the OpenAPI Spec used in this article above

Let us validate these generated tests in a Cypress project:

Cypress Test Runner Result

Even though the generated test Scenarios are greater than the actual test generated by ChatGPT.

Based on this small exercise, it is safe to say QA Automation engineers are safe for now :D

Shout out to Mockoon, which is an excellent API mocking solution, the bit I liked most about this tool is how easy it is to create a mock server based on the OpenAPI 3 spec
https://mockoon.com/docs/latest/openapi/import-export-openapi-format/

More on ChatGPT:

Until Next Time!! 👋