AI-Driven Exploratory Testing Assistance Using ChatGPT in Google Colab
To simulate Exploratory Testing Assistance using ChatGPT in Google Colab, we can build a workflow where ChatGPT generates exploratory test cases based on user scenarios. This involves:
- User Inputs: Defining a hypothetical application and possible user flows.
- ChatGPT API: Interacting with OpenAI’s API to generate exploratory test case descriptions.
This example demonstrates how ChatGPT can help generate exploratory test cases based on user inputs or scenarios for an application.
Prerequisites:
- You need an OpenAI API key to interact with the ChatGPT API.
- You must have the
openai
Python package installed.
Step-by-Step Example:
1. Install OpenAI Python Client
!pip install openai
2. Set Up API and Define the Scenario
In this example, let’s simulate exploratory testing for a hypothetical e-commerce app where users can search for products, add them to a cart, and complete a purchase.
from openai import OpenAI
import os
# Set your OpenAI API key
os.environ['OPENAI_API_KEY'] = 'your api key handle with care'
client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
# Define a simple exploratory test scenario for an e-commerce app
exploratory_prompt = """
You are testing an e-commerce website where users can:
1. Search for products.
2. Add products to the shopping cart.
3. Complete the checkout process.
Generate exploratory test cases based on the user flow above. Focus on edge cases, error conditions, and unusual user behaviors that should be tested.
"""
# Send the prompt to ChatGPT
response = client.chat.completions.create(
model="gpt-4", # You can also use "gpt-3.5-turbo" if "gpt-4" is not available
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": exploratory_prompt}
]
)
# Print the generated exploratory test cases
print(response.choices[0].message.content)
Understanding the Example
Scenario Definition
The exploratory_prompt
outlines a basic user flow for an e-commerce app. You can modify this prompt to fit any scenario you’d like to explore.
ChatGPT API Request
The script sends the prompt to the gpt-4
model (or gpt-3.5-turbo
if gpt-4
is not available), asking it to generate exploratory test cases based on the given scenario.
Response Handling
The output is printed directly, showing test case ideas generated by ChatGPT.
Sample Output:
Here’s an example of the kind of test cases that ChatGPT might generate:
1. Test Case: Searching for a product with a keyword that does not exist or is misspelled. Validate the system's response, whether it returns no results, offers potential correct spellings, or related product suggestions.
2. Test Case: Searching for products by filtering via categories, price, popularity, and other criteria. Test how the system handles a filter parameter that does not match any products.
3. Test Case: Adding multiple quantities of the same product to the shopping cart to check the inventory control by the system.
4. Test Case: Adding a very high number or adding negative numbers of a product to the shopping cart.
5. Test Case: Attempting to add out-of-stock products to the cart.
6. Test Case: Removing and re-adding items from the shopping cart while also browsing and adding other products.
7. Test Case: Attempting to proceed to checkout with an empty shopping cart.
8. Test Case: Leaving items in the cart, logging out, and then logging back in to see if the cart retains its contents.
9. Test Case: Users simultaneously trying to purchase the same last product available, testing the system's handling of inventory conflict.
10. Test Case: Proceeding to checkout and applying a promo code for a discount. Alternatively, applying an expired or invalid promo code.
11. Test Case: Refreshing the page or unintentionally closing the browser during the checkout process.
12. Test Case: Completing the checkout process with outdated or insufficient payment information.
13. Test Case: Testing the system behavior when the checkout process is attempted from different geographical locations, especially if transactions should only be permitted in certain regions.
14. Test Case: Completing the checkout process without agreeing to the terms and conditions.
15. Test Case: Testing the site's performance when multiple users are checking out simultaneously.
16. Test Case: Testing the site's behavior when users try to checkout while there is a network disruption.
17. Test Case: Testing the system behavior when trying to checkout when the server or website suddenly goes down.
---
** TRY IT YOURSELF ** Google Colab Link
Customization:
- Modify the Scenario: You can modify the
exploratory_prompt
to fit other applications, such as mobile apps, banking apps, or social networks. - Generate Different Scenarios: You can adjust the prompt to explore different aspects, such as security testing, performance testing, or accessibility testing.
This example demonstrates how you can leverage OpenAI’s API in Google Colab to assist in exploratory testing by generating dynamic test cases based on user scenarios. You can further refine the prompts based on the specific type of exploratory testing you want to focus on.