簡體   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