Skip to content

Commit 8b882ad

Browse files
committed
puppeteer-to-cypress
1 parent 0578555 commit 8b882ad

4 files changed

Lines changed: 419 additions & 1 deletion

File tree

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
const puppeteer = require('puppeteer'); // v23.0.0 or later
2+
3+
(async () => {
4+
const browser = await puppeteer.launch();
5+
const page = await browser.newPage();
6+
const timeout = 5000;
7+
page.setDefaultTimeout(timeout);
8+
9+
{
10+
const targetPage = page;
11+
await targetPage.setViewport({
12+
width: 802,
13+
height: 633
14+
})
15+
}
16+
{
17+
const targetPage = page;
18+
await targetPage.goto('http://localhost:5173/');
19+
}
20+
{
21+
const targetPage = page;
22+
await puppeteer.Locator.race([
23+
targetPage.locator('::-p-aria(new) >>>> ::-p-aria([role=\\"button\\"])'),
24+
targetPage.locator('nav button'),
25+
targetPage.locator('::-p-xpath(//*[@id=\\"root\\"]/div/nav/a/button)'),
26+
targetPage.locator(':scope >>> nav button')
27+
])
28+
.setTimeout(timeout)
29+
.click({
30+
offset: {
31+
x: 29,
32+
y: 26,
33+
},
34+
});
35+
}
36+
{
37+
const targetPage = page;
38+
await puppeteer.Locator.race([
39+
targetPage.locator('::-p-aria(editor) >>>> ::-p-aria([role=\\"paragraph\\"])'),
40+
targetPage.locator('p'),
41+
targetPage.locator('::-p-xpath(//*[@id=\\"root\\"]/div/div/div[2]/div[1]/div/div/div/div[1]/div/p)'),
42+
targetPage.locator(':scope >>> p')
43+
])
44+
.setTimeout(timeout)
45+
.click({
46+
offset: {
47+
x: 113.875,
48+
y: 13,
49+
},
50+
});
51+
}
52+
{
53+
const targetPage = page;
54+
await puppeteer.Locator.race([
55+
targetPage.locator('div.flex-col > div.grid > div > div > div > div:nth-of-type(1) > div'),
56+
targetPage.locator('::-p-xpath(//*[@id=\\"root\\"]/div/div/div[2]/div[1]/div/div/div/div[1]/div)'),
57+
targetPage.locator(':scope >>> div.flex-col > div.grid > div > div > div > div:nth-of-type(1) > div')
58+
])
59+
.setTimeout(timeout)
60+
.fill('cypress content');
61+
}
62+
{
63+
const targetPage = page;
64+
await puppeteer.Locator.race([
65+
targetPage.locator('html'),
66+
targetPage.locator('::-p-xpath(/html)'),
67+
targetPage.locator(':scope >>> html')
68+
])
69+
.setTimeout(timeout)
70+
.click({
71+
offset: {
72+
x: 681,
73+
y: 325,
74+
},
75+
});
76+
}
77+
{
78+
const targetPage = page;
79+
await puppeteer.Locator.race([
80+
targetPage.locator('::-p-aria(# simple)'),
81+
targetPage.locator('div:nth-of-type(8)'),
82+
targetPage.locator('::-p-xpath(//*[@id=\\"radix-_r_f_\\"]/div[2]/div[8])'),
83+
targetPage.locator(':scope >>> div:nth-of-type(8)'),
84+
targetPage.locator('::-p-text(# simple)')
85+
])
86+
.setTimeout(timeout)
87+
.click({
88+
offset: {
89+
x: 84,
90+
y: 17,
91+
},
92+
});
93+
}
94+
{
95+
const targetPage = page;
96+
await puppeteer.Locator.race([
97+
targetPage.locator('div.flex-col'),
98+
targetPage.locator('::-p-xpath(//*[@id=\\"root\\"]/div/div/div[2])'),
99+
targetPage.locator(':scope >>> div.flex-col'),
100+
targetPage.locator('::-p-text(cypress contentPFont size→← TableTag#simple)')
101+
])
102+
.setTimeout(timeout)
103+
.click({
104+
offset: {
105+
x: 389.875,
106+
y: 314,
107+
},
108+
});
109+
}
110+
{
111+
const targetPage = page;
112+
await puppeteer.Locator.race([
113+
targetPage.locator('::-p-aria([role=\\"link\\"]) >>>> ::-p-aria([role=\\"button\\"])'),
114+
targetPage.locator('a > button'),
115+
targetPage.locator('::-p-xpath(//*[@id=\\"root\\"]/div/div/div[1]/a/button)'),
116+
targetPage.locator(':scope >>> a > button')
117+
])
118+
.setTimeout(timeout)
119+
.click({
120+
offset: {
121+
x: 14.875,
122+
y: 13,
123+
},
124+
});
125+
}
126+
127+
await browser.close();
128+
129+
})().catch(err => {
130+
console.error(err);
131+
process.exit(1);
132+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
describe("Recorded flow", () => {
2+
it("replays user actions", () => {
3+
// viewport recorded: 802x633
4+
cy.viewport(802, 633);
5+
cy.visit("http://localhost:5173/");
6+
cy.contains("new") [role="\button\"].click(29, 26);
7+
cy.contains("editor") [role="\paragraph\"].click(113.875, 13);
8+
cy.get("div.flex-col > div.grid > div > div > div > div:nth-of-type(1) > div")
9+
.clear()
10+
.type("cypress content");
11+
cy.get("html").click(681, 325);
12+
cy.contains("# simple").click(84, 17);
13+
cy.contains("cypress contentPFont size→← TableTag#simple").click(389.875, 314);
14+
cy.get("[role=\"\link\\"] [role=\"\button\\"]").click(14.875, 13);
15+
});
16+
});

‎testing/cypress-testing/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"scripts": {
1313
"initial:install": "pnpm exec cypress install",
1414
"start": "pnpm cypress open",
15-
"open": "pnpm cypress open"
15+
"open": "pnpm cypress open",
16+
"convert:puppeteer": "node puppeteer-to-cypress.js input.puppeteer.js > output.puppeteer.js"
1617
},
1718
"devDependencies": {
1819
"cypress": "^15.10.0"

0 commit comments

Comments
 (0)