Initialization of the steps library is triggered via the command:
npx cds-add-cucumber
It will perform the following operations:
- create cucumber configuration file ./cucumber.yml containing the following settings:
- require steps module
default: requireModule: - "@cap-js-community/cds-cucumber"
- create directory for feature specifications: ./test/features
- create directory for own steps: ./test/features/step_definitions
- optionally (in case the project matches the cds samples one) create first feature file: ./test/features/first.feature
- create configuration for cucumber plugin: ./.vscode/settings.json
{ "cucumberautocomplete.steps": [ "test/features/step_definitions/*.js", "node_modules/@cap-js-community/cds-cucumber/lib/steps/*.js" ], "cucumberautocomplete.strictGherkinCompletion": true }
- optionally (in case the project matches the cds samples one) create file with CDS annotations: ./srv/annotations.cds
In addition to the provided steps you can add your own steps in your repository. By default they should be located in the following folder:
test/features/step_definitions
Additional information about using local SAP UI5 build can be found here.
In order to get support (like code completion) for VSCode while writing your specifications, you can install one of the following plugins:
-
Cucumber for Visual Studio Code (CucumberOpen)
Default configuration in file:
.vscode/settings.json
{ "cucumber.features": [ "test/features/**/*.feature" ], "cucumber.glue": [ "test/features/step_definitions/**/*.js", "node_modules/@cap-js-community/cds-cucumber/lib/steps/*.js" ] }
-
Cucumber (Gherkin) Full Support
Default configuration in file:
.vscode/settings.json
{ "cucumberautocomplete.steps": [ "test/features/step_definitions/*.js", "node_modules/@cap-js-community/cds-cucumber/lib/steps/*.js" ], "cucumberautocomplete.strictGherkinCompletion": true }
Information can be found here.
Information can be found here.
The selenium-webdriver nodejs module is used to control the browser and it requires a webdriver. The version of the webdriver should match the version of the web browser. The node module chromedriver is used to download the latest webdriver version automatically. Both modules are listed in the dependencies of this module.
Most systems are configured to update the browser automatically which requires also an update of the webdriver. You can update the chrome webdriver to the latest version with the following command:
npm install chromedriver --chromedriver_version=LATEST
In cases where the browser is not installed or can not be started (CI), you can run selenium and the corresponding browser in docker as follows:
- start selenium docker container
docker run -d --network host selenium/standalone-chrome
By default the selenium/standalone-chrome image opens the port 4444 to access the webdriver.
- start the tests passing the selenium remote url as an environment variable:
SELENIUM_REMOTE_URL="http://127.0.0.1:4444/wd/hub" npx cucumber-js test
Server-side code-covarage is available using the native V8 code-coverage module c8 and it can be activated via the environment variable CDS_CUCUMBER_CODECOV.
- enable OData v2 plugin
npm add @cap-js-community/odata-v2-adapter
- use the appropriate step to require the OData v2 protocol:
Given we require communication protocol "odata-v2"
- alternatively set the environment variable CDS_CUCUMBER_COMMUNICATION_PROTOCOL
CDS_CUCUMBER_COMMUNICATION_PROTOCOL="odata-v2"
- configure the path of the CDS service using the CDS annotations in case it differs from the default
annotate AdminService with
@protocol: [
{ kind: 'odata-v2', path: '/odata/v2/admin' },
{ kind: 'odata-v4', path: '/odata/v4/admin' }
];