|
| 1 | +# Coffee Machine |
| 2 | + |
| 3 | +This is an example repository with some Gherkin feature files. |
| 4 | + |
| 5 | +Imagine we have built a coffee machine for our office, with automated tests using Cucumber. |
| 6 | + |
| 7 | + |
| 8 | +## Expose on CucumberStudio |
| 9 | + |
| 10 | +You can use [CucumberStudio](https://cucumber.io/tools/cucumberstudio/) "BDD with Cucumber project" to expose the features of this repository and their execution: |
| 11 | + |
| 12 | +1. Display the feature files from this repository in CucumberStudio |
| 13 | + - Fork this repository in a place you own in your favorite git service |
| 14 | + - In CucumberStudio, create a new "BDD with Cucumber" project |
| 15 | + - Connect the repository you have forked |
| 16 | + - You now have your features nicely exposed on CucumberStudio |
| 17 | + |
| 18 | + Congrats! 🎉 |
| 19 | + |
| 20 | +2. Push execution results to CucumberStudio |
| 21 | + - Ensure you have nodejs and npm installed |
| 22 | + - Run `npm install` to install the libraries (which includes [cucumber-js](https://github.com/cucumber/cucumber-js)) |
| 23 | + - Execute the feature files with Cucumber by running `node_modules/.bin/cucumber-js`. All test pass. |
| 24 | + |
| 25 | + - Generate results in a format that CucumberStudio understands |
| 26 | + |
| 27 | + When the features are executed the results must be stored in a file. This file must be in `message` format. Not `junit xml` or `json`. |
| 28 | + |
| 29 | + The command line option `--format=message:messages.ndjson` will output execution results in the `message` format, and store them in the file `messages.ndjson`. This is the final command to run: |
| 30 | + |
| 31 | + node_modules/.bin/cucumber-js --format=message:messages.ndjson |
| 32 | + |
| 33 | + Note: you can also run `npm run test` which does the same, as defined in `package.json`. |
| 34 | + |
| 35 | + - Push the results to CucumberStudio |
| 36 | + |
| 37 | + In CucumberStudio, in the settings there is the command line to use to push results. This command line looks something like this: |
| 38 | + |
| 39 | + curl -X POST \ |
| 40 | + https://studio.cucumber.io/cucumber_project/results \ |
| 41 | + -F messages=@<path to your result file> \ |
| 42 | + -H "project-access-token: <your-project-access-token>" \ |
| 43 | + -H "provider: github" \ |
| 44 | + -H "repo: <repository_name>" \ |
| 45 | + -H "branch: main" \ |
| 46 | + -H "revision: <commit_hash>" |
| 47 | + |
| 48 | + This command is defined in `package.json` as a script. Run `npm run push-results` to run it. You will need to define some environment variables to properly fill in the necessary information: |
| 49 | + - `PROJECT_ACCESS_TOKEN`: the unique access token relative to your project |
| 50 | + - `REPOSITORY_NAME`: the repository name, like `cucumber/coffee-machine-javascript` |
| 51 | + - `COMMIT_HASH`: the git commit hash referring the version actually tested |
| 52 | + |
| 53 | + Command is: |
| 54 | + |
| 55 | + export PROJECT_ACCESS_TOKEN=abcd1234 |
| 56 | + export REPOSITORY_NAME=yourGitHubName/coffee-machine-javascript |
| 57 | + export COMMIT_HASH=$(git rev-parse HEAD) |
| 58 | + npm run push-results |
| 59 | + |
| 60 | + - You should see the results being displayed in CucumberStudio. |
| 61 | + |
| 62 | + Congrats! 🎉 |
0 commit comments