cbliard / coffee-machine-javascript

CucumberStudio sample project in JavaScript for the "BDD with Cucumber" project type
0 stars 1 forks source link

Coffee Machine

This is an example repository with some Gherkin feature files.

Imagine we have built a coffee machine for our office, with automated tests using Cucumber.

Expose on CucumberStudio

You can use CucumberStudio "BDD with Cucumber project" to expose the features of this repository and their execution:

  1. Display the feature files from this repository in CucumberStudio

    • Fork this repository in a place you own in your favorite git service
    • In CucumberStudio, create a new "BDD with Cucumber" project
    • Connect the repository you have forked
    • You now have your features nicely exposed on CucumberStudio

    Congrats! πŸŽ‰

  2. Push execution results to CucumberStudio

    • Ensure you have nodejs and npm installed

    • Run npm install to install the libraries (which includes cucumber-js)

    • Execute the feature files with Cucumber by running node_modules/.bin/cucumber-js. All test pass.

    • Generate results in a format that CucumberStudio understands

      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.

      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:

      node_modules/.bin/cucumber-js --format=message:messages.ndjson

      Note: you can also run npm run test which does the same, as defined in package.json.

    • Push the results to CucumberStudio

      In CucumberStudio, in the settings there is the command line to use to push results. This command line looks something like this:

      curl -X POST \ https://studio.cucumber.io/cucumber_project/results \ -F messages=@ \ -H "project-access-token: " \ -H "provider: github" \ -H "repo: " \ -H "branch: " \ -H "revision: "

      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:

      • CS_PROJECT_ACCESS_TOKEN: the unique access token relative to your project
      • REPOSITORY_NAME: the repository name, like cucumber/coffee-machine-javascript
      • COMMIT_SHA: the git commit hash referring the version actually tested
      • COMMIT_BRANCH: the git commit branch referring the version actually tested

      Command is:

      export CS_PROJECT_ACCESS_TOKEN=abcd1234 export REPOSITORY_NAME=yourGitHubName/coffee-machine-javascript export COMMIT_SHA=$(git rev-parse HEAD) export COMMIT_BRANCH=$(git rev-parse --abbrev-ref $COMMIT_SHA) npm run push-results

      Note: you can also run npm run push-results which does the same, as defined in package.json.

    • You should see the results being displayed in CucumberStudio.

      Congrats! πŸŽ‰