简体   繁体   English

Cypress - 在 BeforeEach Hook 中调用自定义命令

[英]Cypress - Call custom command in BeforeEach Hook

Can anyone assist in following case: Wrote several custom commands and add them into beforeEach Hook.任何人都可以在以下情况下提供帮助:编写了几个自定义命令并将它们添加到 beforeEach Hook 中。 Only one has 3 variables in it, and can no call that function.只有一个有 3 个变量,并且不能调用该函数。 Can someone help to fix this, it looks like small issue, but not logical one to me.有人可以帮忙解决这个问题,这看起来是个小问题,但对我来说不合逻辑。

Imported commands into support/index.js (already for older functions/commands将命令导入 support/index.js(已用于较旧的函数/命令

So.所以。 command looks:命令看起来:

Cypress.Commands.add('mockChosenData', (partURL, mockFile, aliasName) => {
    cy.server();
    cy.route(partURL, mockFile).as(aliasName);
});

Calling command in test:在测试中调用命令:

cy.mockChosenData(
  'partURL_value',
  'fixture:file.json',
  'aliasName_Value',
);

And get this when run test in beforeEach hook:在 beforeEach 钩子中运行测试时得到这个:

在此处输入图片说明

Support/index.js file支持/index.js 文件

在此处输入图片说明

I believe that the issue is inside your support/commands.js file.我相信问题出在您的support/commands.js文件中。 Review it for typos and possible parsing errors.检查拼写错误和可能的解析错误。 Make sure you do not define commands inside of other commands by mistake.确保您没有错误地在其他命令中定义命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM