{"id":14968561,"url":"https://github.com/kanopi/shrubs","last_synced_at":"2025-10-26T02:31:11.634Z","repository":{"id":183972638,"uuid":"671097990","full_name":"kanopi/shrubs","owner":"kanopi","description":"Common support commands for Cypress when interacting with Drupal. Install using Packagist. Issue queue on Drupal.org.","archived":false,"fork":false,"pushed_at":"2025-01-30T13:44:40.000Z","size":101,"stargazers_count":4,"open_issues_count":2,"forks_count":0,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-01-30T14:33:08.474Z","etag":null,"topics":["cypress","do-not-archive","drupal","internal-tool"],"latest_commit_sha":null,"homepage":"https://www.drupal.org/project/shrubs","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kanopi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-26T14:31:17.000Z","updated_at":"2025-01-30T13:44:43.000Z","dependencies_parsed_at":"2023-11-29T20:25:15.333Z","dependency_job_id":"98f29206-97b1-4a11-a07a-9de3c70cd1f3","html_url":"https://github.com/kanopi/shrubs","commit_stats":{"total_commits":67,"total_committers":8,"mean_commits":8.375,"dds":0.6716417910447761,"last_synced_commit":"e8ff24012aa28be77644557dd55ca54908b6ff9c"},"previous_names":["kanopi/cypress_starter","kanopi/shrubs"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanopi%2Fshrubs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanopi%2Fshrubs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanopi%2Fshrubs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanopi%2Fshrubs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kanopi","download_url":"https://codeload.github.com/kanopi/shrubs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238247984,"owners_count":19440879,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cypress","do-not-archive","drupal","internal-tool"],"created_at":"2024-09-24T13:40:07.546Z","updated_at":"2025-10-26T02:31:11.623Z","avatar_url":"https://github.com/kanopi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![shrubs](https://github.com/kanopi/shrubs/assets/5177009/e0d0ed6e-7e08-43be-9c82-69119bb19ab5)\n\n# Shrubs (Drupal Cypress Support Commands)\n\nCommon support commands for Cypress when interacting with Drupal.\n\n*Table of Contents*\n* [Requirements](#requirements)\n* [Installation](#installation)\n* [Available Commands](#available-commands)\n* [Issues](#issues)\n* [Maintainers](#maintainers)\n\n## Requirements\n\n* Cypress installed on your local or CI.\n* @TODO Document how we have Cypress set up.\n\n## Installation\n\n### Install/update composer installers.\n\nAdd two entries in composer.json for an install-type and its path:\n\n```\n\"installer-types\": [\"cypress-support\"],\n\"installer-paths\": {\n // existing entries omitted...\n \"tests/cypress/cypress/support/{$name}\": [\n   \"type:cypress-support\"\n ]\n}\n```\n\n### Tell Cypress where to import the tests\n\nIn the `support` folder for where your Cypress tests are located, edit `commands.js` and add the\nfollowing:\n\n```\n// Import commands.js using ES2015 syntax:\nimport './shrubs/commands'\n```\n\n### Requiring Shrubs using Composer\n\nThe Shrubs repository is available via Packagist.\n\nOnce you have completed the steps above, run the following command:\n\n`composer require kanopi/shrubs`\n\n### Update your CI process to...\n@TODO (See what Paul did on Parks)\n\n## Available Commands\n\n### Drupal Cypress autocomplete\nWill select the first match from an autocomplete field.\n```\ncy.autocomplete('input[data-drupal-selector=\"edit-field-episode-show-0-target-id\"]', 'Term Name')\n```\n\n### Drupal Cypress ckEditor get\nGets the value of a ckeditor instance.\n```\ncy.ckeditorGet('#edit-body-wrapper').should('contain', 'hello world')\n```\n\n### Drupal Cypress ckEditor type\nSet the value of a ckeditor instance.\n```\ncy.ckeditorType('#field_body-wrapper', 'hello world');\n```\n\n### Drupal Cypress drush\nRuns Drush commands in multiple environments.\nWith the correct configuration it can target the following:\n* Docksal\n* Lando\n* DDEV\n* Pantheon\n* Tugboat\n\n```\ncy.drush('status');\n```\n\n#### Config examples\nSet these as environment variables or in your cypress.env.json\n**Docksal**\n```json\n{\n  \"DRUSH_IS_DOCKSAL\" : true\n}\n```\n**Lando**\n```json\n{\n  \"DRUSH_IS_LANDO\" : true\n}\n```\n**DDEV**\n```json\n{\n  \"DRUSH_IS_DDEV\" : true\n}\n```\n**Pantheon**\n\nIn the format of `PANTHEON_SITE_ID.ENVIRONMENT_ID`\n```json\n{\n  \"DRUSH_IS_PANTHEON\" : \"mysite.pr-123\"\n}\n```\n**Tugboat**\n* `DRUSH_IS_TUGBOAT` is your [Tugboat token](https://docs.tugboatqa.com/tugboat-cli/set-an-access-token/index.html)\n* `TUGBOAT_INSTANCE_ID` is the ID of the specific Tugboat instance that is targeted [$TUGBOAT_PREVIEW_ID](https://docs.tugboatqa.com/reference/environment-variables/index.html#image-specific-variables)\n```json\n{\n  \"DRUSH_IS_TUGBOAT\" : \"12345abcdef\",\n  \"TUGBOAT_INSTANCE_ID\" : \"1234567890\"\n}\n```\n##### Tugboat CLI\n\nThe Tugboat CLI needs a little extra help being installed in AMD64 architecture. For example if you are install the CLI within a CI/CD system like CircleCI or GitHub Actions.\n\n```bash\nsudo dpkg --add-architecture amd64\nsudo apt-get update\nsudo apt-get install libc6:amd64 libstdc++6:amd64\nwget https://dashboard.tugboatqa.com/cli/linux/tugboat.tar.gz\nsudo tar -zxf tugboat.tar.gz -C /usr/local/bin/\n```\n\n### Drupal Cypress login\nLogin through the default Drupal login form.\nSets a default login but also passing custom login details\n\n```\ncy.login(); // login as a default user.\ncy.login('user', 'password'); // as a specific user\n```\n\nAssuming there is some other process to create the user.\n\n### Drupal Cypress login as a specific user\nUses a Drush one time login links to login as a specific user.\n```\ncy.loginOneTimeLink('myusername');\n```\n\n### Drupal Cypress logout\nLogs out of the current session\n```\ncy.logout();\n```\n\n### Ajax Click\n\nThere a clicks that can generate a blocking ajax request. I.E. Opening modals or\nslideouts that load content with an ajax request.\n\nThe function will wrap an intercept/wait combination around the click to make\nsure the tests don't continue until the ajax request as completed.\n\nIt's also meant to deal with the anti-pattern of using [wait()](https://docs.cypress.io/guides/references/best-practices#Unnecessary-Waiting) for clicks that trigger ajax requests.\n\n**Example**\n```\ncy.ajaxClick(\"a.product-name\", '/jsonapi/*/**')\n```\n\nThis replaces code that would look like this.\n\n```\nconst jsonApiRequest5 = 'jsonApiRequest' + Math.random();\ncy.intercept('GET', '/jsonapi/*/**').as(jsonApiRequest5)\ncy.get('a.product-name').click();\ncy.wait('@' + jsonApiRequest5).its('response.statusCode').should('eq', 200)\n```\nor\n```\ncy.get('a.product-name').click();\ncy.wait(5000)\n```\n\n### Drupal Cypress add item to media library\nUploads a file to the media library and selects it in the field.\n\nCan optionally set the type of media uploaded if there is more than one type available.\n\nFiles are expected to be in the `fixtures` folder at the same level as `support` and\n`e2e`.  In most cases, that will be `/tests/cypress/cypress/fixtures`.\n```\ncy.mediaLibraryAdd('#field_media_assets-media-library-wrapper', 'sample.png');\ncy.mediaLibraryAdd('#field_media_assets-media-library-wrapper', 'sample.mp3', 'audio');\n```\n\n### Drupal Cypress select item in the media library\nOpen a media browser modal and selects an existing media item\n\nCan optionally set the type of media uploaded if there is more than one type available.\n\nFiles are expected to be in the `fixtures` folder.\n\n```\ncy.mediaLibrarySelect('#field_media_assets-media-library-wrapper', 'sample.png');\ncy.mediaLibrarySelect('#field_media_assets-media-library-wrapper', 'sample.png', 'image');\n```\n\n### Drupal Cypress upload file\nUpload a file through a file field\nFiles should be in the `fixtures` folder.\n```\ncy.uploadFile('#file-field-wrapper', 'example.png');`\n```\n\n### logAndStore(message)\nLogs a message and stores it in an internal array to be retrieved later using\n`cy.logSummary();`\n\n```\ncy.logAndStore('This is a log message.');\n```\n\n### logSummary()\n\nOutputs all stored log messages at the end of a test run.\n\n```\ncy.logSummary();\n```\n\nExample with after() Hook\n```\ndescribe('Example Test with log summary', () =\u003e {\n  beforeEach(() =\u003e {\n    cy.visit('/example-page');\n  });\n\n  it('should log multiple steps', () =\u003e {\n    cy.logAndStore('Step 1: Visiting the page.');\n    cy.logAndStore('Step 2: Clicking a button.');\n    cy.logAndStore('Step 3: Validating output.');\n  });\n\n  after(() =\u003e {\n    cy.logSummary();\n  });\n});\n```\n\n## Pantheon interstitial page and Cypress tests\n\nIn May 2025 [Pantheon added an Interstitial page](https://docs.pantheon.io/release-notes/2025/05/interstitial-pages) to projects that are at the Sandbox level.  Kanopi has the following work around of overwriting the `visit()` command.\n\nIn `e2e.js`\n```js\n/**\n * Overwrite the visit() command to support setting headers globally.\n */\nCypress.Commands.overwrite(\"visit\", (originalVisit, url, options = {}) =\u003e {\n  const globalHeaders = Cypress.env('visitHeaders') || {};\n\n  // Combine global and specific headers from the unique call of visit().\n  const headers = Object.assign({}, globalHeaders, options.headers);\n\n  // Call the real visit with the merged headers\n  return originalVisit(url, { ...options, headers });\n});\n```\nIn your `cypress.config.js` you can add the following environment variable.\n```js\nenv: {\n  \"visitHeaders\" : {\n    \"Deterrence-Bypass\" : \"1\"\n  }\n}\n```\nNow when the `visit()` command is done you dont have to worry about a cookie being set prior.\n\nIf you want to set the cookie to bypass the page later you can do so with.\n```js\ncy.setCookie(\"Deterrence-Bypass\", \"1\");\n```\n\n\n## Issues\nFor issues and support, please use the issue queue at https://www.drupal.org/project/issues/shrubs?categories=All\n\n## Maintainers\n\nCurrent maintainers:\n * [thejimbirch](https://www.drupal.org/u/thejimbirch)\n * [paulsheldrake](https://www.drupal.org/u/paulsheldrake)\n\nThis project is sponsored by:\n * [Kanopi studios](https://www.drupal.org/kanopi-studios)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanopi%2Fshrubs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkanopi%2Fshrubs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanopi%2Fshrubs/lists"}