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

How to get thread number with parallel execution for Allure report timeline? #3031

Unanswered
theptyza asked this question in Q&A
Discussion options

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.
parallel timelines

What do you get instead?

By default in the Allure report all tests are displayed in one timeline.
single timeline

I can add labels to test cases like

const allure = codeceptjs.container.plugins('allure');
Before(() => 
 allure.addLabel('thread', '...')
)

My question is - how can I get the chunk number in the test?

Details

  • CodeceptJS version: 2.3.0
  • NodeJS Version: 10.16.3
  • Operating System: Windows 10
  • Configuration file:
exports.config = {
 ...
 mocha: {
 reporterOptions: {
 reportDir: "./test/report",
 autoOpen: true,
 }
 },
 plugins: {
 allure: {
 enabled: true,
 outputDir: "./test/.output/allure-results"
 },
 stepByStepReport: {}
 },
 multiple: {
 parallel: {
 chunks: "4"
 }
 },
 bootstrap: false,
 teardown: null,
 hooks: [],
 tests: "./test/tests/ui/dashboard/*.js",
 timeout: 120000,
};

Running tests with

npx codeceptjs run-multiple parallel
You must be logged in to vote

Replies: 8 comments

Comment options

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 globally CHUNKS=4 npx codeceptjs run-multiple parallel then 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.

You must be logged in to vote
0 replies
Comment options

@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).

You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
0 replies
Comment options

I 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;

parallel pid

Wondering if there is a better way to do this.

You must be logged in to vote
0 replies
Comment options

@xMutaGenx thanks! Your solution is even better since it gives the actual chunk number.

You must be logged in to vote
0 replies
Comment options

@theptyza or @xMutaGenx could you share the configuration to achive this

You must be logged in to vote
0 replies
Comment options

@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",
 }
 },
You must be logged in to vote
0 replies
Comment options

What about

const { threadId } = require('worker_threads');
const allure = codeceptjs.container.plugins('allure');
allure.addLabel('thread', threadId);

?

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
Converted from issue

This discussion was converted from issue #1855 on September 05, 2021 18:48.

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