如何在后台调用 sql 脚本或查询空手道功能?
how to call a sql script or query in background for a Karate feature?
我有空手道功能和一长串操作。我需要在 运行 进行这些测试之前手动设置一些测试数据,这实际上是一个 sql 查询。有没有一种方法可以让我们在 Karate 的 "background" 中使用此查询 运行?
我正在尝试将状态中所有不是 "ready_to_test" 的值更新为 "ready_to_test".
假设我的查询是
更新 my_table
设置状态 = 'ready_to_test'
其中 status != 'ready_to_test';
编辑:
我正在尝试 运行 更新查询如下
使用JDBC设置测试数据
* 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)
请查看 callSingle
API 是否满足您的需求。
https://github.com/intuit/karate#karate-callsingle
var result = karate.callSingle('classpath:common.feature', { some: 'config' });
我还想更新数据库中的特定行,我尝试将下面的函数添加到 DbUtils,然后使用它的功能文件,它有效。
public void insertRows(final String sql) {
System.out.println("Inserting data to database...");
jdbc.batchUpdate(new String[]{sql});
}
更多信息可以观看this video
我有空手道功能和一长串操作。我需要在 运行 进行这些测试之前手动设置一些测试数据,这实际上是一个 sql 查询。有没有一种方法可以让我们在 Karate 的 "background" 中使用此查询 运行? 我正在尝试将状态中所有不是 "ready_to_test" 的值更新为 "ready_to_test".
假设我的查询是
更新 my_table
设置状态 = 'ready_to_test'
其中 status != 'ready_to_test';
编辑: 我正在尝试 运行 更新查询如下
使用JDBC设置测试数据
* 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)
请查看 callSingle
API 是否满足您的需求。
https://github.com/intuit/karate#karate-callsingle
var result = karate.callSingle('classpath:common.feature', { some: 'config' });
我还想更新数据库中的特定行,我尝试将下面的函数添加到 DbUtils,然后使用它的功能文件,它有效。
public void insertRows(final String sql) {
System.out.println("Inserting data to database...");
jdbc.batchUpdate(new String[]{sql});
}
更多信息可以观看this video