From dbd2beb07cd3487583003fce48ab925a19b6cda7 Mon Sep 17 00:00:00 2001 From: Priyansh Garg Date: Tue, 6 Aug 2024 23:56:56 +0530 Subject: [PATCH 1/4] Add cucumber.conf.js --- cucumber.conf.js | 9 +++++++++ nightwatch.conf.js | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 cucumber.conf.js diff --git a/cucumber.conf.js b/cucumber.conf.js new file mode 100644 index 0000000..e431dbf --- /dev/null +++ b/cucumber.conf.js @@ -0,0 +1,9 @@ +const {AfterStep} = require('@cucumber/cucumber'); + +AfterStep(async function(testStep) { + // take screenshot on failure after each step + if (testStep.result.status === 'FAILED' && this.browser) { + await this.browser.saveScreenshot('failure-screenshot.png'); + } +}); + diff --git a/nightwatch.conf.js b/nightwatch.conf.js index 070a208..6abea1f 100644 --- a/nightwatch.conf.js +++ b/nightwatch.conf.js @@ -32,7 +32,8 @@ module.exports = { options: { feature_path: 'tests/features/*.feature', additional_config: '', - parallel: 2 + parallel: 2, + require: ['./cucumber.conf.js'] } }, From 49a0bec5c0e90d37961cb92e0dd978350acf9cf6 Mon Sep 17 00:00:00 2001 From: Priyansh Garg Date: Wed, 7 Aug 2024 17:25:57 +0530 Subject: [PATCH 2/4] Fix test. --- tests/features/githubSearch.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/features/githubSearch.feature b/tests/features/githubSearch.feature index c4382bf..f5c9c10 100644 --- a/tests/features/githubSearch.feature +++ b/tests/features/githubSearch.feature @@ -6,7 +6,7 @@ Feature: Github test Scenario: open URL Given I open the url "https://github.com/" Then I expect the url to contain "github.com" - And I expect that the title is GitHub: Let’s build from here · GitHub" + And I expect that the title is "GitHub: Let’s build from here · GitHub" @githubSearch Scenario: search for nightwatch repository From 6b6dbcb39cfb71a8e79e72feeb57f23546c6b5ad Mon Sep 17 00:00:00 2001 From: Priyansh Garg Date: Wed, 7 Aug 2024 17:32:12 +0530 Subject: [PATCH 3/4] Disable duckduckgo test. --- .github/workflows/build-node.yaml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-node.yaml b/.github/workflows/build-node.yaml index 3c9407f..62cad34 100644 --- a/.github/workflows/build-node.yaml +++ b/.github/workflows/build-node.yaml @@ -22,4 +22,4 @@ jobs: node-version: ${{ matrix.node-version }} - run: npm ci - run: npm run eslint - - run: npm test -- --env chrome --headless + - run: npm test -- --env chrome --headless --tags "not @duckduckgo" diff --git a/package.json b/package.json index ed3dd9f..ba6575b 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "test" }, "scripts": { - "test": "nightwatch", + "test": "nightwatch --env chrome --tags 'not @duckduckgo'", "eslint": "eslint src/specs --quiet" }, "repository": { From 3f0337ea99523c542383514df042a5b55190963c Mon Sep 17 00:00:00 2001 From: Priyansh Garg Date: Wed, 7 Aug 2024 18:08:49 +0530 Subject: [PATCH 4/4] Refactor screenshot hook. --- cucumber.conf.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cucumber.conf.js b/cucumber.conf.js index e431dbf..1b47dc5 100644 --- a/cucumber.conf.js +++ b/cucumber.conf.js @@ -1,9 +1,13 @@ const {AfterStep} = require('@cucumber/cucumber'); -AfterStep(async function(testStep) { - // take screenshot on failure after each step - if (testStep.result.status === 'FAILED' && this.browser) { - await this.browser.saveScreenshot('failure-screenshot.png'); +AfterStep(async function(testCase) { + // take screenshot on test case failure. + // + // follow this Discord thread for integrating the screenshots into your Cucumber report: + // https://discord.com/channels/618399631038218240/1253341054921609306/1255939897047515250 + // + if (testCase.result.status === 'FAILED' && this.browser) { + await this.browser.saveScreenshot(`screenshots/${testCase.pickle.name}.png`); } });