【问题标题】:How to define variables cucumber steps in groovy?如何在groovy中定义变量黄瓜步骤?
【发布时间】:2019-06-19 16:39:21
【问题描述】:

我不知道如何在 Katalon Studio 中使用变量制作 groovy 代码。 例如。我有一个步骤: 当我转到“示例站点”时

而且我希望这个“当我去”的定义方式是,如果我将任何链接放在功能文件中的引号中,它实际上会将我带到那里。

我告诉你我尝试了什么:

这是常规步骤定义:

    @When('I go to (.*)')
    def I_go_to() {
        WebUI.navigateToUrl('sample site')
    }

这是功能文件中 Cucumber 中的步骤:

     When I go to "sample site"

但是我得到的只是一个错误提示:

I go to "sample site" FAILED.
Reason:
cucumber.runtime.CucumberException: Step [I go to (.*)] is defined with 0 parameters at 'behat.StepDefinition.I_go_to() in file:/D:/Katalon/katalon-tests/katalon-tests/katalon-tests/bin/groovy/'.
However, the gherkin step has 1 arguments:
 * "sample"
Step text: I go to "/admin/structure/taxonomy/manage/category/overview"
    at cucumber.runtime.PickleStepDefinitionMatch.arityMismatch(PickleStepDefinitionMatch.java:84)
    at cucumber.runtime.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:34)

【问题讨论】:

    标签: variables groovy cucumber katalon-studio


    【解决方案1】:

    @When('I go to (.*)')
    def I_go_to() {
        WebUI.navigateToUrl('sample site')
    }
    

    您是在告诉 Cucumber 运行 I_go_to() 函数,该函数采用 无参数。该函数调用以'sample site' 作为参数的WebUI.navigateToUrl() 函数。

    您需要将此处的 (.*) 传递给您的 I_go_to() 函数。你可以试试这样的:

    @When('I go to (.*)')
    def I_go_to(String url) {
        WebUI.navigateToUrl(url)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-12
      • 1970-01-01
      • 1970-01-01
      • 2014-01-10
      相关资源
      最近更新 更多