This page contains instructions to add Nightwatch tests to your Code Studio pipeline and ensure that your Drupal projects are tested efficiently.
Visit the following before you add Nightwatch tests to your pipeline:
tests/src/Nightwatch/Tests
createDrupalLoginScreen.js
in the Tests
directory.Update the file with the following:
module.exports = {
'@tags': ['myproject'],
before(browser) {
browser.globals.drupalSitePath = 'sites/default';
},
'Test login screen': (browser) => {
browser
.url(`${process.env.DRUPAL_TEST_BASE_URL}/user/login`)
.waitForElementVisible('body', 1000)
.assert.visible('input[name="name"]', 'Login input field is visible')
.assert.visible('input[name="pass"]', 'Password input field is visible')
.assert.visible('input#edit-submit', 'Submit button is visible');
},
};
tests/Drupal/Nightwatch
nightwatch.conf.js
in the Nightwatch directory.Update the file with the following:
const collectedFolders = {
Tests: ["./src/Nightwatch/Tests"],
Commands: [],
Assertions: [],
Pages: [],
};
module.exports = {
src_folders: collectedFolders.Tests,
output_folder: process.env.DRUPAL_NIGHTWATCH_OUTPUT,
custom_commands_path: collectedFolders.Commands,
custom_assertions_path: collectedFolders.Assertions,
page_objects_path: collectedFolders.Pages,
webdriver: {
start_process: true,
server_path: "./node_modules/.bin/chromedriver",
port: 9515
},
test_settings: {
default: {
default_path_prefix: process.env.DRUPAL_TEST_WEBDRIVER_PATH_PREFIX || '',
desiredCapabilities: {
browserName: "chrome",
chromeOptions: {
args: ["--headless", "--no-sandbox", "--disable-gpu"]
}
}
}
}
};
.env.example
in your /tests
directory.Update the file with the following contents:
DRUPAL_TEST_BASE_URL=http://127.0.0.1:8888
DRUPAL_TEST_DB_URL=mysql://drupal:[email protected]/drupal
DRUPAL_TEST_WEBDRIVER_HOSTNAME=localhost
DRUPAL_TEST_WEBDRIVER_PORT=9515
DRUPAL_TEST_CHROMEDRIVER_AUTOSTART=true
DRUPAL_NIGHTWATCH_OUTPUT=reports/nightwatch
Use the .gitignore
file that is located in the Drupal repository.
Ensure that your .yarnrc.yml
file in the tests
directory contains the following:
nodeLinker: node-modules
package.json
file in the tests
directory, use the file that is located in the Drupal repository. Modify it according to your requirements.Update your package.json
file with the following:
"scripts": {
"test:nightwatch": "node -r dotenv-safe/config ./node_modules/.bin/nightwatch --config ./Drupal/Nightwatch/nightwatch.conf.js"
},
"dependencies": {
"chromedriver": "^133.0.3"
}
Add the following job in the .gitlab-ci.yml
file:
"Nightwatch Test":
extends: "Test Drupal"
variables:
ACQUIA_TASKS_SETUP_DRUPAL: "true"
ACQUIA_TASKS_SETUP_DRUPAL_STRATEGY: "install"
ACQUIA_TASKS_SETUP_DRUPAL_PROFILE: "minimal"
ACQUIA_TASKS_SETUP_DRUPAL_CONFIG_IMPORT: "false"
before_script:
- eval $YARN_PACKAGE
- eval $YARN_PATH
stage: "Test Drupal"
script:
- !reference [.clone_standard_template, script]
- . "$STANDARD_TEMPLATE_PATH"/ci-files/scripts/utility/setup_prereqs.sh
- . "$STANDARD_TEMPLATE_PATH"/ci-files/scripts/utility/config_ssh.sh
- . "$STANDARD_TEMPLATE_PATH"/ci-files/scripts/utility/composer_install.sh
- . "$STANDARD_TEMPLATE_PATH"/ci-files/scripts/utility/install_drupal.sh
- $CI_PROJECT_DIR/vendor/bin/drush runserver 127.0.0.1:8888 &
- cd tests
- cp .env.example .env
- yarn install
- yarn run test:nightwatch
allow_failure: true
artifacts:
when: always
paths:
- tests/reports/nightwatch/
expire_in: 7 days
Ensure that the following variables are set in your job:
ACQUIA_TASKS_SETUP_DRUPAL
must be set to true.ACQUIA_TASKS_SETUP_DRUPAL_CONFIG_IMPORT
can be true or false.ACQUIA_TASKS_SETUP_DRUPAL_STRATEGY
can be install or sync.ACQUIA_TASKS_SETUP_DRUPAL_PROFILE
can be minimal, standard, or other allowed values.If this content did not answer your questions, try searching or contacting our support team for further assistance.
Thu Mar 13 2025 12:16:11 GMT+0000 (Coordinated Universal Time)