Skip to content

Commit

Permalink
feat: support stringifying flows for Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Aug 2, 2024
1 parent a803066 commit 527a1fb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
12 changes: 12 additions & 0 deletions __snapshots__/PuppeteerStringifyExtension.test.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,15 @@ exports[
}
`;

exports['PuppeteerStringifyExtension Firefox should stringify 1'] = `
const puppeteer = require('puppeteer'); // v22.0.0 or later
(async () => {
const browser = await puppeteer.launch({browser: 'firefox', protocol: 'webDriverBiDi'});
const page = await browser.newPage();
const timeout = 5000;
page.setDefaultTimeout(timeout);
`;
16 changes: 15 additions & 1 deletion src/PuppeteerStringifyExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,30 @@ import {
} from './SchemaUtils.js';
import { formatJSONAsJS } from './JSONUtils.js';

type TargetBrowser = 'chrome' | 'firefox';

export class PuppeteerStringifyExtension extends StringifyExtension {
#shouldAppendWaitForElementHelper = false;
#targetBrowser: TargetBrowser;

constructor(targetBrowser: TargetBrowser = 'chrome') {
super();
this.#targetBrowser = targetBrowser;
}

override async beforeAllSteps(out: LineWriter, flow: UserFlow) {
out.appendLine(
"const puppeteer = require('puppeteer'); // v22.0.0 or later"
);
out.appendLine('');
out.appendLine('(async () => {').startBlock();
out.appendLine('const browser = await puppeteer.launch();');
if (this.#targetBrowser === 'firefox') {
out.appendLine(
`const browser = await puppeteer.launch({browser: 'firefox', protocol: 'webDriverBiDi'});`
);
} else {
out.appendLine('const browser = await puppeteer.launch();');
}
out.appendLine('const page = await browser.newPage();');
out.appendLine(`const timeout = ${flow.timeout || defaultTimeout};`);
out.appendLine('page.setDefaultTimeout(timeout);');
Expand Down
19 changes: 19 additions & 0 deletions test/PuppeteerStringifyExtension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,23 @@ describe('PuppeteerStringifyExtension', () => {
await ext.stringifyStep(writer, step, flow);
snapshot(writer.toString());
});

describe('Firefox', () => {
const ext = new PuppeteerStringifyExtension('firefox');

it('should stringify', async () => {
const step = {
type: StepType.Click as const,
target: 'main',
selectors: ['aria/Test'],
offsetX: 1,
offsetY: 1,
};
const flow = { title: 'test', steps: [step] };

const writer = new InMemoryLineWriter(' ');
await ext.beforeAllSteps(writer, flow);
snapshot(writer.toString());
});
});
});

0 comments on commit 527a1fb

Please sign in to comment.