简体   繁体   中英

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

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM