Spaces:
Runtime error
Runtime error
added test_case and test_script
Browse files
app.py
CHANGED
|
@@ -8,28 +8,70 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
| 8 |
if not openai.api_key:
|
| 9 |
st.error("No OpenAI API key found in the environment variable OPENAI_API_KEY")
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
def generate_test_cases(topic, num_cases):
|
| 14 |
if topic:
|
| 15 |
-
|
| 16 |
response = openai.ChatCompletion.create(
|
| 17 |
model="gpt-3.5-turbo",
|
| 18 |
-
messages=
|
| 19 |
)
|
| 20 |
|
| 21 |
test_cases = response["choices"][0]["message"]["content"]
|
| 22 |
-
# return [f"Test Case {i+1}:\n{case.text.strip()}" for i, case in enumerate(test_cases)]
|
| 23 |
return test_cases
|
| 24 |
else:
|
| 25 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Streamlit interface
|
| 28 |
st.title("Manual Test Case Generator")
|
| 29 |
-
topic = st.text_input("Enter a topic or subject:")
|
| 30 |
-
num_cases = st.number_input("Number of test cases:", min_value=1, max_value=10, value=1)
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
if not openai.api_key:
|
| 9 |
st.error("No OpenAI API key found in the environment variable OPENAI_API_KEY")
|
| 10 |
|
| 11 |
+
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. "}]
|
| 12 |
+
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"}]
|
| 13 |
+
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"}]
|
| 14 |
+
|
| 15 |
|
| 16 |
def generate_test_cases(topic, num_cases):
|
| 17 |
if topic:
|
| 18 |
+
conversation_tc.append({"role": "user", "content": f"Generate {num_cases} manual test cases for the topic: {topic}"})
|
| 19 |
response = openai.ChatCompletion.create(
|
| 20 |
model="gpt-3.5-turbo",
|
| 21 |
+
messages=conversation_tc
|
| 22 |
)
|
| 23 |
|
| 24 |
test_cases = response["choices"][0]["message"]["content"]
|
|
|
|
| 25 |
return test_cases
|
| 26 |
else:
|
| 27 |
+
return "Please enter a topic/subject."
|
| 28 |
+
|
| 29 |
+
def generate_test_scripts(language, framework, test_cases):
|
| 30 |
+
if language == "Python" and framework == "unittest":
|
| 31 |
+
return generate_python_unittest(test_cases)
|
| 32 |
+
elif language == "Java" and framework == "JUnit":
|
| 33 |
+
return generate_java_junit(test_cases)
|
| 34 |
+
else:
|
| 35 |
+
return "Unsupported language or framework."
|
| 36 |
+
|
| 37 |
+
def generate_python_unittest(test_cases):
|
| 38 |
+
convo_py.append({"role": "user", "content": f"Here is a manual test case. {test_cases}"})
|
| 39 |
+
# prompt = f"Create a Python unittest test script for the following test cases:\n{test_cases}"
|
| 40 |
+
response = openai.ChatCompletion.create(
|
| 41 |
+
model="gpt-3.5-turbo",
|
| 42 |
+
messages=convo_py
|
| 43 |
+
)
|
| 44 |
+
script = response["choices"][0]["message"]["content"]
|
| 45 |
+
return script
|
| 46 |
+
|
| 47 |
+
def generate_java_junit(test_cases):
|
| 48 |
+
convo_java.append({"role": "user", "content": f"Here is a manual test case. {test_cases}"})
|
| 49 |
+
# prompt = f"Create a Java JUnit test script for the following test cases:\n{test_cases}"
|
| 50 |
+
response = openai.ChatCompletion.create(
|
| 51 |
+
model="gpt-3.5-turbo",
|
| 52 |
+
messages=convo_java
|
| 53 |
+
)
|
| 54 |
+
script = response["choices"][0]["message"]["content"]
|
| 55 |
+
return script
|
| 56 |
|
| 57 |
# Streamlit interface
|
| 58 |
st.title("Manual Test Case Generator")
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
# Columns layout
|
| 61 |
+
col1, col2 = st.beta_columns(2)
|
| 62 |
+
|
| 63 |
+
with col1:
|
| 64 |
+
topic = st.text_input("Enter a topic or subject:")
|
| 65 |
+
num_cases = st.number_input("Number of test cases:", min_value=1, max_value=10, value=1)
|
| 66 |
+
|
| 67 |
+
if st.button("Generate Test Cases"):
|
| 68 |
+
test_cases = generate_test_cases(topic, num_cases)
|
| 69 |
+
st.write(test_cases)
|
| 70 |
+
|
| 71 |
+
with col2:
|
| 72 |
+
language = st.selectbox("Select a language:", ["Python", "Java"])
|
| 73 |
+
framework = st.selectbox("Select a test framework:", ["unittest", "JUnit"])
|
| 74 |
+
|
| 75 |
+
if st.button("Generate Test Scripts"):
|
| 76 |
+
test_scripts = generate_test_scripts(language, framework, test_cases)
|
| 77 |
+
st.code(test_scripts, language)
|