From bedec09ebfa83ee96034fc8d3e78664701c243f8 Mon Sep 17 00:00:00 2001 From: abaeza-wp <153538325+abaeza-wp@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:30:44 +0000 Subject: [PATCH] NOTICKET: Improve end to end tests using retries for a more reliable run in ci pipelines and ensuring labels exists before extracting attributes (#98) --- demo-app/e2e/config.json | 1 + demo-app/e2e/jest.setup.js | 8 ++++++++ demo-app/e2e/page-objects/LabelPO.js | 4 ++++ 3 files changed, 13 insertions(+) create mode 100644 demo-app/e2e/jest.setup.js diff --git a/demo-app/e2e/config.json b/demo-app/e2e/config.json index d7609f5..c4e5571 100644 --- a/demo-app/e2e/config.json +++ b/demo-app/e2e/config.json @@ -1,4 +1,5 @@ { + "setupFilesAfterEnv": ["/e2e/jest.setup.js"], "globalSetup": "detox/runners/jest/globalSetup", "globalTeardown": "detox/runners/jest/globalTeardown", "maxWorkers": 1, diff --git a/demo-app/e2e/jest.setup.js b/demo-app/e2e/jest.setup.js new file mode 100644 index 0000000..97e29df --- /dev/null +++ b/demo-app/e2e/jest.setup.js @@ -0,0 +1,8 @@ +// Attempt to re-run individual tests when they fail +const retries = 5; +console.log('=========================='); +console.log( + `Running Jest with retries: will retry failing tests ${retries} time(s).` +); +console.log('=========================='); +jest.retryTimes(retries); diff --git a/demo-app/e2e/page-objects/LabelPO.js b/demo-app/e2e/page-objects/LabelPO.js index d258e32..2711fec 100644 --- a/demo-app/e2e/page-objects/LabelPO.js +++ b/demo-app/e2e/page-objects/LabelPO.js @@ -1,9 +1,13 @@ /* eslint-disable @typescript-eslint/no-var-requires */ const { UIComponentPO } = require('./UIComponentPO'); +const { waitFor } = require('detox'); +const { TIMEOUT_IN_MS } = require('./Options'); + /* eslint-enable @typescript-eslint/no-var-requires */ class LabelPO extends UIComponentPO { async text() { + await waitFor(this.component()).toExist().withTimeout(TIMEOUT_IN_MS); const attributes = await this.getAttributes(); return attributes.text; }