Cucumber/CodeceptJs运行报错:../null文件未找到 求技术协助
Hey there! Let's figure out why you're hitting that "../null" file not found error when running your basic Cucumber/CodeceptJS test. This error almost always boils down to a misconfiguration in how your test setup is resolving paths to step definitions or feature files. Let's walk through the most likely fixes:
1. Double-Check Your CodeceptJS Configuration File (codecept.conf.js)
The biggest culprit here is usually an incorrect path in your codecept.conf.js, especially in the Cucumber plugin settings. CodeceptJS needs to know exactly where your step definitions live, and if that path is misconfigured (or accidentally resolving to null), it'll throw this error.
Make sure your config includes the correct path to your steps.js file under the Cucumber plugin's require option. For example:
exports.config = { // ... other config options like helpers, output, etc. plugins: { cucumber: { require: ['./steps.js'] // Adjust this path to match where your steps.js lives // If steps.js is in a subfolder like tests/steps, use './tests/steps/steps.js' } } };
Also verify the tests path points to your feature files correctly (e.g., ./basic.feature or ./tests/**/*.feature if you're using a folder structure).
2. Ensure Dependencies Are Properly Installed
Sometimes missing or corrupted dependencies can cause weird path resolution issues. Run these commands to make sure everything is set up correctly:
npm install # Or if you use yarn: yarn install
This will ensure CodeceptJS, Cucumber, and all their required packages are installed and available.
3. Verify File Structure & Naming
- Make sure your
basic.featureandsteps.jsfiles are in the locations your config expects. For example, if your config looks for features in./tests/features, don't leavebasic.featurein the root folder. - Confirm your step definition file is named correctly (CodeceptJS defaults to looking for files named
steps.js, but if you've renamed it, you need to update the config to match).
Your Provided Code for Reference
Just to recap, here's the code you shared formatted clearly:
basic.feature
Feature: Business rules In order to achieve my goals As a persona I want to be able to interact with a system Scenario: do something Given I have a defined step
steps.js
const { I } = inject(); Given('I have a defined step', () => { I.amOnPage('/my-page/ui'); });
Start by fixing the path in your codecept.conf.js first—this is the most common fix for this exact error. Once that's sorted, run your test again and it should pick up your step definition correctly!
内容的提问来源于stack exchange,提问作者Francislainy Campos

