繁体   English   中英

任何示例都有一个 java class 实例调用一次并在具有不同特征文件的空手道的所有场景中使用

[英]Any example to have a java class instance to call once and use in all scenarios in karate with different feature files

我一直在使用来自空手道演示的 DBUtils class,我知道这个 class 与空手道无关。 我有一个问题,例如给出的示例有 DBUtlis class 在每个场景的后台调用,并且应该在所有功能文件背景中提及:。

像我们配置一次并在所有场景中使用该数据库实例变量的任何东西? 如果是,请举例。

彼得在以下评论后更新:

配置: 在此处输入图像描述

主要功能文件: 在此处输入图像描述

在另一个功能文件中重用数据库实例

在此处输入图像描述

请确认这是否是正确的方法?

字符串试运行:

var result = karate.callSingle('classpath:featureFiles/dbBackground.feature', config);

  config.PersonName = result.name;

主要特征:

Feature: DB Background

Background:
    * def name = "Sandeep";

其他特点:

Feature: Get Account Details

Background:

    * def actualname = PersonName;

@golden
Scenario: user 1 details
 * def expectedFormat = read('../requestFiles/format.json')

        Given url 'https://reqres.in/api/users'
        And params ({id: '1'})
        When method Get
        Then match response.data.email == "george.bluth@reqres.in"
        Then print '###################################name is: ', actualname
        Then print '###################################name is: ', PersonName

看到 null 的控制台结果:

在此处输入图像描述

更新试运行 2:

Feature: DB Background

Background:

    * def name = "Sandeep";

    @golden
Scenario: user sample details
 * def expectedFormat = read('../requestFiles/format.json')

        Given url 'https://reqres.in/api/users'
        And params ({id: '1'})
        When method Get
        Then match response.data.email == "george.bluth@reqres.in"

output:

19:31:33.416 [ForkJoinPool-1-worker-0] DEBUG com.jayway.jsonpath.internal.path.CompiledPath - Evaluating path: $['data']['email']
19:31:33.416 [ForkJoinPool-1-worker-0] INFO com.intuit.karate - [print] ###################################name is:  Sandeep
19:31:33.432 [ForkJoinPool-1-worker-0] INFO com.intuit.karate - [print] ###################################name is:  Sandeep

是的,您可以在karate-config.js中对其进行初始化,然后它将成为一个全局变量。

另请查看karate.callSingle()https://github.com/intuit/karate#hooks

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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