kanopi / shrubs
一组默认支持命令,帮助您快速配置Cypress以支持Drupal。
Requires
README
Shrubs (Drupal Cypress 支持命令)
Cypress与Drupal交互时的常用支持命令。
目录
要求
- 在本地或CI上安装Cypress。
- @TODO 记录我们如何设置Cypress。
安装
安装/更新composer安装器。
在composer.json中添加两个条目,用于安装类型及其路径
"installer-types": ["cypress-support"],
"installer-paths": {
// existing entries omitted...
"tests/cypress/cypress/support/{$name}": [
"type:cypress-support"
]
}
告诉Cypress导入测试的位置
在存放Cypress测试的support
文件夹中,编辑commands.js
并添加以下内容
// Import commands.js using ES2015 syntax:
import './shrubs/commands'
使用Composer安装Shrubs
Shrubs仓库通过Packagist提供。
完成上述步骤后,运行以下命令
composer require kanopi/shrubs
更新您的CI过程...
@TODO (查看Paul在Parks上做了什么)
可用命令
Drupal Cypress 自动完成
将选择自动完成字段中的第一个匹配项。
cy.autocomplete('input[data-drupal-selector="edit-field-episode-show-0-target-id"]', 'Term Name')
Drupal Cypress ckEditor get
获取ckeditor实例的值。
cy.ckeditorGet('#edit-body-wrapper').should('contain', 'hello world')
Drupal Cypress ckEditor type
设置ckeditor实例的值。
cy.ckeditorType('#field_body-wrapper', 'hello world');
Drupal Cypress drush
在多个环境中运行Drush命令
也支持在Pantheon multidev环境中运行命令。
cy.drush('status');
Drupal Cypress 登录
设置默认登录,也可以传递自定义登录详情
cy.login(); // login as a default user.
cy.login('user', 'password'); // as a specific user
假设有其他过程来创建用户。
Drupal Cypress 登出
退出当前会话
cy.logout();
Ajax Click
有些点击会生成阻塞的ajax请求。例如:打开模态框或滑出式菜单,通过ajax请求加载内容。
该函数将在点击周围包裹拦截/等待组合,以确保测试在ajax请求完成后才继续。
它还旨在处理使用wait()的anti-pattern,以等待触发ajax请求的点击。
示例
cy.ajaxClick("a.product-name", '/jsonapi/*/**')
这会替换掉类似下面的代码。
const jsonApiRequest5 = 'jsonApiRequest' + Math.random();
cy.intercept('GET', '/jsonapi/*/**').as(jsonApiRequest5)
cy.get('a.product-name').click();
cy.wait('@' + jsonApiRequest5).its('response.statusCode').should('eq', 200)
或者
cy.get('a.product-name').click();
cy.wait(5000)
Drupal Cypress 将项目添加到媒体库
将文件上传到媒体库并在字段中选择它。
如果有多种类型可用,可以设置上传文件的类型。
文件应位于与support
和e2e
同一级别的fixtures
文件夹中。在大多数情况下,这将是/tests/cypress/cypress/fixtures
。
cy.mediaLibraryAdd('#field_media_assets-media-library-wrapper', 'sample.png');
cy.mediaLibraryAdd('#field_media_assets-media-library-wrapper', 'sample.mp3', 'audio');
Drupal Cypress 在媒体库中选择项目
打开媒体浏览器模态并选择现有的媒体项
如果有多种类型可用,可以设置上传文件的类型。
文件应位于fixtures
文件夹。
cy.mediaLibrarySelect('#field_media_assets-media-library-wrapper', 'sample.png');
cy.mediaLibrarySelect('#field_media_assets-media-library-wrapper', 'sample.png', 'image');
Drupal Cypress 上传文件
通过文件字段上传文件 文件应在fixtures
文件夹中。
cy.uploadFile('#file-field-wrapper', 'example.png');`
问题
有关问题和支持,请使用https://www.drupal.org/project/issues/shrubs?categories=All上的问题队列。
维护者
当前维护者
本项目由以下机构赞助