繁体   English   中英

带有黄瓜步骤和打字稿的开关盒

[英]Switch case with cucumber steps and typescript

我使用 WebdriverIO6、Typescript 4 和黄瓜。
我有这个场景:

Scenario: Login without password
And I enter valid email
But I do not enter password
Then I can see "Password is required" error message  

我有这一步:

Then(/^I can see (.*) error message$/, (type: string) => {
 const headerErrorMessage = loginPage.headerErrorMessage;
 const itemErrorMessage = loginPage.itemErrorMessage;

 switch (type) {
  case 'Authentication': {
   expect(headerErrorMessage.getText()).to.be.equal(errorMessages.headerErrorMessage);
   expect(itemErrorMessage.getText()).to.be.equal(errorMessages.authenticationFailedErrorMessage);
   break;
  }
  case 'Invalid email address': {
   expect(headerErrorMessage.getText()).to.be.equal(errorMessages.headerErrorMessage);
   expect(itemErrorMessage.getText()).to.be.equal(errorMessages.invalidEmailErrorMessage);
   break;
  }
  case 'Password is required': {
   expect(headerErrorMessage.getText()).to.be.equal(errorMessages.headerErrorMessage);
   expect(itemErrorMessage.getText()).to.be.equal(errorMessages.passwordRequiredErrorMessage);
   break;
  }
  default: {
  throw new TypeError('Unsupported type of error message');
  }
}
});  

而且开关不工作。 对于这种情况,它与case 'Password is required'不匹配。 它只是默认说它是Unsupported type of error message
有人知道为什么吗?
谢谢!
编辑
当我把这个Then(/^I can see "([^"]*)" error message$/, (type: string) => { (注意我有"([^"]*)"而不是(.*) ),然后它就可以工作了。
有好心人能解释一下吗?
有什么不同解释?
谢谢!

括号表示 Cucumber 捕获模式:(模式)。
.* 的正则表达式匹配任何字符(换行符除外)0 次或多次。

您可以在运行时检查“类型”参数的值吗? 您可能正在使用您的 switch case 不匹配的 Gherkin 行中的引号捕获“需要密码”。

暂无
暂无

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

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