-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.ts
More file actions
46 lines (41 loc) · 1.12 KB
/
Copy pathform.ts
File metadata and controls
46 lines (41 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { BrowserContext } from "playwright";
import { Field } from "./elements";
interface FormOpts {
context: BrowserContext;
url: string;
fields: Field[];
}
export class Form {
private context: BrowserContext;
private url: string;
private fields: Field[];
public filled = 0;
constructor(opts: FormOpts) {
this.fields = opts.fields;
this.url = opts.url;
this.context = opts.context;
}
private async initPage() {
const page = await this.context.newPage();
await page.goto(this.url);
return page;
}
public async fillAndSubmit(opts?: { screenshot?: boolean; log?: boolean }) {
this.filled++;
const page = await this.initPage();
const fills = await Promise.all(
this.fields.map((field) => field.fill(page))
);
if (opts?.log) {
console.log("filled", fills);
}
if (opts?.screenshot) {
await page.screenshot({ path: `./pre-submit-${this.filled}.png` });
}
await page.click(".freebirdThemedFilledButtonM2");
if (opts?.screenshot) {
await page.screenshot({ path: `./post-submit-${this.filled}.png` });
}
await page.close();
}
}