CleanupTotalサービス
wdio-cleanuptotal-service はサードパーティ製のパッケージです。詳細については、GitHub | npm を参照してください。
webdriver.io 用の cleanup-total サービスを使用すると、各テスト後の適切なクリーンアップを簡単に確保できます。このサービスは、作成直後に削除対象としてエンティティをマークするための体系的な方法を提供します。これは、テストで投資プランと預金のある銀行口座などの複雑な構造を作成する場合に特に役立ちます。適切なクリーンアップを行わないと、口座が空でないために拒否されるなど、口座の削除を試みるとエラーが発生する可能性があります。ただし、cleanup-totalを使用すると、エンティティが正しい順序で削除され、テストが後処理され、互いに干渉しないことが保証されます。
インストール
このモジュールを (開発) 依存関係としてインストールする最も簡単な方法は、次のコマンドを使用することですnpm install wdio-cleanuptotal-service --save-dev
使用法
wdio.conf.js に wdio-cleanuptotal-service を追加します
exports.config = {
  // ... other options
  services: ['cleanuptotal']
  // ... other options
};
またはサービスオプションを使用します
exports.config = {
  // ... other options
  services: [
    [
      'cleanuptotal',
      {
        // Use a custom logger function to write messages to the test report
        customLoggerMethod: console.log(), // TODO: replace with your own logger function if needed
        // Only write to the log when an error occurs to reduce clutter
        logErrorsOnly: false, // TODO: consider changing to 'true' if you have too many messages in the report
      }
    ]
  ]
  // ... other options
};
テストでの使用法
テストファイルやその他のクラスなど、必要な場所でcleanuptotalサービスをインポートできます。
import { cleanuptotal } from "wdio-cleanuptotal-service";
it("should keep things tidy", () => {
  // ...
  // Create an account and add it to the cleanup list for deletion after the test
  const accountId = createAccount("John Blow");
  cleanupTotal.addCleanup(async () => {
    await deleteAccount(accountId);
  });
  // Add an investment plan to the account and add it to the cleanup list
  addInvestmentPlan(accountId, "ModRisk");
  cleanupTotal.addCleanup(async () => {
    await removeInvestmentPlan(accountId);
  });
  // Deposit funds into the account and add it to the cleanup list
  deposit(accountId, 1000000);
  cleanupTotal.addCleanup(async () => {
    await undoDeposit(accountId);
  });
  // ...
});
// Note that the actual cleanup code will be executed after the test is complete
Typescriptサポート
このプラグインでは Typescript がサポートされています。