栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

katalon:将验证结果保存至数据库

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

katalon:将验证结果保存至数据库

一、新建数据库表

根据要存储的数据,新建数据库表
如:
在数据库test下新建log表:

二、新建关键字
package utils
 
import java.sql.Connection
import java.sql.DriverManager
import java.sql.ResultSet
import java.sql.Statement
import java.text.SimpleDateFormat

import com.kms.katalon.core.annotation.Keyword
 
public class DemoMySql {
 
private static Connection connection = null;
 

 
//Establishing a connection to the DataBase
 
@Keyword
 
def connectDB(String url, String dbname, String port, String username, String password){
 
//Load driver class for your specific database type
String conn = "jdbc:mysql://" + url + ":" + port + "/" + dbname
 
//Class.forName("org.sqlite.JDBC")
 
//String connectionString = "jdbc:sqlite:" + dataFile
 
if(connection != null && !connection.isClosed()){
 
connection.close()
 
}
 
connection = DriverManager.getConnection(conn, username, password)
 
return connection
 
}
 
 
@Keyword
 
def executeQuery(String queryString) {
 
Statement stm = connection.createStatement()
 
ResultSet rs = stm.executeQuery(queryString)
 
return rs
 
}
 
//Closing the connection
 
@Keyword
 
def closeDatabaseConnection() {
 
if(connection != null && !connection.isClosed()){
 
connection.close()
 
}
 
connection = null
 
}
 
 
@Keyword
 
def execute(String queryString) {
 
Statement stm = connection.createStatement()
 
boolean result = stm.execute(queryString)
 
return result
 
}


@Keyword
def saveVerifyResultForDatabase(verify_the_content,desired_value,actual_value,isequals){
	def date = new Date()
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
	connectDB("127.0.0.1","test","3306","root","root")
	
	execute("INSERT INTO `test`.`log` ( `name`, `expected`, `actual`, `result`, `create_time`) VALUES ('"+verify_the_content+"', '"+desired_value+"', '"+actual_value+"', '"+isequals+"','"+sdf.format(date)+"');")
	closeDatabaseConnection()
}
 
}

存储数据使用 saveVerifyResultForDatabase,其中链接数据库connectDB的配置根据实际配置进行修改。

三、调用关键字

在填写测试用例时,调用关键字,保存验证结果:

 CustomKeywords.'utils.DemoMySql.saveVerifyResultForDatabase'("检查个人登录端证件类型", desired_value, getcardtype,s1)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/999365.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号