Skip to main content

CleanupTotal Service

wdio-cleanuptotal-service is a 3rd party package, for more information please see GitHub | npm

With this plugin for webdriver.io it is easy to properly cleanup after each test. Cleanup after test might get complicated. For example: Lets say you are creating a bank account and then adding an investment plan and depositing there some money. If you try to delete the account you'd probably get a refusion because the account is not empty. cleanup-total helps you to do it systematically by 'marking' each entity you create for deletion right after its creation. When the test is finished, cleanup-total would delete the investment plan, the deposit and the account in the right order.

Installation

The easiest way to install this module as a (dev-)dependency is by using the following command:
npm install wdio-cleanuptotal-service --save-dev

Usage

Add wdio-cleanuptotal-service to your wdio.conf.js:

exports.config = {
// ...
services: ['cleanuptotal']
// ...
};

or with the service options:

exports.config = {
// ...
services: [
['cleanuptotal',
{
// TODO: you can put here any logger function
customLoggerMethod: allureReporter.addStep
}]
]
// ...
};

Usage in test

Just import cleanuptotal where you need it, whether it be your test file or any other class:

import { cleanuptotal } from "wdio-cleanuptotal-service";

it("should keep things tidy", () => {
// ...

const accountId = createAccount("John Blow");

cleanupTotal.addCleanup(async () => { await deleteAccount(accountId) }); // TODO: mark for deletion *

addInvestmentPlan(accountId, "ModRisk");

cleanupTotal.addCleanup(async () => { await removeInvestmentPlan(accountId) }); // TODO: mark for deletion *

deposit(accountId, 1000000);

cleanupTotal.addCleanup(async () => { await removeDeposit(accountId) }); // TODO: mark for deletion *

//...
});

// TODO: * Please note that the actual execution of the cleanup code would take palce AFTER test completion.

Typescript support

Typescript is supported for this plugin.