【问题标题】:How can the tags in cucumber hooks(@Before and @After) be organisedcucumber hooks(@Before and @After)中的标签如何组织
【发布时间】:2020-10-13 09:41:31
【问题描述】:

我有两个包含两种类型标签(填充和测试)的步骤定义

  1. 第一步 def - cars.ts 包含以下标签:@populate_cars1、@cars1、@populate_cars2、@cars2。
  2. 第二步 def - clients.ts 包含以下标签:@populate_clients1、@clients1、@populate_clients2、@clients2。

在钩子中我有以下定义:

-> Before("not @populate_cars1 and not @populate_cars2 and not @populate_clients1 and not @populate_clients2", function(){...}) - 按预期工作

-> After("not @cars1 and not @cars2 and not @clients1 and not @clients2", function(){...}) - 按预期工作。

我想组织如下标签: let pop_car = "not @populate_cars1 and not @populate_cars2" let pop_client = "and not @populate_clients1 and not @populate_clients2" @Before(pop_car + pop_client, function(){...})

我为每个步骤定义一个变量,其中包含标签之间的操作并将变量连接起来以获取字符串。

问题是当我连接变量“pop_car + pop_client”时 - 钩子 @Before 被调用

【问题讨论】:

  • 你能添加一个连接变量的例子吗?如果可能的话,终端日志显示@Before 被调用?
  • 变量在@Before 中连接,如上。另外,我尝试在调用@Before 之前连接变量并将字符串添加到@Before。 let pop_car = "not @populate_cars1 and not @populate_cars2" let pop_client = "and not @populate_clients1 and not @populate_clients2" Before("pop_car+pop_client", function () { console.log("init db before test") return populateDB('development', true) }) 在每次测试前我都看到了控制台日志。
  • 我不太明白这是什么问题?您正在调用 @Before 并调用钩子。我理解对了吗?
  • 是的。如果我输入 'Before("not @populate_cars1 而不是 @populate_cars2 而不是 @populate_clients1 而不是 @populate_clients2", function(){...})' - 它按预期工作。在这种情况下,@Before 有来自功能 Car 和 Clients 的 4 个标签。我想要@Before(_before),_before = tagsCar + tagsClient。在这种情况下,@Before 没有按预期工作。提前谢谢!
  • 试试Before("pop_car" + " " + "pop_client")。 (在它们之间添加一个空格)

标签: node.js cucumber gherkin cucumberjs


【解决方案1】:

您需要在连接的变量之间留一个空格。

尝试:

@Before("pop_car" + " " + "pop_client")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 2013-01-11
    • 1970-01-01
    • 2019-12-10
    • 1970-01-01
    相关资源
    最近更新 更多