-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add tests and improve docs for cypress-cucumber-preprocessor (#…
…175) * chore: add tests and improve docs for cypress-cucumber-preprocessor * use node 18 * try install with --concurrency 1
- Loading branch information
Showing
7 changed files
with
201 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
describe(`cucumber folder`, () => { | ||
beforeEach(() => { | ||
cy.visit(`examples/cucumber/cypress/reports/html/index.html`); | ||
}); | ||
|
||
it('Validate all tests exists', () => { | ||
cy.get('li[title="Suites"]').contains(1); | ||
cy.get('li[title="Tests"]').contains(5); | ||
cy.get('li[title="Passed"]').contains(4); | ||
cy.get('li[title="Failed"]').contains(1); | ||
}); | ||
|
||
it('screenshot exist for failed test', () => { | ||
// 2 retries | ||
cy.validateTestHasScreenshot('fail', 2); | ||
}); | ||
|
||
it('video exist for tests', () => { | ||
cy.validateTestHasVideo('pass'); | ||
cy.validateTestHasVideo('fail'); | ||
cy.validateTestHasVideo('pass with examples (example #1)'); | ||
cy.validateTestHasVideo('pass with examples (example #2)'); | ||
cy.validateTestHasVideo('pass with examples (example #3)'); | ||
}); | ||
|
||
describe('Validate test code text', () => { | ||
it('pass', () => { | ||
cy.validateTestCode( | ||
'pass', | ||
` | ||
Feature: Test 1 | ||
Scenario: pass | ||
When I visit "site/index.html" | ||
Then The list has 4 items | ||
` | ||
); | ||
}); | ||
|
||
it('fail', () => { | ||
cy.validateTestCode( | ||
'fail', | ||
` | ||
Feature: Test 1 | ||
Scenario: fail | ||
When I visit "site/index.html" | ||
Then The list has 5 items | ||
` | ||
); | ||
}); | ||
|
||
it('pass with examples (example #1)', () => { | ||
cy.validateTestCode( | ||
'pass with examples (example #1)', | ||
` | ||
Feature: Test 1 | ||
Scenario Outline: pass with examples | ||
When I visit "site/index.html" | ||
Then The list has more than <num> items | ||
Examples: | ||
| num | | ||
| 1 | | ||
` | ||
); | ||
}); | ||
|
||
it('pass with examples (example #2)', () => { | ||
cy.validateTestCode( | ||
'pass with examples (example #2)', | ||
` | ||
Feature: Test 1 | ||
Scenario Outline: pass with examples | ||
When I visit "site/index.html" | ||
Then The list has more than <num> items | ||
Examples: | ||
| num | | ||
| 2 | | ||
` | ||
); | ||
}); | ||
|
||
it('pass with examples (example #3)', () => { | ||
cy.validateTestCode( | ||
'pass with examples (example #3)', | ||
` | ||
Feature: Test 1 | ||
Scenario Outline: pass with examples | ||
When I visit "site/index.html" | ||
Then The list has more than <num> items | ||
Examples: | ||
| num | | ||
| 3 | | ||
` | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Setup with `cypress-cucumber-preprocessor` | ||
|
||
> ⚠️ `@badeball/cypress-cucumber-preprocessor` require node >= 18 | ||
1. Follow the steps in the [main README](../../README.md) to setup the reporter. | ||
|
||
1. Your `cypress.config.js` file should look like: | ||
|
||
```js | ||
const { defineConfig } = require('cypress'); | ||
const cypressOnFix = require('cypress-on-fix'); | ||
const createBundler = require('@bahmutov/cypress-esbuild-preprocessor'); | ||
const { addCucumberPreprocessorPlugin } = require('@badeball/cypress-cucumber-preprocessor'); | ||
const { createEsbuildPlugin } = require('@badeball/cypress-cucumber-preprocessor/esbuild'); | ||
|
||
module.exports = defineConfig({ | ||
reporter: 'cypress-mochawesome-reporter', | ||
video: true, | ||
retries: 1, | ||
e2e: { | ||
specPattern: 'cypress/e2e/**/*.feature', | ||
async setupNodeEvents(on, config) { | ||
// "cypress-on-fix" is required because "cypress-mochawesome-reporter" and "cypress-cucumber-preprocessor" use the same hooks | ||
on = cypressOnFix(on); | ||
|
||
require('cypress-mochawesome-reporter/plugin')(on); | ||
|
||
await addCucumberPreprocessorPlugin(on, config); | ||
|
||
on( | ||
'file:preprocessor', | ||
createBundler({ | ||
plugins: [createEsbuildPlugin(config)], | ||
}) | ||
); | ||
|
||
return config; | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
1. Add to `cypress/support/step_definitions/index.js` | ||
|
||
```js | ||
import 'cypress-mochawesome-reporter/cucumberSupport'; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters