Cypress 简明教程

Cypress - Plugins

Cypress 有多个插件可添加到其功能中。有多种类型的插件,例如身份验证、组件测试、自定义命令、开发工具等。

Cypress has multiple plugins to add to its features. There are multiple types of plugins like the authentication, component testing, custom commands, development tools and so on.

一些非常重要的插件包括 −

Some of the prominent plugins include −

要在 Cypress 中使用 perform file upload task ,我们必须首先使用下面提到的命令安装 install a plugin

To perform file upload task in Cypress, we have to first install a plugin with the command mentioned below −

npm install –dev cypress-file-upload

安装完成后,我们必须在 command.js 文件中添加语句 import 'cypress-file-upload',该文件位于 Cypress 项目中的 support 文件夹内。

Once the installation is done, we have to add the statement import 'cypress-file-upload' in the command.js file, which resides inside the support folder within the Cypress project.

要使用框架,首先,我们必须使用下面给出的命令安装 Cypress plugin for frames

To work with frames, first, we have to install the Cypress plugin for frames with the command given below −

npm install –D cypress-iframe

然后,我们必须在代码中添加语句 import 'cypress-iframe'。

Then, we have to add the statement import 'cypress-iframe' in the code.

identify elements with xpath locator ,运行以下命令 −

To identify elements with xpath locator, run the following command −

npm install cypress-xpath

安装完成后,我们必须在 index.js 文件中添加语句 require (“cypress-xpath”),该文件位于 Cypress 项目中的 support 文件夹内。

Once the installation is done, we have to add the statement require ("cypress-xpath") within the index.js file, which resides inside the support folder within the Cypress project.

此外,我们必须使用 cy.xpath 命令来识别元素。

Also, we have to use the cy.xpath command to identify elements.

enable themes ,我们必须使用下面提到的命令安装一个插件 −

To enable themes, we have to install a plugin with the command mentioned below −

npm install --save-dev cypress-dark

安装完成后,我们必须在 index.js 文件中添加语句 require ("cypress-dark”),该文件位于 Cypress 项目中的 support 文件夹内。

Once the installation is done, we have to add the statement require ("cypress-dark") within the index.js file, which resides inside the support folder within the Cypress project.