如何在空手道测试中定义自己的StepActions类? [英] How do I define my own StepActions class in a Karate test?

查看:90
本文介绍了如何在空手道测试中定义自己的StepActions类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在空手道测试中定义自己的StepActions类?

How do I define my own StepActions class in a Karate test?

我所需要的只是一个工作示例(显然没有人在任何地方都可以找到这个示例;我看了却找不到任何东西,所以我在这里问).

All I need is one working example (apparently nobody has an example of this anywhere; I looked and couldn't find anything and so I am asking here).

例如,如何在Java中实现此辅助步骤操作?在这种情况下,如何从Java上下文中访问WebDriver driver实例?那么,如何称呼嵌入?

For example, how would I implement this helper step action in Java? In this case, how do I get access to the WebDriver driver instance from within Java context? Then, how do I call the embed?

@Slf4j
public class SeleniumStepActions extends StepActions {
    public SeleniumStepActions(FeatureContext featureContext, CallContext callContext, Scenario scenario, LogAppender appender) {
        super(featureContext, callContext, scenario, appender);
    }
    @When("^screenshot$")
    public void takeAScreenShot()
    {
        // goals is to simulate this in a karate js test
        //    * def bytes = driver.screenshot()
        //    * karate.embed(bytes, 'image/png')
        log.info("Testing my own custom action.");
    }
}

以上内容可能无法正常工作.我只是想让认识的人指出正确的方向.我希望在空手道演示中有这样的例子.

It is possible the above won't work. I am just looking to be pointed in the right direction by someone who knows. I wish there was such an example in the karate demo.

推荐答案

您不能.这就是为什么没有任何演示:P

You can't. Which is why there ain't any demo :P

有关详细讨论,请阅读以下主题: https://github.com/intuit /karate/issues/398

For a detailed discussion, please read this thread: https://github.com/intuit/karate/issues/398

摘要:

  • Karate does not support the "Step Definitions" that Cucumber does
  • There are 2 ways to inject custom logic, a) JS, b) Java interop
  • These are more than sufficient to implement something close to custom "keywords" - see this example: https://twitter.com/KarateDSL/status/1128170638223364097
  • and another: https://twitter.com/KarateDSL/status/1144458169822806016

如果您坚持让测试读起来像普通英语"(恕我直言不值得)-那么空手道可能不是您团队的最佳选择.

If you insist on making your test read like "plain english" (which IMHO is not worth it) - then Karate may not be the best choice for your team.

这篇关于如何在空手道测试中定义自己的StepActions类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆