Skip to content

Commit 3488484

Browse files
authored
Merge pull request #2 from K11-Software-Solutions/copilot/merge-mcp-branch-to-main
Merge MCP branch into main
2 parents 6e89f74 + a4c2208 commit 3488484

35 files changed

+1822
-175
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@ build/
4646
.vscode/
4747

4848
### Mac OS ###
49-
.DS_Store
49+
.DS_Store
50+
51+
# MCP AI Test logs and reports
52+
mcp_testlog/
53+
mcp_testreport/

config/mcp-config.properties

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1-
# Output directory for generated tests
2-
output.dir=src/test/ai_generated_tests/k11softwaresolutions
1+
# Directory for AI prompt templates
2+
prompt.dir=mcp-prompts/k11softwaresolutions
33
# Web URL for AI-generated tests
44
weburl=https://k11softwaresolutions-platform.vercel.app/
55
username=testuser
66
password=testpass
77

8+
# === MCPTestWorkflow properties (no prefix) ===
9+
scenario=Login to the dashboard and verify the dashboard is visible
10+
classNameBase=GeneratedPlaywrightLogin
11+
ai.packageName=org.k11techlab.framework_unittests.ai_generated.k11softwaresolutions
12+
# Java package for ConfigurationManager class
13+
configmanager.package=org.k11techlab.framework.selenium.webuitestengine.configManager
14+
# Directory for MCP test logs
15+
log.dir=mcp_testlog
16+
17+
maven.test.dir=src/test/java/org/k11techlab/framework_unittests/ai_generated/k11softwaresolutions
18+
19+
review.prompt=Review the following Java TestNG test class for correctness, best practices, and possible improvements. Provide a concise summary and suggestions.\n\n
20+
report.src=test-output/emailable-report.html
21+
# Path to Maven executable for test automation
22+
maven.cmd.path=C:/Program Files/maven-1.0.2/mvn/bin/mvn.cmd
23+
# Output directory for generated tests
24+
output.dir=src/test/java/org/k11techlab/framework_unittests/ai_generated/k11softwaresolutions
25+
26+
827
# Default engine for MCP test generation (selenium or playwright)
928
engine=selenium
1029
# Default package name for generated tests
@@ -18,3 +37,15 @@ mongo.db=mcpdb
1837
mongo.collection=context
1938

2039

40+
41+
# === k11softwaresolutions app-specific properties ===
42+
k11softwaresolutions.weburl=https://k11softwaresolutions-platform.vercel.app/
43+
# Page object prompt config
44+
k11softwaresolutions.prompt.pagedir=mcp-prompts/k11softwaresolutions/pages
45+
k11softwaresolutions.prompt.pages=pageobject_creation_prompt_multi.txt
46+
# Test generation prompt config
47+
k11softwaresolutions.prompt.testdir=mcp-prompts/k11softwaresolutions/tests
48+
k11softwaresolutions.prompt.logintest=logintest_creation_prompt.txt
49+
50+
# Framework standards prompt for test generation
51+
k11softwaresolutions.prompt.framework=mcp-prompts/framework_standards_prompt.txt
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Playwright Framework Standards Prompt
2+
3+
- All Playwright test classes must extend `BasePlaywrightTest`.
4+
- Use `PlaywrightManager.getInstance()` to obtain the browser, context, and page.
5+
- Do not use `Playwright.create()` or direct browser/page instantiation in test classes.
6+
- Use `@BeforeClass` and `@AfterClass` for setup and teardown, delegating to `BasePlaywrightTest` where possible.
7+
- Example test method:
8+
9+
@Test
10+
public void testExample() {
11+
Page page = PlaywrightManager.getInstance().getPage();
12+
// test steps...
13+
}
14+
15+
- Use the Page Object Model for all page interactions.
16+
- Follow Java and TestNG best practices for naming and structure.
17+
- All test code should be readable, maintainable, and DRY.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Generate a complete, compilable Java TestNG test class using Playwright for Java.
2+
Package: {packageName}
3+
Class: {className}
4+
MUST include:
5+
- All required imports (Playwright, TestNG, ConfigurationManager, etc).
6+
- A @BeforeClass setUp() method that launches Playwright, a Chromium browser in headless mode, and creates a Page. Store Playwright, Browser, and Page as fields.
7+
- A @Test method that:
8+
- Reads weburl, username, and password using ConfigurationManager.getBundle().getPropertyValue('weburl'), etc.
9+
- Navigates to the weburl.
10+
- Fills the username and password fields and clicks the login button (use generic selectors if not specified).
11+
- Asserts that the dashboard is visible after login (e.g., page.isVisible('text=Dashboard')).
12+
- A @AfterClass tearDown() method that closes the browser and Playwright.
13+
- Output ONLY Java code, no markdown.
14+
- The code must be complete and not truncated.
15+
16+
Scenario:
17+
{scenario}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Page Object Creation Prompt Example
2+
3+
You are an AI assistant that generates Playwright Page Object Model (POM) Java classes. Use the following JSON structure as input:
4+
5+
{
6+
"className": "HomePage",
7+
"fields": {
8+
"isDashboardVisible": {"id": "Dashboard", "method": "isVisible"},
9+
"clickServiceLink": {"id": "service", "text": "Service", "method": "click"},
10+
"clickLoginMenu": {"id": "loginMenu", "text": "Login", "method": "click"},
11+
"clickRegisterMenu": {"id": "registerMenu", "text": "Register", "method": "click"}
12+
}
13+
}
14+
15+
- Use id as the first preference, then name, then text for selectors.
16+
- Each field should generate a method in the Java class.
17+
- Use Playwright's Page API for actions (fill, click, isVisible, etc).
18+
- Output only valid Java code for the page object class.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Page Object Creation Prompt for HomePage and LoginPage
2+
3+
{
4+
"pageObjects": [
5+
{
6+
"className": "HomePage",
7+
"fields": {
8+
"isDashboardVisible": {"id": "Dashboard", "method": "isVisible"},
9+
"clickServiceLink": {"id": "service", "text": "Service", "method": "click"},
10+
"clickLoginMenu": {"id": "loginMenu", "text": "Login", "method": "click"},
11+
"clickRegisterMenu": {"id": "registerMenu", "text": "Register", "method": "click"}
12+
}
13+
},
14+
{
15+
"className": "LoginPage",
16+
"fields": {
17+
"enterUsername": {"id": "username", "name": "username", "text": "Username", "method": "fill"},
18+
"enterPassword": {"id": "password", "name": "password", "text": "Password", "method": "fill"},
19+
"clickLogin": {"id": "login", "name": "login", "text": "Login", "method": "click"}
20+
}
21+
}
22+
]
23+
}
24+
25+
- Use id as the first preference, then name, then text for selectors.
26+
- Each field should generate a method in the Java class.
27+
- Use Playwright's Page API for actions (fill, click, isVisible, etc).
28+
- Output only valid Java code for the page object classes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Login Test Generation Prompt
2+
3+
{
4+
"testScenario": "Login to the dashboard and verify the dashboard is visible",
5+
"testClassName": "GeneratedPlaywrightLoginTest",
6+
"pageObjects": ["HomePage", "LoginPage"],
7+
"steps": [
8+
"Navigate to the login page",
9+
"Enter username and password",
10+
"Click the login button",
11+
"Verify the dashboard is visible"
12+
]
13+
}
14+
15+
- Use the provided page objects and methods.
16+
- Use TestNG for the test class structure.
17+
- Use Playwright's Page API for browser actions.
18+
- Output only valid Java code for the test class.

pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
<version>2.20</version>
2929
<configuration>
3030
<testFailureIgnore>true</testFailureIgnore>
31+
<includes>
32+
<include>org/k11techlab/framework_unittests/webUITests/wikipedia/**</include>
33+
</includes>
3134
</configuration>
3235
</plugin>
3336
<plugin>
@@ -64,7 +67,6 @@
6467
<groupId>com.microsoft.playwright</groupId>
6568
<artifactId>playwright</artifactId>
6669
<version>1.44.0</version>
67-
<scope>test</scope>
6870
</dependency>
6971
<dependency>
7072
<groupId>com.github.javaparser</groupId>

src/main/java/org/k11techlab/framework/ai/mcp/MCPServer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public void start(int port) throws IOException {
2929
server.createContext("/mcp/correct-code", new CorrectCodeHandler(new OpenAIClient()));
3030
server.createContext("/mcp/generate-and-run-selenium-test", new GenerateAndRunTestHandler());
3131
server.createContext("/mcp/generate-and-run-playwright-test", new GenerateAndRunTestHandler());
32+
server.createContext("/mcp/generate-page-object", new GeneratePageObjectHandler());
3233

3334
server.setExecutor(null);
3435
server.start();

src/main/java/org/k11techlab/framework/ai/mcp/handlers/GenerateAndRunTestHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public GenerateAndRunTestHandler() {
3333

3434
// Playwright wiring
3535
this.playwrightGenerator = new PlaywrightTestGenerator(openAI);
36-
this.playwrightWorkflow = new PlaywrightWorkflow(playwrightGenerator, openAI, 2);
36+
this.playwrightWorkflow = new PlaywrightWorkflow();
3737
}
3838

3939

@@ -55,7 +55,7 @@ public void handle(HttpExchange exchange) throws IOException {
5555

5656
String packageName = (configPackage != null && !configPackage.isBlank())
5757
? configPackage.trim()
58-
: "org.k11techlab.framework_unittests.ai_generated";
58+
: "org.k11techlab.framework_unittests.ai_generated.k11softwaresolutions";
5959

6060
String classBase = "GeneratedTest_" + System.currentTimeMillis();
6161

0 commit comments

Comments
 (0)