在Karate框架的RunnerTest.jave中编写Java脚本通用功能 [英] Writing java script common function in RunnerTest.jave in Karate framework

查看:109
本文介绍了在Karate框架的RunnerTest.jave中编写Java脚本通用功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Karate框架,并创建了多个功能文件.

I am working on Karate framework and have created multiple feature files.

每个功能中都有通用的Java脚本功能 此功能将指定的数据插入到Influx DB中

In each feature there is common java script function This function insert the specified data to influx DB

我的功能文件看起来像这样

My feature file looks something like this

    #####################################################
          @API Name
    Feature: API test

    #####################################################################################
            Background:
        * def DbUtils 
      * def config 
        * def db 

        * def 
        * def db
        * configure afterScenario = 
java script function to insert code to DB    
"""
    function(){
      var info = karate.info; 
      karate.log('after', );
      karate.log('after', );
      karate.log('after', );
      karate.log('after', );
      karate.log('after', );
      var featurenameupdate = info.featureFileName.substring();

      var status="Fail";
      if(!info.errorMessage == null){
        status="Pass";
      }
      dbCDB.DBConnection( );
      dbCDB.DBwrite(  );
      dbCDB.connectionClose();
    }
    """

    Scenario Outline: <scenarioNm>
    * def req = read('')

    * set req.param.param.id = 
    * set req.param.param.param = 


    #Building the authentication request, storing cookie and response validation

    Given url <<URL>>
    And request req
    When method method
    Then status status code
    Then match response.error
    <<error response>>      

有可能吗?如何做到这一点?

Is it possible? How can this be achieve?

推荐答案

这正是我建议使用Java interop的一种用例.请编写一个可以执行此设置的自定义Java实用程序,它也将更加易于维护和调试.然后,您可以从任何地方轻松调用它.

This is exactly the kind of use-case where I recommend using Java interop. Please write a custom Java utility that can perform this setup and it will be much easier to maintain and debug also. Then you can easily call it from anywhere.

请参阅文档: https://github.com/intuit/karate#calling- Java

此特定示例使用JDBC: dogs.feature

This specifc example uses JDBC: dogs.feature

这篇关于在Karate框架的RunnerTest.jave中编写Java脚本通用功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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