In the Karate DSL Framework, how can we add custom step definitions to expand its functionalities beyond REST capabilities?

允我心安 提交于 2019-11-30 20:09:51

问题


I understand the philosophy behind Karate is to not have to add custom Step definitions. However, the REST API Testing we perform in our project is more integrated so we have to verify POST responses in MongoDB collections, ActiveMQ, and a SQL Server DB. Is there anyway to easily add custom step definitions to expand the Karate DSL Framework beyond its REST Capabilities? I tried downloading the source code and importing it as a Maven project but I came across many dependency issues.


回答1:


It is very easy to extend Karate via Java Interop. The best way to understand this, is to look at this demo example which uses JDBC to call a database: dogs.feature.

It is worth calling out here that if you return a Map (or List of Maps) from Java - you are back in JSON-land within Karate, and you can use match and all the other data-driven goodness of Karate.

Yes, it is that easy - and you don't have the un-necessary overhead of Step Definitions and dependency injection.

Hope this makes it clear as to why you don't need step definitions at all !



来源:https://stackoverflow.com/questions/46225745/in-the-karate-dsl-framework-how-can-we-add-custom-step-definitions-to-expand-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!