-
-
Notifications
You must be signed in to change notification settings - Fork 747
-
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
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 8 comments
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
@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).
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
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;
Wondering if there is a better way to do this.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
@xMutaGenx thanks! Your solution is even better since it gives the actual chunk number.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
@theptyza or @xMutaGenx could you share the configuration to achive this
Beta Was this translation helpful? Give feedback.
All reactions
-
@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", } },
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 4
-
What about
const { threadId } = require('worker_threads'); const allure = codeceptjs.container.plugins('allure'); allure.addLabel('thread', threadId);
?
Beta Was this translation helpful? Give feedback.