2

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).

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.

djangofan
  • 28,471
  • 61
  • 196
  • 289

1 Answers1

1

You can't.

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

The summary:

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.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248