@playwright/test#test TypeScript Examples

The following examples show how to use @playwright/test#test. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From excalideck with MIT License 6 votes vote down vote up
async selectSlide(index: number) {
        await test.step(`Select slide at index ${index}`, async () => {
            await this.page.click(
                `.SortableSlideMiniature:nth-child(${index + 1})`
            );
            await this.page.waitForSelector(
                `.SortableSlideMiniature:nth-child(${
                    index + 1
                }) .SelectedSlideMiniature`
            );
        });
    }
Example #2
Source File: drawing-multiple-slides.test.ts    From excalideck with MIT License 6 votes vote down vote up
test("Draw simple shapes in multiple slides", async ({ page }) => {
    const excalideckEditorPage = new ExcalideckEditorPage(page);
    await excalideckEditorPage.go();
    await excalideckEditorPage.drawRectangle();
    await excalideckEditorPage.addSlide();
    await excalideckEditorPage.drawEllipse();
    await excalideckEditorPage.expectToSee(
        "two slide miniatures",
        "the second slide miniature as selected",
        "an ellipse in the drawing area",
        'the corresponding ellipse "reflected" in the selected slide miniature',
        "a rectangle in the non-selected slide miniature"
    );
});
Example #3
Source File: drawing-common-elements.test.ts    From excalideck with MIT License 6 votes vote down vote up
test("Draw common elements", async ({ page }) => {
    const excalideckEditorPage = new ExcalideckEditorPage(page);
    await excalideckEditorPage.go();
    await excalideckEditorPage.addSlide();
    await excalideckEditorPage.goToSettings();
    await excalideckEditorPage.drawRectangle();
    await excalideckEditorPage.goToSlides();
    await excalideckEditorPage.expectToSee(
        "a rectangle (common element) in the middle of the drawing area",
        "two slide miniatures",
        'the rectangle "reflected" in each slide miniature'
    );
});
Example #4
Source File: deleting-slide.test.ts    From excalideck with MIT License 6 votes vote down vote up
test("Delete a slide", async ({ page }) => {
    const excalideckEditorPage = new ExcalideckEditorPage(page);
    await excalideckEditorPage.go();
    await excalideckEditorPage.drawRectangle();
    await excalideckEditorPage.addSlide();
    await excalideckEditorPage.drawEllipse();
    await excalideckEditorPage.addSlide();
    await excalideckEditorPage.drawDiamond();
    await excalideckEditorPage.selectSlide(1);
    await excalideckEditorPage.deleteSlide();
    await excalideckEditorPage.expectToSee(
        "two slide miniatures",
        "the first slide miniature has a rectangle",
        "the second slide miniature has a diamond",
        "a rectangle in the drawing area"
    );
});
Example #5
Source File: drawing-single-slide.test.ts    From excalideck with MIT License 6 votes vote down vote up
test("Draw a simple shape in a single slide", async ({ page }) => {
    const excalideckEditorPage = new ExcalideckEditorPage(page);
    await excalideckEditorPage.go();
    await excalideckEditorPage.drawRectangle();
    await excalideckEditorPage.expectToSee(
        "a rectangle in the drawing area",
        'the corresponding rectangle "reflected" in the slide miniature'
    );
});
Example #6
Source File: index.ts    From excalideck with MIT License 6 votes vote down vote up
/*
     * Private API
     */

    private async drawShape(shape: "rectangle" | "ellipse" | "diamond") {
        await test.step(
            `Draw ${shape} in the middle of the drawing area`,
            async () => {
                await this.runAndWaitForSlideMiniaturesChange(async () => {
                    // Select the shape
                    await this.page.click(`[title*="${shape}" i]`);
                    // Configure it not to draw sloppy shapes, as they are
                    // random and produce visual diffs from one run to the other
                    await this.page.click('[title*="architect" i]');
                    // Fill it to make it more visible
                    await this.page.fill(
                        'input[aria-label="background" i]',
                        "000000"
                    );
                    await this.page.click('[title*="solid" i]');
                    // Draw the shape
                    const initialX = this.viewportSize.width / 2 - 100;
                    const initialY = this.viewportSize.height / 2 - 50;
                    await this.page.mouse.move(initialX, initialY);
                    await this.page.mouse.down();
                    await this.page.mouse.move(initialX + 200, initialY + 100);
                    await this.page.mouse.up();
                });
            }
        );
    }
Example #7
Source File: index.ts    From excalideck with MIT License 6 votes vote down vote up
async expectToSee(...expectations: string[]) {
        const stepTitle = [
            "Expect to see:",
            castArray(expectations)
                .map((expectation) => `${expectation}`)
                .join(", "),
        ].join(" ");
        await test.step(stepTitle, async () => {
            expect(await this.page.screenshot()).toMatchSnapshot(
                this.issueNextSnapshotName()
            );
        });
    }
Example #8
Source File: index.ts    From excalideck with MIT License 6 votes vote down vote up
async changePrintableArea(width: number, height: number) {
        await test.step(
            `Change printable area to have width ${width} and height ${height}`,
            async () => {
                await this.page.fill(
                    'input[aria-label*="width" i]',
                    String(width)
                );
                await this.page.fill(
                    'input[aria-label*="height" i]',
                    String(height)
                );
            }
        );
    }
Example #9
Source File: index.ts    From excalideck with MIT License 6 votes vote down vote up
async excludeCommonElementsForSlide() {
        await test.step("Exclude common elements for slide", async () => {
            await this.runAndWaitForSlideMiniaturesChange(async () => {
                await this.page.click(
                    'button[title*="include common elements" i][aria-checked=true]'
                );
                await this.page.waitForSelector(
                    'button[title*="include common elements" i][aria-checked=false]'
                );
            });
        });
    }
Example #10
Source File: excluding-common-elements-from-slide.test.ts    From excalideck with MIT License 6 votes vote down vote up
test("Exclude common elements from a slide", async ({ page }) => {
    const excalideckEditorPage = new ExcalideckEditorPage(page);
    await excalideckEditorPage.go();
    await excalideckEditorPage.addSlide();
    await excalideckEditorPage.goToSettings();
    await excalideckEditorPage.drawRectangle();
    await excalideckEditorPage.goToSlides();
    await excalideckEditorPage.selectSlide(1);
    await excalideckEditorPage.excludeCommonElementsForSlide();
    await excalideckEditorPage.expectToSee(
        "two slide miniatures",
        "a rectangle (common element) in the first miniature",
        "no rectangle (common element) in the second slide",
        "no rectangle (common element) in the drawing area"
    );
});
Example #11
Source File: index.ts    From excalideck with MIT License 6 votes vote down vote up
async moveSlide(fromIndex: number, toIndex: number) {
        await test.step(
            `Move slide at index ${fromIndex} to index ${toIndex}`,
            async () => {
                await this.runAndWaitForSlideMiniaturesChange(async () => {
                    await this.page.dragAndDrop(
                        `.SortableSlideMiniature:nth-child(${fromIndex + 1})`,
                        `.SortableSlideMiniature:nth-child(${toIndex + 1})`,
                        { targetPosition: { x: 10, y: 10 } }
                    );
                });
            }
        );
    }
Example #12
Source File: index.ts    From excalideck with MIT License 6 votes vote down vote up
async deleteSlide() {
        await test.step("Delete slide", async () => {
            await this.runAndWaitForSlideMiniaturesChange(async () => {
                this.page.once("dialog", async (dialog) => {
                    await dialog.accept();
                });
                await this.page.click('button[title*="delete slide" i]');
            });
        });
    }
Example #13
Source File: rearranging-slides.test.ts    From excalideck with MIT License 6 votes vote down vote up
test("Drag and drop slides to rearrange them", async ({ page }) => {
    const excalideckEditorPage = new ExcalideckEditorPage(page);
    await excalideckEditorPage.go();
    await excalideckEditorPage.drawRectangle();
    await excalideckEditorPage.addSlide();
    await excalideckEditorPage.drawEllipse();
    await excalideckEditorPage.addSlide();
    await excalideckEditorPage.drawDiamond();
    await excalideckEditorPage.moveSlide(2, 0);
    await excalideckEditorPage.expectToSee(
        "three slide miniatures",
        "the first slide miniature has a diamond",
        "the second slide miniature has a rectangle",
        "the third slide miniature has an ellipse",
        "a diamond in the drawing area"
    );
});
Example #14
Source File: index.ts    From excalideck with MIT License 6 votes vote down vote up
async goToSettings() {
        await test.step("Go to Settings view", async () => {
            await this.page.click(
                '.InactiveViewInputRadioButton:has-text("Settings")'
            );
            await this.page.waitForSelector(
                '.ActiveViewInputRadioButton:has-text("Settings")'
            );
        });
    }
Example #15
Source File: index.ts    From excalideck with MIT License 6 votes vote down vote up
async goToSlides() {
        await test.step("Go to Slides view", async () => {
            await this.page.click(
                '.InactiveViewInputRadioButton:has-text("Slides")'
            );
            await this.page.waitForSelector(
                '.ActiveViewInputRadioButton:has-text("Slides")'
            );
        });
    }
Example #16
Source File: index.ts    From excalideck with MIT License 6 votes vote down vote up
/*
     * Public API
     */

    async go() {
        await test.step("Go to Excalideck Editor test page", async () => {
            await this.page.goto("/");
        });
    }
Example #17
Source File: entry.spec.ts    From tailchat with GNU General Public License v3.0 6 votes vote down vote up
test.describe('entry page', () => {
  test('should auto jump to entry page', async ({ page }) => {
    await expect(page).toHaveURL('/entry/login');
  });

  test('auto goto entry if not login', async ({ page }) => {
    await page.goto('/main');
    await expect(page).toHaveURL('/entry/login?redirect=%2Fmain'); // should with redirect
  });

  test('registry', async ({ page }) => {
    await page.locator('text=注册账号').click();
    await expect(page).toHaveURL('/entry/register');

    await page.locator('button:has-text("注册账号")').click();
    await expect(page.locator('p.text-red-500')).toHaveText('邮箱不能为空');

    await page.locator('[name="reg-email"]').click();
    await page.locator('[name="reg-email"]').fill('123456789');
    await page.locator('button:has-text("注册账号")').click();
    await expect(page.locator('p.text-red-500')).toHaveText('邮箱格式不正确');

    await page.locator('[name="reg-email"]').click();
    await page.locator('[name="reg-email"]').fill('[email protected]');
    await page.locator('button:has-text("注册账号")').click();
    await expect(page.locator('p.text-red-500')).toHaveText('密码不能低于6位');

    await page.locator('[name="reg-password"]').click();
    await page.locator('[name="reg-password"]').fill('1234');
    await page.locator('button:has-text("注册账号")').click();
    await expect(page.locator('p.text-red-500')).toHaveText('密码不能低于6位');
  });
});
Example #18
Source File: main.spec.ts    From player-component with MIT License 6 votes vote down vote up
test.describe("Player", ()=>{
  test.beforeEach(async ({ page }) => {
    // Go to the starting url before each test
    await page.goto("http://localhost:8080", { waitUntil: "domcontentloaded" });
  });

  test("is present", async ({ page }) => {
    const selector = "dotlottie-player";
    const element = await page.innerHTML(selector);
    expect(element).toBeDefined();
  });

  test("controls are present", async ({ page }) => {
    const selector = ".controls";
    const element = await page.$$(selector);
    expect(element.length).toBeGreaterThan(0);
  });

  test("seeker is present", async ({ page }) => {
    const selector = ".seeker";
    const element = await page.$$(selector);
    expect(element.length).toBeGreaterThan(0);
  });

  test("screenshot matches", async ({ page }) => {
    // wait for the page to load (could use some other signal?)
    await page.waitForTimeout(1000);

    const screenshot = await page.screenshot({fullPage: true});
    expect(screenshot).toMatchSnapshot(`player-test.png`, { threshold: 0.2 });
  });
});
Example #19
Source File: skipping-slide.test.ts    From excalideck with MIT License 6 votes vote down vote up
test("Skip a slide", async ({ page }) => {
    const excalideckEditorPage = new ExcalideckEditorPage(page);
    await excalideckEditorPage.go();
    await excalideckEditorPage.drawRectangle();
    await excalideckEditorPage.addSlide();
    await excalideckEditorPage.drawEllipse();
    await excalideckEditorPage.selectSlide(1);
    await excalideckEditorPage.skipSlide();
    await excalideckEditorPage.expectToSee(
        "two slide miniatures",
        "the second slide miniature is skipped"
    );
});
Example #20
Source File: screenshots.spec.ts    From mirrorz with MIT License 5 votes vote down vote up
test.beforeAll(async () => {
    server.listen(8000);
});
Example #21
Source File: config.ts    From player-component with MIT License 5 votes vote down vote up
test.runWith(new FirefoxEnv(options), { tag: 'firefox' });
Example #22
Source File: screenshots.spec.ts    From mirrorz with MIT License 5 votes vote down vote up
Object.entries(testPages).map(([name, url]) => test(name, async ({ browserName, page }) => {
    await page.goto(baseUrl + url);
    await page.waitForTimeout(1000);
    expect(await page.screenshot({ fullPage: true })).toMatchSnapshot(name + '.png', { threshold: 0.2 });
}));
Example #23
Source File: screenshots.spec.ts    From mirrorz with MIT License 5 votes vote down vote up
test.afterAll(async () => {
    server.close();
});
Example #24
Source File: entry.spec.ts    From tailchat with GNU General Public License v3.0 5 votes vote down vote up
test.beforeEach(async ({ page }) => {
  await page.goto('/');
});
Example #25
Source File: main.spec.ts    From tailchat with GNU General Public License v3.0 5 votes vote down vote up
test.beforeEach(async ({ page, context }) => {
  await loginToDemoUser(page, context);
});
Example #26
Source File: basic.spec.ts    From mui-toolpad with MIT License 5 votes vote down vote up
test('basic test', async ({ page }) => {
  await page.goto('/');
  const brand = page.locator('data-test-id=brand');
  await expect(brand).toHaveText('MUI Toolpad CE');
});
Example #27
Source File: changing-printable-area.test.ts    From excalideck with MIT License 5 votes vote down vote up
test("Change the printable area", async ({ page }) => {
    const excalideckEditorPage = new ExcalideckEditorPage(page);
    await excalideckEditorPage.go();
    await excalideckEditorPage.goToSettings();
    await excalideckEditorPage.changePrintableArea(1000, 1000);
    await excalideckEditorPage.expectToSee("a square printable area");
});
Example #28
Source File: index.ts    From excalideck with MIT License 5 votes vote down vote up
async skipSlide() {
        await test.step("Skip slide", async () => {
            await this.page.click('button[title*="skip" i][aria-checked=true]');
            await this.page.waitForSelector(
                'button[title*="skip" i][aria-checked=false]'
            );
        });
    }
Example #29
Source File: index.ts    From excalideck with MIT License 5 votes vote down vote up
async addSlide() {
        await test.step("Add slide to the deck", async () => {
            await this.runAndWaitForSlideMiniaturesChange(async () => {
                await this.page.click('button[title*="add slide" i]');
            });
        });
    }