【问题标题】:Karate - How to use karate-config.js variables in java file?空手道 - 如何在 java 文件中使用 karate-config.js 变量?
【发布时间】:2019-06-16 16:15:37
【问题描述】:

我有一个 DB utils java 文件,我需要根据运行代码的环境加载 DB 用户名密码,并且我需要从 karate-config.js 导入这些环境值。如何做到这一点?

【问题讨论】:

    标签: karate


    【解决方案1】:

    只需使用嵌入式表达式!因此,如果您在karate-config.js 中设置了dbusernamedbpassword

    * def config = { username: '#(dbusername)', password: '#(dbpassword)', url: 'jdbc:h2:mem:testdb', driverClassName: 'org.h2.Driver' }
    * def DbUtils = Java.type('com.mycompany.DbUtils')
    * def db = new DbUtils(config)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-19
      • 2020-01-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多