Rayrun
← Back to Discord Forum

TypeError: body is not a function

fatkobra_74254posted in #help-playwright
Open in Discord
fatkobra_74254

Hi, having problems running Playwright site test using Playwright-bdd. getting the following error:

✘  2 [chromium] › .features-gen/src/sample.feature.spec.js:6:7 › Playwright site › Check title (66ms)
--------------------------------------------------------------------------------
/home/.features-gen/src/sample.feature.spec.js:6

Playwright site: Check title


✗ Execution failed with error (69ms)

  TypeError: body is not a function
      at /home/.features-gen/src/sample.feature.spec.js:7:5


  1) [chromium] › .features-gen/src/sample.feature.spec.js:6:7 › Playwright site › Check title › [object Object] 

    TypeError: body is not a function

       5 |
       6 |   test("Check title", async ({ Given, When, Then }) => {
    >  7 |     await Given("I open url \"https://playwright.dev\"");
         |     ^
       8 |     await When("I click link \"Get started\"");
       9 |     await Then("I see in title \"Playwright\"");
      10 |   });

        at /home/.features-gen/src/sample.feature.spec.js:7:5

  1 failed
    [chromium] › .features-gen/src/sample.feature.spec.js:6:7 › Playwright site › Check title ──────
  1 passed (3.9s)
================================================================================
Execution Summary

Playwright site:                1 broken, 1 total (69ms)
src/config/le-auth-set...:  1 successful, 1 total (2s 734ms)

Total time: 2s 803ms
Real time: 3s 870ms
Scenarios:  2
================================================================================

package.json here:

"devDependencies": {
    "playwright-bdd": "^5.3.0",
    "@playwright/test": "^1.39.0",
    "@types/node": "^20.8.4",

This thread is trying to answer question "What is causing the 'TypeError: body is not a function' error in my Playwright-bdd test and how can I fix it?"

2 replies
ibrahim.bektas
ibrahim.bektas

What code is behind this ? | await Given("I open url "https://playwright.dev\""); -> somewhere you use a body() function

fatkobra_74254

Here is the code: @ibrahim.bektas

import { expect } from '@playwright/test';
import { createBdd } from 'playwright-bdd';

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

Given('I open url {string}', async ({ page }, url) => {
    await page.goto(url);
});

When('I click link {string}', async ({ page }, name) => {
    await page.getByRole('link', { name }).click();
});

Then('I see in title {string}', async ({ page }, keyword) => {
    await expect(page).toHaveTitle(new RegExp(keyword));
});

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].