In Playwright cucumber JS framework , how to add logs in allure report? #2169
Unanswered
preethinaren
asked this question in
Questions & Support
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to add logs in the allure report, but it's not working. See error like below
error: Allure.addStep is not a function
error: Allure.logsetp is not a function
error: Allure.addAttachment is not a function
Can someone please help me?
const allure = require('allure-commandline');
// Log the modified names to Allure report
allure.addAttachment('Modified First Name', modifiedFirstName, 'text/plain');
allure.addAttachment('Modified Last Name', modifiedLastName, 'text/plain');
// Log the request data to Allure report
allure.addAttachment('Request Data', JSON.stringify(global.attom_home_value_jsonData, null, 2), 'application/json')
error:
Launching browser
Creating a new context and page
Modified First Name: TestAutomationF5M
Modified Last Name: QAAPIAutomationF5M
Error: Allure.addStep is not a function
Closing page and context
Closing the browser
Project code:
{
"name": "api-automation",
"version": "1.0.0",
"description": "test.",
"main": "index.js",
"scripts": {
"test": "npx cross-env NODE_ENV=TEST cucumber-js --tags @test --require cucumber.js --require src/tests/step-definitions/**/*.js --format ./src/helper/report/allure-config.js",
"allure:generate": "npx allure generate ./allure-results --clean",
"allure:open": "allure open allure-report"
},
"keywords": [],
"author": "preethi",
"license": "ISC",
"devDependencies": {
"@cucumber/cucumber": "^9.4.0",
"@cucumber/pretty-formatter": "^1.0.0",
"@playwright/test": "^1.37.0",
"allure-commandline": "^2.24.1",
"allure-cucumberjs": "^2.9.2",
"allure-js-commons": "^2.9.2",
"chai": "^4.3.7",
"cheerio": "^1.0.0-rc.12",
"cross-env": "^7.0.3",
"cucumberjs-allure2-reporter": "^1.3.0",
"dotenv": "^16.3.1",
"fs-extra": "^11.1.1",
"jsdom": "^22.1.0",
"multiple-cucumber-html-reporter": "^3.4.0",
"node-html-parser": "^6.1.5"
},
"dependencies": {
"@faker-js/faker": "^8.1.0",
"axios": "^1.5.0",
"csv-parser": "^3.0.0",
"faker": "^5.5.3",
"log4js": "^6.9.1",
"winston": "^3.11.0"
}
}
Allure-config.js:
const { AllureRuntime } = require("allure-js-commons");
const { CucumberJSAllureFormatter } = require("allure-cucumberjs");
class AllureCucumberJSFormatter extends CucumberJSAllureFormatter {
constructor(options) {
super(options, new AllureRuntime({ resultsDir: "./allure-results" }), {
labels: [
{
pattern: [/@feature:(.)/],
name: "epic",
},
{
pattern: [/@Severity:(.)/],
name: "severity",
},
],
links: [
{
pattern: [/@issue=(.)/],
type: "issue",
urlTemplate: "http://localhost:8080/issue/%s",
},
{
pattern: [/@tms=(.)/],
type: "tms",
urlTemplate: "http://localhost:8080/tms/%s",
},
],
});
}
}
module.exports = AllureCucumberJSFormatter;
cucumber Test:
const { Given, When, Then, defineStep, setDefaultTimeout, Before } = require('@cucumber/cucumber');
const faker = require('faker');
const fs = require('fs');
const csv = require('csv-parser');
const os = require('os');
const {Allure} = require('allure-js-commons');
global.attom_home_value_jsonData = null; // Initialize attom_home_value_jsonData as a global variable
global.fake_home_value_jsonData = null; // Initialize fake_home_value_jsonData as a global variable
global.fake_State_jsonData = null;
const exitingRecordFilePath = 'src/helper/util/test-data/usedData.csv';
// input given in scenarios outline
Given(/^I create a borrower lead with Firstname "([^"])",Lastname "([^"])", age "([^"])",Address "([^"])",City "([^"])",state "([^"])",zipcode "([^"])",PropertyValue "([^"])",MortgageBalance "([^"]*)"$/,
async (FirstName, LastName, Age, StreetAddress, City, State, Zipcode, PropertyValue, MortgageBalance) => {
const randomString = generateRandomString(3); // Change the length as needed
const modifiedFirstName = FirstName + randomString;
const modifiedLastName = LastName + randomString;
// Log the modified names to Allure report
Allure.addAttachment('Modified First Name', modifiedFirstName, 'text/plain');
Allure.addAttachment('Modified Last Name', modifiedLastName, 'text/plain');
global.attom_home_value_jsonData = { test object
};
// Log the request data to Allure report
allure.addAttachment('Request Data', JSON.stringify(global.attom_home_value_jsonData, null, 2), 'application/json');
});
Beta Was this translation helpful? Give feedback.
All reactions