Katalon Studio - Database record count verification

Hi All,

I am very new to katalon studio. Using the documentation provided, I have created a custom keyword which connects to my MySQL database and execute a query.I have called this custom keyword inside my main script. But I am clueless on implementing below scenario.

Issue: I have a table named “users” where I have 100 records. When I add a new user from UI the count should be increased by 1 in the users table.So in my script , I have added code to add new record from UI and to connect with table and execute query to get record count , but I need to verify this query result with old records count from database(something like verify operation or assert).How to achieve this comparison part?

Can someone help me with this?


this is a pseudo-code for your problem. It should work like this:

int countBefore = mysqlQueryExecutor('select count(*) from users')


int countAfter = mysqlQueryExecutor('select count(*) from users')

assert countBefore + 1 == countAfter
1 Like

Thanks a lot for your solution.I will try out your solution and provide update

@Marek_Melocik : When i use the solution provided and used in my script, getting the below error.

Script : int userscountbefore = CustomKeywords.‘com.sampleproj.DBConnection.dblogin.executeQuery’(‘Select count(*) from users’)

**Error message **
**2019-**09-10 14:29:42.815 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/Functional/users/Create a new user FAILED.
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object ‘SQLServerResultSet:1’ with class ‘com.microsoft.sqlserver.jdbc.SQLServerResultSet’ to class ‘int’
at Create a new Category.run(Create a new Category:67)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1568105958194.run(TempTestCase1568105958194.groovy:21)

Alternate script tried :
def userscountbefore = CustomKeywords.‘com.sampleproj.DBConnection.dblogin.executeQuery’(‘Select count(*) from users’)

If i use above statement, i am not getting above error message.But results are not stored in userscountbefore variable

I can’t see into your code, but it seems the method execureQuery() returns SQLServerResultSet object, so you must gt the actual value out of it. I am not familiar with this class, so I can’t serve here.