vitalets / playwright-bdd

BDD testing with Playwright runner
https://vitalets.github.io/playwright-bdd/
MIT License
302 stars 35 forks source link

Bug: BeforeAll missing browser #85

Closed moygospadin closed 7 months ago

moygospadin commented 9 months ago
const { BeforeAll, AfterAll } = createBdd();

BeforeAll(async function ({ playwright }) {
  try {
    const browser = await playwright.chromium.launch();
    console.log("browser", browser);
  } catch (error) {
    console.log("error", error);
  }}

the same for

const { BeforeAll, AfterAll } = createBdd();

BeforeAll(async function ({ browser }) {
  try {
    const page = await browser.newPage();
    console.log("page", page);
  } catch (error) {
    console.log("error", error);
  }}

page or browser is undefined "@playwright/test": "^1.40.1", "@cucumber/cucumber": "^10.0.1", "playwright-bdd": "^5.7.1",

moygospadin commented 9 months ago

Playwright config

import { defineConfig, devices } from "@playwright/test";
import { defineBddConfig } from "playwright-bdd";

require("dotenv").config({ path: __dirname + "/.env" });
const testDir = defineBddConfig({
  importTestFrom: "./tests/steps/fixtures.ts",
  paths: ["./tests/features"],
  require: ["./tests/steps/*.ts"],
  quotes: "backtick",
  featuresRoot: "./tests/features",
});

export default defineConfig({
  testDir,
  reporter: "html",

  webServer: [
    {
      env: {
        googleRefreshToken: process.env.GOOGLE_REFRESH_TOKEN as string,
        googleClientId: process.env.REACT_APP_GOOGLE_CLIENTID as string,
        googleClientSecret: process.env
          .REACT_APP_GOOGLE_CLIENT_SECRET as string,
      },
      command: "yarn run start:e2e",
      url: "http://localhost:8080",
      reuseExistingServer: true,
    },
  ],

  use: {
    screenshot: "only-on-failure",
    baseURL: "https://finops-staging.globalgiving.org",
  },
  projects: [
    {
      name: "chromium",

      use: {
        ...devices["Desktop Chrome"],
        storageState: "./setup/storage-state.json",
      },
    },
  ],
});
vitalets commented 9 months ago

Hi @moygospadin I've tried to reproduce the issue in playwright-bdd example in hooks-fixtures-85 branch. After running npm test it correctly shows that browser and page are defined:

  1. Could you clone this branch and run npm test on it?
  2. How do you import files with hooks?
vitalets commented 7 months ago

Closing as not reproducible.