Skip to content

Commit

Permalink
fix(driver): rely on puppeteer-core only.
Browse files Browse the repository at this point in the history
  • Loading branch information
asafkorem committed Jan 27, 2025
1 parent 286970b commit 0cbde0a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"typescript": "^5.3.3",
"puppeteer": "^20.8.0"
}
}
}
2 changes: 2 additions & 0 deletions examples/puppeteer/tests/example.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copilot from "@copilot";
import puppeteer from "puppeteer";
import { PromptHandler } from "../../utils/promptHandler";
import { PuppeteerFrameworkDriver } from "@copilot/drivers/puppeteer";

Expand All @@ -11,6 +12,7 @@ describe("Example Test Suite", () => {
const promptHandler: PromptHandler = new PromptHandler();

frameworkDriver = new PuppeteerFrameworkDriver();
frameworkDriver = new PuppeteerFrameworkDriver(puppeteer.executablePath());

copilot.init({
frameworkDriver,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"url": "https://github.com/wix-incubator/detox-copilot/issues"
},
"peerDependencies": {
"playwright": "^1.50.0",
"puppeteer": "^20.8.0"
"playwright": ">=1.50.0",
"puppeteer-core": ">=20.8.0"
},
"devDependencies": {
"@playwright/test": "^1.50.0",
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/puppeteer/getCleanDOM.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as puppeteer from "puppeteer";
import * as puppeteer from "puppeteer-core";

/**
* Get clean DOM from the page content
Expand Down
10 changes: 7 additions & 3 deletions src/drivers/puppeteer/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { TestingFrameworkAPICatalog, TestingFrameworkDriver } from "@/types";
import * as puppeteer from "puppeteer";
import * as puppeteer from "puppeteer-core";
import path from "path";
import fs from "fs";
import getCleanDOM from "./getCleanDOM";

export class PuppeteerFrameworkDriver implements TestingFrameworkDriver {
private currentPage?: puppeteer.Page;
private executablePath?: string;

constructor() {
constructor(executablePath?: string) {
this.getCurrentPage = this.getCurrentPage.bind(this);
this.setCurrentPage = this.setCurrentPage.bind(this);
this.executablePath = executablePath;
}

/**
Expand Down Expand Up @@ -84,8 +86,10 @@ export class PuppeteerFrameworkDriver implements TestingFrameworkDriver {
signature: "const browser = await puppeteer.launch([options])",
description: "Launches a new browser instance.",
example:
'const browser = await puppeteer.launch({`headless: "new"`});',
`const browser = await puppeteer.launch({\`headless: "new"\`, executablePath: "${this.executablePath}" });\n` +
`const browser = await puppeteer.launch({\`headless: "false"\`, executablePath: "${this.executablePath}" });`,
guidelines: [
`Executable path is required always, use the path: ${this.executablePath}`,
"Options can specify `headless`, `slowMo`, `args`, etc.",
"Useful for running tests in a headless browser environment.",
'Prefer passing `headless: "new"` to `puppeteer.launch() unless mentioned that ' +
Expand Down
6 changes: 6 additions & 0 deletions src/utils/CodeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export class CodeEvaluator {
try {
const result = await asyncFunction();

logger.info({
message: `\nCopilot evaluated the code: \n\`\`\`\n${code}\n\`\`\``,
isBold: false,
color: "gray",
});

return { code, result, sharedContext };
} catch (error) {
logger.error({
Expand Down

0 comments on commit 0cbde0a

Please sign in to comment.