-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question:How do i get the "Scenario" details? #261
Comments
Feature files are not loaded inside test workers for performance reason. |
Based on steps, if step has data table then i want to set up the values in some variables before the start of the test. |
So, no built-in methods to achieve that for now. Given('my step with data table', async function (dataTable) {
// set up values for step with data table
// ...
}); Another more tricky option is to read test title and file from Before(async ({ $testInfo }) => {
console.log('Starting test:', $testInfo.title, $testInfo.file);
// 1. get location of feature file by $testInfo.file
// 2. read and parse feature file
// 3. find scenario by $testInfo.title
// 4. iterate through steps and check for data table
}); |
how would you iterate through steps ? while iteration we may get the steps text ? // 4. iterate through steps and check for data table |
The approach is like here: import path from 'node:path';
import fs from 'node:fs';
import * as Gherkin from '@cucumber/gherkin';
import * as Messages from '@cucumber/messages';
const uuidFn = Messages.IdGenerator.uuid();
const builder = new Gherkin.AstBuilder(uuidFn);
const matcher = new Gherkin.GherkinClassicTokenMatcher(); // or Gherkin.GherkinInMarkdownTokenMatcher()
const parser = new Gherkin.Parser(builder, matcher);
Before(async ({ $testInfo }) => {
const featureFile = './features/' + path.basename($testInfo.file).replace('.spec.js', '');
const featureContent = fs.readFileSync(featureFile, 'utf-8');
const gherkinDocument = parser.parse(featureContent);
const pickles = Gherkin.compile(gherkinDocument, featureFile, uuidFn);
const pickle = pickles.find((p) => p.name === $testInfo.title);
console.log(pickle?.steps);
}); |
I want to fetch the steps that are written in feature file and print before the test starts.
when i tried to implement below code its giving error for me on scenario
// Print all steps of the scenario
const steps = scenario.getSteps();
steps.forEach(step => {
const stepText = step.getText();
const hasDataTable = step.getArgument() instanceof DataTable;
console.log(
Step: ${stepText}
);console.log(
Contains Data Table: ${hasDataTable}
);});
The text was updated successfully, but these errors were encountered: