0% found this document useful (0 votes)
10 views5 pages

ChatGPT For SDET

Uploaded by

mrpalitaev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

ChatGPT For SDET

Uploaded by

mrpalitaev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

SDET guide for manual usage

Owerview
You can run the tool’s workflow manually. You need to get the content of your project’s Swagger
JSON file and follow the steps below:

This guide is designed to assist Software Development Engineers in Test (SDETs) in manually
utilizing the ChatGPT tool's workflow for their projects. In scenarios where automation is not
feasible or for those seeking a hands-on approach, this manual process allows you to effectively
interact with the tool to generate the desired results.
To get started, you will need your project's Swagger JSON file and follow the outlined steps. The
initial step will involve obtaining a template with placeholders for your project information and
initiating a chat with ChatGPT to begin the process. This guide will walk you through these steps
in detail, ensuring a smooth and effective manual usage experience.

First step
In your first message, you need to get the template below and replace the tags with your project
information. Paste this template below in a chat with ChatGPT.

<api_description>

A good list of test cases should include cases for:


- all the possible status codes
- various request parameters, request headers
- response body content
- positive, negative, and edge cases
To help test <api_method> <api_path> API <api_summary>, list diverse
scenarios which <api_method> <api_path> API <api_summary> should
handle. Format them as an ordered list, one case per item.

In this template, you need to replace the tags with your information:
● <api_description> - you can replace it with your JSON file, or you can describe it in
human language.
● <api_method> - HTTP method, such as GET, POST, DELETE, etc.
● <api_path> - API endpoint, such as /pet/{pet_Id}
● <api_summary> - if your API endpoint has a summary, then you can provide the
summary for this API endpoint.

Prompt example: in this scenario, I want to test the/pet/{pet_Id} endpoint, so my first message
will look like this:
{'openapi': '3.0.2', 'info': {'title': 'Swagger Petstore - OpenAPI
3.0', 'description': "This is a sample Pet Store Server based on…

A good list of test cases should include cases for:


- all the possible status codes
- various request parameters, request headers
- response body content
- positive, negative, and edge cases (in this case “edge cases” means
that test verifies whether a system can handle extreme or
out-of-ordinary scenarios considered unlikely to occur in normal
usage)
To help test get /pet/{petId} API (Find pet by ID), list diverse
scenarios that get /pet/{petId} API (Find pet by ID) should handle.
Format them as an ordered list, one case per item.

Second step
You will get a bunch of test cases from the LLM. You need to ask it to generate tests for a range
of those test cases since the LLM might implement only a part of those test cases and write
something like “implement remaining tests as I did.”
In this template, you need to replace the tags with your information: <test_cases_range>
where <test_cases_range> is a range of generated test cases. For example: 1-10, 11-20, …

You can do this this way:


You are a world-class Python developer with an eagle eye for
unintended bugs and edge cases.
A good API test suite should aim to:
- Take advantage of the features of `pytest` to make the tests easy
to write and maintain
- Tests should create and delete all the required data (using POST
and DELETE methods)
- Be easy to read and understand, with clean code and descriptive
names
- Be deterministic, so that the tests always pass or fail in the same
way
- You must create assertions with error text, like this example
`assert condition, "The condition is not appropriate."`

Implement API test suite in code for test cases <test_cases_range>


listed above. Reply only with code. Use Python and Pytest and
recommendations for good API test suite given above.
Here is an example how can you implement test for GET /pet API (use
it only for a reference, don't merge it with your code):
```python
import requests, pytest

API_URL = "https://petstore3.swagger.io/api/v3"

@pytest.fixture()
def pet():
pet = requests.post(f"{API_URL}/pet", data={"id": 1, "name":
"cat", "status": "cute"}).json()

yield pet

requests.delete(f"{API_URL}/pet/{pet['id']}")

def test_get_pet(pet):
get_pet = requests.get(f"{API_URL}/pet/{pet['id']}").json()
assert "name" in get_pet, "There is no name"
assert "id" in get_pet, "There is no ID"
assert get_pet["name"] == pet["name"], "Names are different"
assert get_pet["id"] == pet["id"], "IDs are different"

```

Now is your turn. Continue the following code:


```python
import requests, pytest

Prompt example: let’s continue the previous example in this step. Don’t forget about secrets
and sensitive data! Don’t send it to ChatGPT:
You are a world-class Python developer with an eagle eye for
unintended bugs and edge cases.
A good API test suite should aim to:
- Take advantage of the features of `pytest` to make the tests easy
to write and maintain
- Tests should create and delete all the required data (using POST
and DELETE methods)
- Be easy to read and understand, with clean code and descriptive
names
- Be deterministic, so that the tests always pass or fail in the same
way
- You must create assertions with error text, like this example
`assert condition, "The condition is not appropriate."`

Implement API test suite in code for test cases 1-10 listed above.
Reply only with code. Use Python and Pytest and recommendations for
good API test suite given above.

Here is an example how can you implement test for GET /pet API (use
it only for a reference, don't merge it with your code):
```python
import requests, pytest

API_URL = "https://petstore3.swagger.io/api/v3"

@pytest.fixture()
def pet():
pet = requests.post(f"{API_URL}/pet", data={"id": 1, "name":
"cat", "status": "cute"}).json()

yield pet

requests.delete(f"{API_URL}/pet/{pet['id']}")

def test_get_pet(pet):
get_pet = requests.get(f"{API_URL}/pet/{pet['id']}").json()
assert "name" in get_pet, "There is no name"
assert "id" in get_pet, "There is no ID"
assert get_pet["name"] == pet["name"], "Names are different"
assert get_pet["id"] == pet["id"], "IDs are different"

```

Now is your turn. Continue the following code:


```python
import requests, pytest

Third step
After the LLM generates all tests, ask it to merge all generated tests. In this case, you need to
replace the <test_pairs> tag with all pairs that you provided to your LLM.
For example: if you used 1-10, 11-20, 21-30 ranges, then you need to replace <test_pairs>
tag with “1-10, 11-20, 21-30”.
You can do this this way: Merge code generated for <test_pairs> test cases
into one file. Don't merge any samples given to you.
Prompt example:
Merge code generated for 1-10, 11-20, 21-30 test cases into one file.
Don't merge any samples given to you.
At the end of this example, you will receive API tests for the GET /pet/{pet_Id} endpoint.

You might also like