如何在后台调用SQL脚本或查询空手道功能? [英] how to call a sql script or query in background for a Karate feature?

查看:54
本文介绍了如何在后台调用SQL脚本或查询空手道功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有空手道功能,并且操作很长.在运行这些测试之前,我需要手动设置一些测试数据,这实际上是一个sql查询.有没有一种方法可以让我们在空手道中的背景"中运行此查询? 我正在尝试将状态中不是"ready_to_test"的所有值更新为"ready_to_test".

I have Karate feature with a long list of operations. I need to manually have some test data setup before running these tests which is essentially one sql query. Is there a way we can have this query run in "background" in Karate? I'm trying to update all the values in status which aren't "ready_to_test" to "ready_to_test".

说我的查询是
更新my_table 设置状态="ready_to_test" 状态为!='ready_to_test';

Say my query is
update my_table set status = 'ready_to_test' where status != 'ready_to_test';

我正在尝试按以下方式运行更新查询

I am trying to run the update query as follows

* def config = {username: 'postgres', password: 'postgres', url: 'jdbc:postgresql://localhost:5432/postgres', driverClassName: 'org.postgresql.Driver'}
* def DbUtil = Java.type('com.utils.DbUtils')
* def db = new DbUtil(config)
* def correctStatus = 'ready_to_test'
* def testData = db.cleanRows('UPDATE MY_TABLE M SET M.STATUS = ' 'WHERE M.STATUS != ' + correctStatus)

也尝试过 * def testData = db.cleanRows('UPDATE MY_TABLE SET STATUS ='ready_to_test'WHERE STATUS!='ready_to_test)

Also tried * def testData = db.cleanRows('UPDATE MY_TABLE SET STATUS = 'ready_to_test' WHERE STATUS != 'ready_to_test)

推荐答案

请查看callSingle API是否满足您的需求.

Please see if the callSingle API solves your need.

https://github.com/intuit/karate#karate-callsingle

var result = karate.callSingle('classpath:common.feature', { some: 'config' });

另请参阅钩子: https://github.com/intuit/karate#hooks

这篇关于如何在后台调用SQL脚本或查询空手道功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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