@playwright-labs/fixture-faker
v1.0.3
Published
Faker fixture integration for Playwright
Downloads
66
Maintainers
Readme
Faker fixture
This is a base @faker-js/faker all-in-one fixture and helpers for playwright from Playwright labs team!
Installation
- Install playwright (optional)
npm i @playwright/test
pnpm add @playwright/test
yarn add @playwright/test- Install
@playwright-labs/fixture-faker
npm i @playwright-labs/fixture-faker
pnpm add @playwright-labs/fixture-faker
yarn add @playwright-labs/fixture-fakerUsage
Basic Test Setup
import { test, expect } from "@playwright-labs/fixture-faker";
test("my test", async ({ page, faker }) => {
await page.goto("https://example.com");
await page.fill("#username", faker.internet.email());
await page.fill("#password", faker.internet.password());
await page.click("#submit");
});Advanced Usage (fixture)
// filename: custom-fixture.ts
import { mergeExpects, mergeTests } from "@playwright/test";
import {
expect as allureExpect,
test as allureTests,
} from "@playwright-labs/fixture-allure";
export const expect = mergeExpects(allureExpect);
export const test = mergeTests(allureTests);And now you are ready to use the custom fixture in your tests.
import { expect, test } from "./custom-fixture";
test("Login", async ({ page, faker }) => {
await page.goto("https://example.com");
await page.fill("#username", faker.internet.email());
await page.fill("#password", faker.internet.password());
await page.click("#submit");
});Using different locale
We exports useFaker function to configure faker with different options(e.g. locale)
import { test } from "@playwright-labs/fixture-faker";
test("simple test", async ({ page, useFaker }) => {
const faker = await useFaker({ locale: "fr" });
await page.fill("#username", faker.internet.email());
await page.fill("#password", faker.internet.password());
await page.click("#submit");
});