剧作家:自动测试失败时不会删除自动测试容器

时间:2020-11-11 14:12:23

标签: javascript typescript automated-tests playwright

即使测试由于某种原因失败,如何将Playwright中的测试容器设置为自动删除?我们在测试的“之后”部分中使用了.deleteContainer方法,但这仅在不中断测试的情况下有效。知道如何在测试中断的情况下实现一些自动删除方法吗?

这是我们的测试套件的外观:

export const someSuite = ({
  module,
  description,
  tests,
  snapshots,
}: SuiteArgs) => {
  const browsersToRun = browsers;

      browsers.forEach((browserType) => {
    describe(`[${module} - ${browserType}] ${description}`, () => {
      const testContext = new TestContext();

      before(async () => {
        testContext.container = (
          await DockerAPI.ContainerManager.createContainer(snapshots)
        ).containerInfo;
        testContext.browser = (await playwright[browserType].launch({
          ...getBrowserSpecificArgs(browserType),
          headless: false,
        })) as Browser;
        testContext.browserContext = await testContext.browser.newContext();
        testContext.page = await testContext.browserContext.newPage();
      });

      tests(testContext);

      after(async () => {
        **await DockerAPI.ContainerManager.deleteContainer(
          testContext.container.uuid**
        );
        await testContext.page.close();
      });
    });
  });
};

0 个答案:

没有答案