How to run a command that performs an S3 upload AFTER ALL feature files/steps are executed?

48 Views Asked by At

I am currently executing some basic performance tests using the following:

STATUS: the performanceTotal package generates csv and json results files form where I extract information in order to generate a graph that measures the time it takes for changing a page, for example. The results files are generated ONLY AFTER ALL features/steps (including AfterAll) are executed.

ISSUE: in order to generate long term graphs with the results I am interested in, I plan on running the tests in Jenkins, but I need to upload the results files to S3 (upload request successful!) and since the tests results files are available only at the end of the execution, is there a way of executing the upload command "outside" or after the ending of the run?

Here is a snippet of the AfterAll step, where feat is an Array of the features I am testing and item is an object/feature from the array which is used for generating individual graphs. For example feat may contain: [Login, Logout, NavigationToPage_X, etc.]. result is a JSON with the extracted info from the results files used for graph generation.

AfterAll({timeout: 10 * 60000} ,async () => {
  logInfo("Starting generation of charts and upload of json result files to S3");
  await Promise.all(feat.map(async item => {
    await generatePerformanceChart(item, "line", result);
    await uploadResultsToS3(item);
  }));
  logSuccess("Upload of results files to S3 successful!");
});

But this doesn't work as the results files are generated after the AfterAll step for some reason. I would require something that executes the upload command outside the Cucumber framework.

1

There are 1 best solutions below

1
HaC On

It looks like you are running it under AfterAll inside of a Step definition? What you need is to use the onComplete Hook under your wdio.conf.js instead. From WebdriverIO doc:

/**
 * Gets executed after all workers have shut down and the process is about to exit.
 * An error thrown in the `onComplete` hook will result in the test run failing.
 * @param {object} exitCode 0 - success, 1 - fail
 * @param {object} config wdio configuration object
 * @param {Array.<Object>} capabilities list of capabilities details
 * @param {<Object>} results object containing test results
 */
onComplete: function (exitCode, config, capabilities, results) {
},