zerostep-ai / zerostep

Supercharge your Playwright tests with AI
MIT License
197 stars 17 forks source link

Need help - Getting error while trying to execute from inside cucumber js steps #32

Closed debdutta-chatterjee closed 8 months ago

debdutta-chatterjee commented 10 months ago

When executing the ai step inside cucumber getting the error -> "Error: test.step() can only be called from a test"

Can you please share an example how to call the Ai() functions inside cucumber JS

Sample code I am using

When('Hit enter', async function () {
    const page = pageFixture.page;
    await ai('Hit enter', { page, test })
  });
tmcneal commented 10 months ago

@debdutta-chatterjee Can you provide a full test that allows us to repro the issue?

debdutta-chatterjee commented 10 months ago

Please find the details

Feature file

Feature: AI test using zero code

Scenario: Search and verify the first organic search result

And Hit enter

Step definition

import {Given, When, Then} from '@cucumber/cucumber'
import { pageFixture } from '../../hooks/pageFixture';
import {chromium,test,Page} from '@playwright/test'
import { ai } from '@zerostep/playwright'

let page : Page;

When('Hit enter', async function () {
  let browser = await chromium.launch({ headless: false });
  page = await browser.newPage();  
  await page.goto('https://www.google.com');
    await ai('Hit enter', { page, test })
  });

Error

× And Hit enter # src\test\steps\aiTestStpes.ts:8 Error: test.step() can only be called from a test at TestTypeImpl._step (C:\Users\path\node_modules\@playwright\test\node_modules\playwright\lib\common\testType.js:192:26) at C:\Users\path\node_modules\@zerostep\playwright\src\index.ts:34:10 at ai (C:\Users\path\node_modules\@zerostep\playwright\src\index.ts:31:10) at World. (C:\Users\\aiTestStpes.ts:12:13)

Note - "path" is system folder path

tmcneal commented 8 months ago

Can you try putting the When inside a test block like in the examples in our repo? I'm not familiar with how the Cucumber library works for Playwright, so I'm unsure of if Cucumber tests will work inside a test block or not. But as the error states, you need to be within the context of a "test" in order for an ai() step to work.