Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Faker fixture

This is a base @faker-js/faker all-in-one fixture and helpers for playwright from Playwright labs team!

Installation

  1. Install playwright (optional)
npm i  @playwright/test
pnpm add @playwright/test
yarn add @playwright/test
  1. Install @playwright-labs/fixture-faker
npm i @playwright-labs/fixture-faker
pnpm add @playwright-labs/fixture-faker
yarn add @playwright-labs/fixture-faker

Usage

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 fakerExpect,
  test as fakerTest,
} from "@playwright-labs/fixture-faker";

export const expect = mergeExpects(fakerExpect);
export const test = mergeTests(fakerTest);

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");
});