我在我的功能文件中创建了以下场景:
Scenario Outline: User can navigate to expected url by selecting the associated link
Given Application configured for testing
And on the Test page screen
When the user selects link for <pageName> - <dataTestId>
Then the user navigates to the expected url: <urlPathName>
Examples:
| pageName | dataTestId | urlPathName |
| Test Page | passwordTestLink | passwordTest |
| Custom Test | customTestLink | customTest |
我为每个步骤创建了相应的测试定义。但是当我运行测试时,“何时”和“然后”步骤返回为“未定义”。即 Cucumber 找不到步骤。错误信息是:
?当用户选择自定义测试链接时 - customTestLink 不明确的。使用以下代码片段实现:这是未找到的步骤之一的示例: When('用户选择自定义测试的链接 - customTestLink', async function () { // 在这里编写代码,将上面的短语转化为具体的操作 返回“待处理”; });
When('the user selects link for {string} - {string}', async function( dataTestId:string) {
administrationPage = new AdministrationPage(fixture.page);
await administrationPage.clickLink(dataTestId);
})
我不确定为什么没有找到测试,但我认为这与两个字符串参数有关。我需要更改什么才能确保 Cucumber 找到步骤定义?
你的脚步
When the user selects link for <pageName> - <dataTestId>
与您的步骤定义不匹配。
When('the user selects link for {string} - {string}', async function( dataTestId:string) {
要匹配
{string}
,您的步骤应使用 qoutes。
When the user selects link for "<pageName>" - "<dataTestId>"
你的步骤定义应该有两个参数。黄瓜表达式中的每个参数都有一个。
When('the user selects link for {string} - {string}', async function(pageName:string, dataTestId:string) {