Repository navigation
How to get thread number with parallel execution for Allure report timeline? #1855
Description
Activity
You can retrieve your chunks configuration with the following
const chunks = require('codeceptjs').config.get()['multiple']['parallel']['chunks'];alternatively you can pass in the number of chunks to the node env, which then allows you to access that globallyCHUNKS=4 npx codeceptjs run-multiple parallelthen you can set them in your config via:multiple: { parallel: { chunks: process.env.CHUNKS } }As well as access them globally:
const allure = codeceptjs.container.plugins('allure'); Before(() => allure.addLabel('thread', process.env.CHUNKS) )Hope this helps.
@xMutaGenx thanks. What I'm trying to do is get the current chunk number.
So that tests from chunk 1 are recorded as thread 1, tests from chunk 2 as thread 2 etc.With
const chunks = require('codeceptjs').config.get()['multiple']['parallel']['chunks']; Before(() => allure.addLabel('thread', process.env.CHUNKS) )
Every test is recorded as thread 4 (the number of chunks).
Ah apologies @theptyza misunderstood you then, one way you could do this is by accessing the mocha child processes:
let child = require('codeceptjs').config.get().mocha.child;
This will give you something like
1.chrome:chunk1:chrome
Next you'll want to get the number of your child process from the string:child = child.substring(0, child.indexOf('.'));
Finally you'll have something like:
Before(() => { let child = require('codeceptjs').config.get().mocha.child; child = child.substring(0, child.indexOf('.')); allure.addLabel('thread', child) })
Not the cleanest approach, but it works, might allow you to continue working until a better solution appears 🤷♂ Hope this helps.
Reacted by Stanislav RogozhinI was able to use process ID as thread number for Allure report by creating a helper that sets thread label for each test
let Helper = codecept_helper; const process = require('process'); class AllureHelper extends Helper { _before() { const allure = codeceptjs.container.plugins('allure'); allure.addLabel('thread', process.pid); } } module.exports = AllureHelper;
Wondering if there is a better way to do this.
Reacted by jancorvus@xMutaGenx thanks! Your solution is even better since it gives the actual chunk number.
Reacted by xMutaGenx@theptyza or @xMutaGenx could you share the configuration to achive this
@Naimadnap I've created an allureHelper
'use strict'; let Helper = codecept_helper; class AllureHelper extends Helper { _before() { let child = codeceptjs.config.get().mocha.child; // if there are child processes set thread label in Allure report to chunk number // child process name is like '1.parallel:chunk1:default' if(child) { const allure = codeceptjs.container.plugins('allure'); allure.addLabel('thread', child.substring(0, child.indexOf('.'))); } } } module.exports = AllureHelper;
and included it in codecept.conf.js
helpers: { Nightmare: { url: process.env.CODECEPT_URL || "http://localhost:3000", windowSize: "1920x1080", typeInterval: "-1" }, allureHelper: { require: "./test/helpers/allureHelper.js", } },
Reacted by xMutaGenx, Aravinda Weerasekara, eg and jancorvusWhat about
const { threadId } = require('worker_threads'); const allure = codeceptjs.container.plugins('allure'); allure.addLabel('thread', threadId);
?
- locked and limited conversation to collaborators
on Sep 5, 2021

What are you trying to achieve?
I'm running tests in parallel with 4 chunks and write reports to Allure.

I want to see tests from each chunk displayed in a separate timeline. If I manually add a "thread" label to each suite or test (in the XML) I can split the test results into multiple timelines.
What do you get instead?
By default in the Allure report all tests are displayed in one timeline.

I can add labels to test cases like
My question is - how can I get the chunk number in the test?
Details
Running tests with