Spaces:
Runtime error
Runtime error
File size: 3,323 Bytes
2dcb1ad def9376 2dcb1ad def9376 2dcb1ad def9376 2dcb1ad 097056d b1b1f5e 2dcb1ad 097056d b1b1f5e 097056d b1b1f5e 2dcb1ad b1b1f5e 2dcb1ad 097056d 17b88d7 def9376 097056d 6a5ecf7 097056d 6a5ecf7 097056d 6a5ecf7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import os
import streamlit as st
import openai
# Read OpenAI API key from environment variable
openai.api_key = os.getenv("OPENAI_API_KEY")
if not openai.api_key:
st.error("No OpenAI API key found in the environment variable OPENAI_API_KEY")
conversation_tc = [{"role": "system", "content": "You are a technical and a professional QA manager, working in a technological firm. You provide test cases for a scenario. "}]
convo_py = [{"role": "system", "content": "You are a technical and a professional QA manager who specializes in Python Unittest, working in a technological firm. You should provide Python Unittest test scripts in for the test case provided"}]
convo_java = [{"role": "system", "content": "You are a technical and a professional QA manager who specializes in Java JUnit, working in a technological firm. You should provide Java JUnit test scripts in for the test case provided"}]
def generate_test_cases(topic, num_cases):
if topic:
conversation_tc.append({"role": "user", "content": f"Generate {num_cases} manual test cases for the topic: {topic}"})
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=conversation_tc
)
test_cases = response["choices"][0]["message"]["content"]
return test_cases
else:
return "Please enter a topic/subject."
def generate_test_scripts(language, framework, test_cases):
if language == "Python" and framework == "unittest":
return generate_python_unittest(test_cases)
elif language == "Java" and framework == "JUnit":
return generate_java_junit(test_cases)
else:
return "Unsupported language or framework."
def generate_python_unittest(test_cases):
convo_py.append({"role": "user", "content": f"Here is a manual test case. {test_cases}"})
# prompt = f"Create a Python unittest test script for the following test cases:\n{test_cases}"
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=convo_py
)
script = response["choices"][0]["message"]["content"]
return script
def generate_java_junit(test_cases):
convo_java.append({"role": "user", "content": f"Here is a manual test case. {test_cases}"})
# prompt = f"Create a Java JUnit test script for the following test cases:\n{test_cases}"
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=convo_java
)
script = response["choices"][0]["message"]["content"]
return script
# Streamlit interface
st.title("Manual Test Case Generator")
# Columns layout
col1, col2 = st.columns(2)
test_cases = None
with col1:
topic = st.text_input("Enter a topic or subject:")
num_cases = st.number_input("Number of test cases:", min_value=1, max_value=10, value=1)
if st.button("Generate Test Case"):
test_cases = generate_test_cases(topic, num_cases)
st.write(test_cases)
with col2:
if test_cases:
language = st.selectbox("Select a language:", ["Python", "Java"])
framework = st.selectbox("Select a test framework:", ["unittest", "JUnit"])
if st.button("Generate Test Script"):
test_scripts = generate_test_scripts(language, framework, test_cases)
st.code(test_scripts, language)
|