How to print sql query results?

Hi there,
I have a problem how print the query result. In Log Viewer test passes but I have something like that:

In test I want to get something from SQL Database and match text in with text on website. That’s possible?

query_results.png

Hi,
why no getting Data with prepared Data Objects?
https://docs.katalon.com/display/KD/Manage+Test+Data

So you can just:

def data = findTestData('YourDataObject')
// get value from cell of column 1 and row 1
println data.getValue(1, 1)

Yes it’s possible. Set up Data file - test data, use global connection to connect with your DB and enter your SQL Query.

Then in your test case set up variable (there is a tab for this)
Add a new variable, call it whatever you want
Type should be “Test Data Value”
Edit the default value:
Test Data should refer to your Data File
Set column and row

This will set that variable to whatever you want from the DB, you can then do a verify match statement or something to compare.

For example on your webpage you can do a
String example = WebUI.getText(findTestObject(‘object’))
WebUI.verifyMatch(example, testDataVariable, true)

Thanks for answer! But in the way they were proposed I can use only one SQL Query in TC. What when I want to use few query in Test Case?

I suppose it depends on the queries, would a join work? Could you do multiple test data and set separate variables? I think there are ways posted in the forums to do a sql query from inside the script but test data is the way I have always gone personally.

If you can provide more information of what you are trying to do, I’ll do my best to come up with something in this method. I’m not an expert and still new myself though.

I did it as you prepared.Maybe you know how to check all the rows in the table.
How to get text from all rows in one variable and verifyTextPresent? Or in loop : First turn loop row 1 second row 2 etc.

getall.png

Okey, I have it :slight_smile:

But now I have other problem… I create two Database with different query. Frist query work excelent but when I want put some query in second DB I I get the message:

Query is correct because in SQL Management Studio I had correct results.

conf.png

Yes you can loop through the rows, you have that figured out?

So others who read this can also I’ll add what I do for looping through rows to compare. I did this to verify all dropdown values match db
‘Query DB and verify each value appears in the dropdown for Group’

String groupList = ‘’

int rowNumbers = TestDataFactory.findTestData(‘Project/Dashboard/user/groups_DB’).getRowNumbers()

int columnNumbers = TestDataFactory.findTestData(‘Project/Dashboard/user/groups_DB’).getColumnNumbers()

for (int i = 1; i < rowNumbers; i++) {
groupList = TestDataFactory.findTestData(‘Project/Dashboard/user/groups_DB’).getValue(1, i)

WebUI.verifyOptionPresentByLabel(findTestObject('Project/Dashboard/user/02 User Editing/03 Fields/18 Group Dropdown/04_value_Group'), 
    groupList, false, 0, FailureHandling.CONTINUE_ON_FAILURE)

}

For your other issue it depends on your table structure of your DB, are they both in the same tree?

I had to set up separate connect for different DB tables because the where in separate sections. I don’t know the proper name as I don’t build DB but they where basically separate DBs

Either way it’s not liking the conf.ConfigurationHeader

typically when you have “something.table” it’s because it’s a different connection URL. So as I mentioned I have two and each section of DB Datafiles I have, I had to setup separately to connect to that one. If I was to query in pgadmin I could just put something.table name but from katalon this gave me an error too saying it didn’t exist.

My answer in this thread may or may not be useful:

2 Likes