vitalets / playwright-bdd

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

Question: Using request #212

Closed bmsoko closed 1 month ago

bmsoko commented 3 months ago

Hello, Can you please provide example of using playwright's request? I had successfully implemented for UI, and would love to have in the same project API requests, but when I add a api-login-steps.ts, the FW seems not to find the step.

I've created the following

import { createBdd } from 'playwright-bdd';
import { test } from '../fixtures/fixture';
import { expect, request } from '@playwright/test';

const { Before, Given, When, Then } = createBdd(test);

Given('User logs in', async ({ apiUserPage, request } ) => {
  const response = await request.post('....',
    {
      data: 
        {
          "AuthParameters": {
              "USERNAME": "....",
              "PASSWORD": "...!"
          },
          "AuthFlow": "USER_PASSWORD_AUTH",
          "ClientId": "...."
      },
      headers: {
        "X-AAA-Target": "...",
        "Content-Type": "application/x-amz-json-1.1",

      }

    }

  )
  var res = await response.json()
  console.log(res);

  let IdToken = await res.AuthenticationResult.IdToken;
  console.log(IdToken);

  expect(response.status()).toBe(200);

});

After executing npx bddgen --tags '@API' && cross-env ENV=stg npx playwright test

I get the following:

npm run test-stg-api

> mt_stargate_playwright_bdd_poc@0.1.0 test-stg-api
> npx bddgen --tags '@API' && cross-env ENV=stg  npx playwright test

WARNING: Option "importTestFrom" in defineBddConfig() is not needed anymore. Try to remove it and include that file into "steps" pattern.
--
This warning can be disabled by setting in BDD config:
disableWarnings: { importTestFrom: true }
Feel free to report any bugs: https://github.com/vitalets/playwright-bdd/issues
/Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/dist/gen/testFile.js:323
        throw new Error(`Pickle step not found for step: ${step.text}`);
              ^

Error: Pickle step not found for step: User logs in
    at TestFile.findPickleStep (/Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/gen/testFile.ts:409:11)
    at TestFile.getStep (/Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/gen/testFile.ts:324:29)
    at /Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/gen/testFile.ts:285:16
    at Array.map (<anonymous>)
    at TestFile.getSteps (/Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/gen/testFile.ts:277:34)
    at TestFile.getBeforeEach (/Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/gen/testFile.ts:202:38)
    at TestFile.getSuiteChild (/Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/gen/testFile.ts:186:39)
    at /Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/gen/testFile.ts:180:60
    at Array.forEach (<anonymous>)
    at TestFile.getSuite (/Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/gen/testFile.ts:180:22)
    at TestFile.getRootSuite (/Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/gen/testFile.ts:170:17)
    at TestFile.build (/Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/gen/testFile.ts:106:25)
    at /Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/gen/index.ts:90:12
    at Array.map (<anonymous>)
    at TestFilesGenerator.buildFiles (/Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/gen/index.ts:82:8)
    at /Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/gen/index.ts:33:12
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at withExitHandler (/Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/utils/exit.ts:30:12)
    at TestFilesGenerator.generate (/Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/gen/index.ts:31:5)
    at async Promise.all (index 0)
    at Command.<anonymous> (/Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/src/cli/commands/test.ts:32:5)

Node.js v22.5.1

And if I execute with --verbose

npx bddgen --verbose
WARNING: Option "importTestFrom" in defineBddConfig() is not needed anymore. Try to remove it and include that file into "steps" pattern.
--
This warning can be disabled by setting in BDD config:
disableWarnings: { importTestFrom: true }
Feel free to report any bugs: https://github.com/vitalets/playwright-bdd/issues
Loading steps: tests/steps/*.ts
Resolved step files: 2
  tests/steps/api-steps.ts
  tests/steps/login-steps.ts
Loaded steps: 6
Loading features: tests/features/***.feature
Resolved feature files: 2
  tests/features/login.feature
  tests/features/user-api.feature
/Users/bsoko/Documents/Dev/mt_stargate_playwright_bdd_poc/node_modules/playwright-bdd/dist/gen/testFile.js:323
        throw new Error(`Pickle step not found for step: ${step.text}`);
              ^
.....
....
....
Node.js v22.5.1

Thank you.

vitalets commented 3 months ago

Hey! I see that 2 step files were found by pattern tests/steps/*.ts:

Resolved step files: 2
  tests/steps/api-steps.ts
  tests/steps/login-steps.ts

But file with step User logs in is named as api-login-steps.ts. Could you share files structure - where is it located?

vitalets commented 1 month ago

Closing as there is no response from author. Feel free to reopen if needed.