Skip to content

Commit 2bf0a48

Browse files
authored
Merge pull request #174 from Cloud-Code-AI/173-refc-reformat-the-prompts-for-ui-test-case-generator
feat: Updated prompt for ui test generation
2 parents 65d73df + 9c7dba3 commit 2bf0a48

File tree

3 files changed

+53
-19
lines changed

3 files changed

+53
-19
lines changed

examples/basic/generate.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
from kaizen.generator.ui import UITestGenerator
2+
import time
3+
import sys
24

35
generator = UITestGenerator()
46

57
WEBPAGE_URL = "https://cloudcode.ai"
68

7-
tests, _ = generator.generate_ui_tests(WEBPAGE_URL)
9+
print(f"Generating UI tests for `{WEBPAGE_URL}`, please wait...")
10+
start_time = time.time()
11+
12+
try:
13+
tests, _ = generator.generate_ui_tests(WEBPAGE_URL)
14+
except Exception as e:
15+
print(f"Error: {e}")
16+
sys.exit(1)
17+
18+
end_time = time.time()
19+
elapsed_time = end_time - start_time
20+
print(f"\nUI tests generated in {elapsed_time:.2f} seconds.")
821

9-
# print("Generated Tests: ", json.dumps(tests))
1022

1123
for test in tests:
12-
print(f'#### ======== Module Title: {test["module_title"]} ========== ####')
24+
print(f'#### ======== Module Title: {test["module_title"]} || Importance: {test["importance"]} ========== ####')
1325
for t in test["tests"]:
1426
print(f'Desc: {t["test_description"]}')
1527
print(f'Code: \n{t["code"]}')

kaizen/helpers/output.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ def create_test_files(json_tests, folder_path):
100100
logger.info(f"Failed to clean code")
101101
else:
102102
cleaned_code = (
103-
f"''' Module Name: {module['module_title']}\n '''\n\n"
103+
f"'''Importance: {module['importance']}\
104+
\nModule Name: {module['module_title']}\
105+
\nDescription: {test['test_description']}\n'''\n\n"
104106
+ cleaned_code
105107
)
106108
f.write(cleaned_code)

kaizen/llms/prompts.py

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -143,34 +143,54 @@
143143
{CODE_DIFF}
144144
145145
"""
146-
# TODO: Rephrase prompt to make it more clear and accurate.
146+
147147
UI_MODULES_PROMPT = """
148-
Assign yourself as a quality assurance engineer. Read this code and design comprehensive tests to test the UI
149-
of this html. Break it down into 5-10 separate modules and return the output as JSON with the following keys:
150-
id - serial number to identify
148+
Assign yourself as a quality assurance engineer.
149+
Read this code and design comprehensive tests to test the UI of this HTML.
150+
Break it down into 5-10 separate modules and identify the possible things to test for each module.
151+
For each module, also identify which tests should be checked repeatedly (e.g., after every code change, every build, etc.).
152+
153+
Return the output as JSON with the following keys:
154+
id - serial number to identify module
151155
module_title - title of the identified module
152-
tests - JSON containing list of tests steps to carry out for that module with keys - id, test_description, test_name.
156+
tests - JSON containing list of tests steps to carry out for that module with keys:
157+
id - serial number for the test case
158+
test_description - description of the test case
159+
test_name - name of the test case
160+
repeat - boolean indicating if this test should be checked repeatedly or not
153161
folder_name - relevant name for the module
154162
importance - level of importance of this test out of ['critical', 'good_to_have', 'non_essential']
155-
Share the JSON output ONLY. No other text.
156163
157-
CONTENT:
158-
```{WEB_CONTENT}```
164+
Share the JSON output ONLY. No other text.
165+
CONTENT: ```{WEB_CONTENT}```
159166
"""
160167

161-
# TODO: Rephrase prompt to make it more clear and accurate.
162168
UI_TESTS_SYSTEM_PROMPT = """
163-
As a test case engineer, your task is to write comprehensive test cases for a given user interface.
164-
You should review the user interface and identify all possible use cases and edge cases that need to be tested.
165-
Your test cases should cover all aspects of the user interface, including functionality, usability, and accessibility.
169+
Here's a shortened version of the system prompt:
170+
171+
You are a Quality Assurance AI assistant specializing in writing Playwright test scripts for web applications. Your goal is to create robust and maintainable test scripts that can be integrated into a CI/CD pipeline.
172+
173+
When given requirements or specifications, you should:
174+
175+
1. Analyze the requirements and design a comprehensive test plan.
176+
2. Write Playwright test scripts in Python 3.9 following best practices.
177+
3. Implement techniques like Page Object Model for reusability.
178+
4. Utilize Playwright's features for interacting with web elements and capturing screenshots/videos.
179+
5. Incorporate data-driven testing and parallelization strategies.
180+
6. Ensure compatibility with the CI/CD pipeline and provide clear documentation.
181+
7. Continuously maintain and improve the test scripts as the application evolves.
182+
183+
Prioritize code quality, maintainability, and adherence to best practices in test automation. Collaborate with developers and stakeholders for seamless integration into the software development lifecycle.
184+
185+
Remember, you cannot open URLs or links directly. Ask the human to provide relevant text or image content if needed.
166186
"""
167187

168-
# TODO: Rephrase prompt to make it more clear and accurate.
169188
PLAYWRIGHT_CODE_PROMPT = """
170-
Assign yourself as a quality assurance engineer. Read this code and write playwright code for test -
171-
{TEST_DESCRIPTION}. Return ONLY the playwright code based on python and strictly no other text.
189+
Read this code and write Playwright code in Python for the following test - {TEST_DESCRIPTION}.
190+
Return ONLY the Playwright code in Python and strictly no other text.
172191
173192
URL: {URL}
193+
Content:
174194
```{WEB_CONTENT}```
175195
"""
176196

0 commit comments

Comments
 (0)