also iterate through stacks

This commit is contained in:
Abi Raja 2024-05-17 16:52:01 -04:00
parent 7396160833
commit 610400bc49

View File

@ -1,5 +1,6 @@
import puppeteer, { Browser, Page, ElementHandle } from "puppeteer"; import puppeteer, { Browser, Page, ElementHandle } from "puppeteer";
import { Stack } from "../lib/stacks"; import { Stack } from "../lib/stacks";
import { CodeGenerationModel } from "../lib/models";
const REPO_PATH = "/Users/abi/Documents/GitHub/screenshot-to-code/frontend"; const REPO_PATH = "/Users/abi/Documents/GitHub/screenshot-to-code/frontend";
const DOWNLOAD_PATH = `${REPO_PATH}/qa`; const DOWNLOAD_PATH = `${REPO_PATH}/qa`;
@ -32,42 +33,46 @@ describe("Simple Puppeteer Test", () => {
await browser.close(); await browser.close();
}); });
const stacks = Object.values(Stack); const stacks = Object.values(Stack).slice(0, 1);
const models = Object.values(CodeGenerationModel);
// For debugging // For debugging
//.slice(0, 1); //.slice(0, 1);
stacks.forEach((stack) => { models.forEach((model) => {
it(`should load the homepage and check the title for stack: ${stack}`, async () => { stacks.forEach((stack) => {
const codeGenerationModel = "claude_3_sonnet"; it(`should load the homepage and check the title for stack: ${stack}`, async () => {
const testId = `${codeGenerationModel}_${stack}`; const testId = `${model}_${stack}`;
await setupLocalStorage(page, stack, codeGenerationModel); await setupLocalStorage(page, stack, model);
// Upload file // Upload file
const fileInput = (await page.$( const fileInput = (await page.$(
".file-input" ".file-input"
)) as ElementHandle<HTMLInputElement>; )) as ElementHandle<HTMLInputElement>;
if (!fileInput) { if (!fileInput) {
throw new Error("File input element not found"); throw new Error("File input element not found");
} }
await fileInput.uploadFile(IMAGE_PATH); await fileInput.uploadFile(IMAGE_PATH);
// Screenshot the first step // Screenshot the first step
await page.screenshot({ await page.screenshot({
path: `${SCREENSHOTS_PATH}/${testId}_image_uploaded.png`, path: `${SCREENSHOTS_PATH}/${testId}_image_uploaded.png`,
}); });
// Click the generate button and wait for the code to be generated // Click the generate button and wait for the code to be generated
await page.waitForNetworkIdle(); await page.waitForNetworkIdle();
await page.waitForFunction(() => document.body.innerText.includes("v1"), { await page.waitForFunction(
timeout: 30000, () => document.body.innerText.includes("v1"),
}); {
timeout: 30000,
}
);
await page.screenshot({ await page.screenshot({
path: `${SCREENSHOTS_PATH}/${testId}_image_results.png`, path: `${SCREENSHOTS_PATH}/${testId}_image_results.png`,
});
}); });
}); });
}); });