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

117 lines
3.9 KiB
PHP

<?php
header("Content-Type: application/json");
$base = "/var/www/html/api/ambre-pw-tests";
@mkdir("$base", 0755, true);
@mkdir("$base/tests", 0755, true);
@mkdir("$base/output", 0755, true);
// === playwright.config.js ===
$config = '// @ts-check
const { defineConfig, devices } = require("@playwright/test");
module.exports = defineConfig({
testDir: "./tests",
timeout: 120000,
retries: 0,
workers: 1,
use: {
baseURL: "https://weval-consulting.com",
trace: "off",
screenshot: "on",
video: "on",
viewport: { width: 1280, height: 720 },
ignoreHTTPSErrors: true,
},
outputDir: "./output",
reporter: [["list"], ["json", { outputFile: "./output/results.json" }]],
projects: [
{ name: "chromium", use: { ...devices["Desktop Chrome"] } },
],
});';
file_put_contents("$base/playwright.config.js", $config);
// === package.json ===
$pkg = json_encode([
"name" => "ambre-chat-tests",
"version" => "1.0.0",
"scripts" => ["test" => "playwright test"],
"devDependencies" => ["@playwright/test" => "^1.58.0"],
], JSON_PRETTY_PRINT);
file_put_contents("$base/package.json", $pkg);
// === chat-capabilities.spec.js ===
$spec = <<<'JS'
const { test, expect } = require("@playwright/test");
const CAPABILITIES = [
{ name: "PDF", msg: "Genere un PDF sur: WEVIA demo" },
{ name: "Word", msg: "Genere un document Word sur: strategie" },
{ name: "PPT", msg: "Genere une presentation sur: pitch" },
{ name: "Mermaid", msg: "Genere un schema mermaid pour: flow" },
{ name: "Image", msg: "Genere une image: logo" },
{ name: "Code", msg: "Ecris le code python pour: fibonacci" },
{ name: "Traduire", msg: "Traduis en anglais: bonjour" },
{ name: "Ping", msg: "ping" },
];
test.describe("WEVIA Chat Capabilities Test", () => {
test("8 capabilities end-to-end with video", async ({ page }) => {
test.setTimeout(300000);
console.log("🎬 Ouverture wevia.html");
await page.goto("/wevia.html");
await page.waitForLoadState("networkidle");
await page.waitForTimeout(1500);
// Screenshot initial state
await page.screenshot({ path: "output/00-initial.png", fullPage: false });
console.log("📸 Screenshot initial OK");
const input = page.locator("#msgInput");
const sendBtn = page.locator("#sendBtn, button[onclick*=send], button.send-btn").first();
for (let i = 0; i < CAPABILITIES.length; i++) {
const cap = CAPABILITIES[i];
const num = String(i + 1).padStart(2, "0");
console.log(`\n🔷 [${i + 1}/8] ${cap.name}: ${cap.msg}`);
// Clear and type
await input.click();
await input.fill(cap.msg);
await page.waitForTimeout(400);
// Send (Enter key is fallback)
await input.press("Enter");
console.log(` Message envoyé`);
// Wait for response (thinking bubble disappears + message rendered)
try {
await page.waitForSelector(".msg.assistant:last-of-type .bubble", { timeout: 60000, state: "visible" });
} catch (e) {
console.log(` ⚠️ Pas de réponse détectée rapidement`);
}
await page.waitForTimeout(2500);
// Screenshot de la réponse
await page.screenshot({ path: `output/${num}-${cap.name}.png` });
console.log(` 📸 Screenshot ${num}-${cap.name}.png capturé`);
}
// Final screenshot
await page.waitForTimeout(1500);
await page.screenshot({ path: "output/99-final.png", fullPage: true });
console.log("\n✅ Test terminé - 8 capabilities enregistrées avec vidéo");
});
});
JS;
file_put_contents("$base/tests/chat-capabilities.spec.js", $spec);
echo json_encode([
"ok" => true,
"files" => [
"config" => filesize("$base/playwright.config.js"),
"spec" => filesize("$base/tests/chat-capabilities.spec.js"),
"package" => filesize("$base/package.json"),
],
"base" => $base,
], JSON_PRETTY_PRINT);