Files
html/api/ambre-pw-v3.php
2026-04-21 16:50:02 +02:00

122 lines
4.4 KiB
PHP

<?php
header("Content-Type: application/json");
$base = "/var/www/html/api/ambre-pw-tests";
// V3 improved spec — actually waits for file URL + scrolls + viewport 1920x1080
$spec = <<<'JS'
const { test, expect } = require("@playwright/test");
const CAPABILITIES = [
{ name: "PDF", msg: "Genere un PDF sur: WEVIA enterprise demo", needle: ".pdf" },
{ name: "Word", msg: "Genere un document Word sur: strategie pharma", needle: ".docx" },
{ name: "PPT", msg: "Genere une presentation sur: pitch investor", needle: ".pptx" },
{ name: "Mermaid", msg: "Genere un schema mermaid pour: workflow commande", needle: "graph TD" },
{ name: "Image", msg: "Genere une image: paysage montagne", needle: ".svg" },
{ name: "Code", msg: "Ecris le code python pour: fibonacci recursif", needle: ".py" },
{ name: "Traduire", msg: "Traduis en anglais: bonjour comment allez-vous", needle: "English:" },
{ name: "Ping", msg: "ping", needle: "WEVIA Engine" },
];
test("8 capabilities video + file URLs verified", async ({ page }) => {
test.setTimeout(420000); // 7min safety
// Navigate
await page.goto("/wevia.html");
await page.waitForLoadState("networkidle");
await page.waitForTimeout(2000);
await page.screenshot({ path: "output/v3-00-initial.png", fullPage: false });
console.log("📸 Initial state captured (1920x1080)");
const input = page.locator("#msgInput");
for (let i = 0; i < CAPABILITIES.length; i++) {
const cap = CAPABILITIES[i];
const num = String(i + 1).padStart(2, "0");
console.log(`\n[${num}/8] ${cap.name}: ${cap.msg}`);
try {
// Clear + type
await input.click({ timeout: 5000 });
await input.fill("");
await page.waitForTimeout(300);
await input.fill(cap.msg);
await page.waitForTimeout(500);
await input.press("Enter");
console.log(` sent, waiting for needle "${cap.needle}"...`);
// Wait for response with the needle OR 40s timeout
const waitStart = Date.now();
let found = false;
while (Date.now() - waitStart < 40000) {
const bodyText = await page.evaluate(() => document.body.innerText);
if (bodyText.includes(cap.needle)) {
found = true;
break;
}
await page.waitForTimeout(1000);
}
const elapsed = ((Date.now() - waitStart) / 1000).toFixed(1);
if (found) {
console.log(` ✅ Response has "${cap.needle}" in ${elapsed}s`);
} else {
console.log(` ⚠️ Needle not found after ${elapsed}s`);
}
// Scroll to bottom to see latest message
await page.evaluate(() => {
const msgs = document.getElementById("messages");
if (msgs) msgs.scrollTop = msgs.scrollHeight;
window.scrollTo(0, document.body.scrollHeight);
});
await page.waitForTimeout(1500);
// Screenshot full page to see entire response with download link
await page.screenshot({ path: `output/v3-${num}-${cap.name}.png`, fullPage: true });
console.log(` 📸 Screenshot v3-${num}-${cap.name}.png`);
} catch (e) {
console.log(` ❌ Error: ${e.message.substring(0, 100)}`);
}
}
// Final fullpage screenshot
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
await page.waitForTimeout(2000);
await page.screenshot({ path: "output/v3-99-final.png", fullPage: true });
console.log("\n✅ Test V3 8/8 terminé");
});
JS;
file_put_contents("$base/tests/chat-capabilities-v3.spec.js", $spec);
// Remove old v2 spec
@unlink("$base/tests/chat-capabilities-v2.spec.js");
// Update config viewport to 1920x1080
$cfg = '// @ts-check
const { defineConfig, devices } = require("@playwright/test");
module.exports = defineConfig({
testDir: "./tests",
timeout: 420000,
retries: 0,
workers: 1,
use: {
baseURL: "https://weval-consulting.com",
trace: "off",
screenshot: "on",
video: "on",
viewport: { width: 1920, height: 1080 },
ignoreHTTPSErrors: true,
},
outputDir: "./output",
reporter: [["list"], ["json", { outputFile: "./output/results.json" }]],
projects: [{ name: "chromium", use: { ...devices["Desktop Chrome"], viewport: { width: 1920, height: 1080 } } }],
});';
file_put_contents("$base/playwright.config.js", $cfg);
echo json_encode([
"ok" => true,
"spec_size" => filesize("$base/tests/chat-capabilities-v3.spec.js"),
"config_size" => filesize("$base/playwright.config.js"),
]);