CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Any way to run tests in specific order?

Open iljao opened this issue 7 years ago • 6 comments

I have 3 test files, each with a single feature and multiple scenarios. I'd like to execute this features (or files) in a specific order. Is there a way to do it, beside having all files named in alphabetic order?

Thanks!

iljao avatar Feb 20 '19 18:02 iljao

1_test_auth.ts 2_test_network.ts 3_test_download.ts

xeonarno avatar Feb 20 '19 23:02 xeonarno

I found it best to use numbers starting at 10 if you have less than 100 tests in the folder. If over 100 tests in the test folder start at 100.

Example: 100_test_auth.ts 101_test_network.ts 102_test_download.ts

If you don't do it this way your files may not run in the expected order. A test with prefix 10 may run after a test with prefix 1.

impressto avatar Jan 26 '20 23:01 impressto

Anyway, tests should not be dependent on other tests. Try to avoid this

elukoyanov avatar Jan 27 '20 07:01 elukoyanov

Anyway, tests should not be dependent on other tests. Try to avoid this

I don't think is it about dependencies, just knowing the order in which the tests will run so it is predictable.

impressto avatar Jan 27 '20 08:01 impressto

Having a dependant order of tests can be important in e2e testing if you need to step through certain sequential items. Say step 1 you create your user by signing up, then step 2 log in with said user and carry on with the testing.

finnmerlett avatar Feb 18 '22 01:02 finnmerlett

the below code i am using but not able to execute the test cases in sequence one after another, My test cases are depends on previous test cases in E2E.

Please help me where i need to specify the feature files to execute my test cases sequentially. const { Workers, event } = require('codeceptjs'); const workerConfig = { testConfig: 'codecept.conf.js', }; // don't initialize workers in constructor const workers = new Workers(null, workerConfig); const testGroups = workers.createGroupsOfTests(1); const browser = { url: 'http://localhost', show: true, browser: 'chromium', ignoreHTTPSErrors: true, restart: true, keepCookies: false } const browsers = [browser, browser]; const runTags = ['@Smoke, '@Sanity'] const configs = browsers.map(browser => { let data = { helpers: { Playwright: browser } } return data }); for (const config of configs) { for (group of testGroups) { const worker = workers.spawn(); worker.addTests(group); worker.addConfig(config); worker.addConfig({ mocha: { grep: runTags[configs.indexOf(config)], reporter: 'mocha-junit-reporter', reporterOptions: { mochaFile: junitReports/result${configs.indexOf(config)}${testGroups.indexOf(group)}.xml } } }) } } workers.on(event.test.failed, (failedTest) => { console.log('Failed : ', failedTest.title); });

// Listen events for passed test workers.on(event.test.passed, (successTest) => { console.log('Passed : ', successTest.title); });

// test run status will also be available in event workers.on(event.all.result, () => { // Use printResults() to display result with standard style workers.printResults(); });

// run workers as async function runWorkers();

async function runWorkers() { try { // run bootstrapAll await workers.bootstrapAll(); // run tests await workers.run(); } finally { // run teardown All await workers.teardownAll(); } }

anil-devaki avatar Sep 26 '22 19:09 anil-devaki