For what I know when creating a data file you are required to choose what file are you going to import (e.g. excel, csv, DB file, or internal data) may I know what data type did you choose?
Hello Timo, my issue here is not about storing the data, its about having a column whereby at specific rows, it will have a data and that data i need to compare this to perform a check and later on to do an action on the screen.
As a starting point, i’m using the InternalData with string type.
e.g you can fetch needed data by row index from the db
//get rowdata to list by index number
List<String> rowData = new ArrayList<>()
rowData = CustomKeywords.'postgresUtil.postgresHandler.getRowDataById'(newRow)
String fName = rowData.get(1)
int personAge = Integer.parseInt(rowData.get(2))
String add = rowData.get(3)
double sal = Double.parseDouble(rowData.get(4))
String personSsn = rowData.get(5)
......
then use it in test case
@Keyword
public List<String> getRowDataById(int idx){
List<String> rowData = new ArrayList<>()
try {
Class.forName("org.postgresql.Driver");
c = DriverManager
.getConnection("jdbc:postgresql://"+host+":5432/"+db,user,pass);
c.setAutoCommit(false);
System.out.println("Opened database successfully");
String SQL = "SELECT * FROM COMPANY WHERE id = ?";
pstmt = c.prepareStatement(SQL);
pstmt.setInt(1, idx);
ResultSet rs = pstmt.executeQuery();
while ( rs.next() ) {
int id = rs.getInt("id");
String name = rs.getString("name");
int age = rs.getInt("age");
String address = rs.getString("address");
float salary = rs.getFloat("salary");
String ssn = rs.getString("ssn");
if (id == idx){
rowData.add(id)
rowData.add(name)
rowData.add(age.toString())
rowData.add(address)
rowData.add(salary.toString())
rowData.add(ssn)
System.out.println( "ID = " + id );
System.out.println( "NAME = " + name );
System.out.println( "AGE = " + age );
System.out.println( "ADDRESS = " + address );
System.out.println( "SALARY = " + salary );
System.out.println( "SSN = " + ssn );
System.out.println();
}
}
rs.close();
pstmt.close();
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName()+": "+ e.getMessage() );
System.exit(0);
}
System.out.println("Operation done successfully");
return rowData
}
Hi Timo, the solution you provided me is too complexe. What i really need is that when Katalon is going to execute the first row of data, the last column at times will have data and at times not.
What i want at run time is that, when executing the first row of data, it should check the value of the last column is not null and contain a value and that value will be check which types of action.
like this code snip
List<String> columns = new ArrayList<>()
columns.add("first")
columns.add("second")
columns.add("third")
InternalData data = findTestData('SpamData/someSpamTestData')
String column
int x = 0
int y = 0
message = "column has not value!!!!"
KeywordUtil log = new KeywordUtil();
for (def index : (0..data.getRowNumbers() - 1)) {
for (int k = 0; k < columns.size(); k++){
column = data.internallyGetValue(columns.get(k), x)
if (column.equals("")){
log.markWarning("column "+columns.get(k)+ " row "+x+" has not data "+column);
//log.markError(message +columns.get(k)+ " row "+x );
//throw new com.kms.katalon.core.exception.StepErrorException("cell is null")
}else{
println "column "+k+ " row "+x+" data "+column
}
y++
}
if (y >= data.getRowNumbers() - 1)
x++
y=0
}
column has not value!!!! first row 0
2019-04-03 20:28:01.371 WARN com.kms.katalon.core.util.KeywordUtil - column first row 0 has not data
column 1 row 0 data two
column 2 row 0 data cow
column 0 row 1 data dog
column has not value!!!! second row 1
2019-04-03 20:28:01.654 WARN com.kms.katalon.core.util.KeywordUtil - column second row 1 has not data
column 2 row 1 data cat
Timo’s code is the one you are looking for but I think its hard for you to understand it, so, I’m going to make it simple. You can do this since you only need to read MemoConn column.
//locate your internal data
InternalData iData = findTestData("your_internal_data")
//this is to print all the values
println iData.getAllData()
//this is to specify the column you want to use
//parameters should be column name and the row number will start at 1
iData.getValue("ColumnName", 1)
//or
//instead of column name, use the index of the column
//first parameter is for the column and second parameter is for the value/row number
iData.getValue(1, 1)
//Sample condition
if (iData.getValue("MemoConn", 1).contains("App")
{
// do something
}
else
{
// do something
}
Hi @Arnel In my CSV i have 4 different kind of names in one column based on that particular row text i need to select the drop down in WebUI which contains the CSV row name,How can i implement this can you pls help me.
May I know the html source/locator of that drop down? because you can do that by comparing the value of your CSV to the value of your dropdown, thats why I need to know the locator, you need to get the dropdown items first before comparing it to your csv data… If it matches then it will be selected.
Hi @Arnel Thank You i used switch case it’s working.And one more doubt how can we download the files into different directories currently i’m downloading all different kind’s of files(CSV & PDF’s) into one directory could you please help me.