Test data refresh while running a Test Suite?

I am new to this field of automation so bare with me
Quick explanation: The the website i am testing generates some numbers that i catch with getText, and i store them in a Test Data Excel file. User completes an action ( in my case is doing a process ) and a new process is generated with some other number. Process-2 is closed and Process-3 is created and so on. i am able to link Process-2 with Process-3, but from there on the test data does not update and i cannot link anymore.
I use a keyword to write in excel the getText, this works.
Then i have a GlobalVariable for each process
After this i have a Keyword that goes through the whole table to find the Processes-x stored in the test data and GlobalVariable. This is where i fail. My first check works.
-Create Process-1 → store in test data → global variable → find Process-1 → open → Process-2 created //this is where its stopping (i used a println to see what happens, its empty, but if i open the excel file it is there) . It does not refresh with the new values. Please note that this is only happening if i run test cases in a Test Suite. If i run each test case one by one, it works. I tried doing a Object excel refresh, does not work.

Hi @donose-daniel.andrei,

Based on this. . .

Yes it will not be refreshed unless you will read the excel file again while your suite is running. Because the first instance it will read the current value then your code will do a change, of course the current instance cannot go back and read the latest change so you need to have a second instance to read the excel file again to acquire the updated value.

Something like. . . .

//first instance
ExcelReader reader1 = new ExcelReader()
String num1 = reader1.getValue(param1, param2)
println num1
//sample output 12345

//your code when changing/updating your test data

//second instance
ExcelReader reader2 = new ExcelReader()
String num2 = reader2.getValue(param1, param2)
println num2
//sample output 67890

//this is not the exact code, I'm just giving you an idea on how you will sort it out.

If you will use ‘reader1’ you won’t be able to reader the latest change, it will still read the previous value. That’s why you need to have a second instance (‘reader2’) that will read your latest change.

It will be much better if you can share a snippet of your code here so that we can advise a better solution.

Hope that helps. . . :slight_smile:

Hello @Arnel ,

i don’t read the excel data, i store it in a global variable from a getText
this is the code i use to write in the file ( i have one keyword for each process):

@Keyword
public static void write(String name,String Column_Name) throws IOException{
FileInputStream fis = new FileInputStream("./Data Files/processes.xlsx")
XSSFWorkbook workbook = new XSSFWorkbook(fis)
XSSFSheet sheet = workbook.getSheet(“data”)
int rowCount = i
if (Column_Name==‘Meeting’){
Row row = sheet.getRow(rowCount+1)
Cell cell = row.createCell(0,0)
cell.setCellType(cell.CELL_TYPE_STRING)
cell.setCellValue(name)
}

  FileOutputStream fos = new FileOutputStream("./Data Files/processes.xlsx")
  workbook.write(fos)
  fos.close()

}

I then take this data and store it in the global variable (findTestData(‘Test Data’).getValue(parm1,param2)

and after this i use this Keyword ( again one for each process ) to find buttons on the website corresponding to the excel file:

@Keyword
def contract(){
Object excel = ExcelFactory.getExcelDataWithDefaultSheet("./Data Files/processes.xlsx",“data”,true)
excel.getValue(“Contract”,1)
TestData update
println('This is test data '+findTestData(‘Test data’).getValue(3, 1))
println(‘This is global variable ‘+GlobalVariable.Contract)
WebDriver driver = DriverFactory.getWebDriver()
String lookFor = GlobalVariable.Contract
WebElement Table = driver.findElement(By.xpath(’//*[@id=“mainData”]/table[1]/tbody’))
List rows_table = Table.findElements(By.tagName(‘tr’))
List buttons = Table.findElements(By.tagName(‘button’))
int rows_count = rows_table.size
for (int row = 0; row < rows_count; row++){
List Columns_row = rows_table.get(row).findElements(By.tagName(‘button’))
int columns_count = Columns_row.size()
println(((lookFor) + ’ are ') + columns_count)
for (int column = 0; column < columns_count; column++){
String celltext = Columns_row.get(column).getText()
println((((('Cell Value Of row number ’ + row) + ’ and column number ') + column) + ’ Is ') + celltext)
if (celltext == lookFor){
rows_table.get(row).findElement(By.tagName(‘button’)).click()
return
}
break
}
}
}

This finds me in a table the string that is written in excel from the getText and then clicks the element that has that string as text. As you can see i tried something to refresh the file at runtime.
Thanks!

i am now using findTestData instead of global variable and it works after i refresh the excel file