0

I'm using AWS lambda to execute API tests in my project. At the end of the test I'm generating Cucumber HTML report. Now I want to generate cucumber-js HTML report in memory and read the HTML report without saving it in a folder. Library name @cucumer/cucumber. This will help me to send cucumber report as email to stakeholders. Is there any way to generate HTML report in memory? currently, I'm using this command in package.json file to run the test and generate HTML report. cucumber-js -f html:output/report.html @tags

I'm looking for answer like creating a handler or runner to run cucumber tests:

ex:

cucumber.run({
    features: ['features/my-feature.feature'],
    reporters: [cucumberReport({ inMemory: true })],
});

1 Answer 1

0

There's a JavaScript API for running Cucumber:
https://github.com/cucumber/cucumber-js/blob/main/docs/javascript_api.md

There's no explicit provision for getting a handle of formatter output in memory. But you could override the stdout stream with a custom one so the formatter output is directed to that, and use the HTML formatter as the primary one, something like:

import { loadConfiguration, runCucumber } from '@cucumber/cucumber/api'

const environment = { stdout: myStream }
const { runConfiguration } = await loadConfiguration({
  provided: {
    format: ['html']
  }
}, environment)
const { success } = await runCucumber(runConfiguration, environment)
// do stuff with your report

Alternatively, you could just create a temporary file and then clean it up afterwards in the same process, something like:

import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { loadConfiguration, runCucumber } from '@cucumber/cucumber/api'

const tmpDir = tmpdir()
const { runConfiguration } = await loadConfiguration({
  provided: {
    format: ['html:' + join(tmpDir, 'report.html')]
  }
})
const { success } = await runCucumber(runConfiguration, environment)
// do stuff with your report and then delete the temporary file
Sign up to request clarification or add additional context in comments.

1 Comment

But is there anyway to save this HTML report in tmp folder in aws lambda? I tried this -f html:/tmp/cucumber_report.html with cucumber-js command. But unfortunately, I cannot save in tmp folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.