我不确定如何链接测试用例,添加更多验证。 我在考虑如何链接以上两者,存储API响应以及成功完成此操作后的ID:productid,productinfo。
然后查询数据库详细信息,如果可能的话,将其存储(我已经创建了检查点,不确定这是否是正确的方法),然后从API响应中验证与数据库列值相同的值。
我有一组API消息(GET / POST)的对象存储库
然后使用2个关键字测试与数据库记录匹配的API响应
连接到API和POST以插入新产品
连接到数据库并获取表详细信息
我有一个单独的测试用例,用于测试API POST消息获得响应200并成功运行。另一个测试用例连接到数据库并查询表详细信息。
============ 1.添加产品关键字groovy脚本
package Product
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import groovy.json.JsonBuilder
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
public class API {
@Keyword
AddProduct() {
def result = WS.sendRequestAndVerify(findTestObject('AddProduct'))
return result
}
}
====================================== 2.数据库常规脚本
package database
import java.sql.*
import com.kms.katalon.core.annotation.Keyword
public class postgresHandler {
Connection c = null
Statement stmt = null
@Keyword
public void connectToPostgres(){
try {
Class.forName("org.postgresql.Driver")
String url = "jdbc:postgresql://localhost:5433/postgres?currentSchema=SCHEMA";
Properties props = new Properties();
props.setProperty("user","postgres");
props.setProperty("password","postgres");
c = DriverManager.getConnection(url, props);
} catch (Exception e) {
e.printStackTrace()
System.err.println(e.getClass().getName()+": "+e.getMessage())
System.exit(0)
}
System.out.println("Opened database successfully")
}
@Keyword
public void getProduct(){
try {
Class.forName("org.postgresql.Driver")
String url = "jdbc:postgresql://localhost:5433/postgres?currentSchema=SCHEMA";
Properties props = new Properties();
props.setProperty("user","postgres");
props.setProperty("password","postgres");
c = DriverManager.getConnection(url, props);
c.setAutoCommit(false)
System.out.println("Opened database successfully")
stmt = c.createStatement()
ResultSet rs = stmt.executeQuery( "select * from products.products;" )
while ( rs.next() ) {
String id = rs.getString("id")
String productid = rs.getString("productid")
String productInfo = rs.getString("productInfo")
System.out.println( "ID = " + id )
System.out.println( "productID = " + productid )
System.out.println( "productInfo = " + productInfo )
System.out.println()
}
rs.close()
stmt.close()
c.close()
} catch ( Exception e ) {
System.err.println( e.getClass().getName()+": "+ e.getMessage() )
System.exit(0)
}
System.out.println("Operation done successfully")
}
}
================================================ ============== 3.测试用例以调用添加产品关键字groovy脚本
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
result = CustomKeywords.'swisslog.KafkaRest.AddProduct'()
print(result)
WS.sendRequest(findTestObject('AddProduct'))
================================================ ======
import com.kms.katalon.core.configuration.RunConfiguration
CustomKeywords.'dsdatabase.postgresHandler.connectToPostgres'()
CustomKeywords.'dsdatabase.postgresHandler.getProduct'()