Skip to content

get test title in After() or Scenario() #3662

Closed Answered by myrepojuly1987
adudyak asked this question in Q&A
Discussion options

You must be logged in to vote

@adudyak - You mean how to call the test title inside the test scenario? You can try something like below

const { event } = require('codeceptjs');

const testDetails = {
  title: null
};

event.dispatcher.on(event.test.before, function (test) {
  testDetails.title =test.title ;
});

module.exports = { testDetails };

Then in your test file,

const  {testDetails} = require('./events');

Feature('Test something');

Scenario('test scenario', async ({ I }) => {
  console.log(testDetails.title);
});

I don't think we the below is required in the codecept.conf.js. You can remove it, if the above works. Please test it.

CustomSteps: {
     require: './events.js' //relative path to the events.js fi…

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@adudyak
Comment options

@myrepojuly1987
Comment options

@adudyak
Comment options

@myrepojuly1987
Comment options

Answer selected by adudyak
@myrepojuly1987
Comment options

@adudyak
Comment options

@adudyak
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants