Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Accessing the current test in an After block #3528

Unanswered
Todaichi asked this question in Q&A
Discussion options

I am writing some custom logging, due to our crazy system. I have all of it in place except 1 thing, I can't figure out how to grab the current test in the After hook... neither _after as a helper or After() as a Scenario header. You can pass "test" to a before, but you can't with an After. Any ideas how I can access the current Test?

If running a Break point in the "After" block the debugger gives a reference to a "currentTest" block that has all the information I need, but I can't find a way to access it.

After(async ({I}) => {
if(testPassed)
doThis()
else
DoThat()
});

You must be logged in to vote

Replies: 1 comment

Comment options

@Todaichi looks like you can use https://codecept.io/hooks/#event-listeners as a helper, smth like

const {Helper, event} = require('codeceptjs');
class SomeHelper extends Helper {
 /**
 * Constructor
 * @param config
 */
 constructor(config) {
 super(config);
 event.dispatcher.on(event.test.after, function (test) {
 console.log(test)
 })
 }
}
module.exports = SomeHelper;

will give you access to test object after his execution.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /