Looping input text reading from a excel for UI testing

Hello,
I’m trying to input several sample text (one at a time) from a excel file. I want to put this in a loop so it will input each text from cell 1 then from cell 2 then from cell 3…

Any suggestion on bets way to get this done. The current loop is not working for me:

def info = WebUI.callTestCase(findTestCase(‘Simplify/data_setup’), [:], FailureHandling.STOP_ON_FAILURE)

def sampleText = info.sampleText

‘Global variable for env and nav to app’

Site = GlobalVariable.url_prod

WebUI.openBrowser(Site)

WebUI.waitForPageLoad(30)

for (row = 2; row <= findTestData(info).getRowNumbers(); row++) {

WebUI.sendKeys(findTestObject(‘Object Repository/Content_App/i_text_input_box’), Keys.chord(Keys.ENTER))

WebUI.sendKeys(findTestObject(‘Object Repository/Content_App/i_text_input_box’), Keys.chord(Keys.COMMAND, ‘a’))

WebUI.clearText(findTestObject(‘Object Repository/Content_App/i_text_input_box’))

WebUI.click(findTestObject(‘Object Repository/Content_App/i_text_input_box’))

WebUI.setText(findTestObject(‘Object Repository/Content_App/i_text_input_box’), sampleText)

CustomKeywords.‘com.clickhelper.clickHelper.clickUsingJS’(findTestObject(‘Object Repository/Content_main_func/a_summarize’),

}

Hello
Can i know the console error? and failed log?
and findTestData(info).getRowNumbers() is not equal zero?

Hi Rick,

Based on my understanding, what you’re trying to do is you’re going to pull a data or string text from your excel file then you will put it into your text box?

If so, then try to do this:

Object excelData = ExcelFactory.getExcelDataWithDefaultSheet(excelPath, sheetName, true)
for(int row = 1; row <= excelData.getRowNumbers(); row++)
{
//your additional commands here
WebUI.setText(findTestObject(‘Object Repository/Content_App/i_text_input_box’), excelData.getValue(columnName, row))
}

Hope that helps. . .

1 Like

Arnel said:

Hi Rick,

Based on my understanding, what you’re trying to do is you’re going to pull a data or string text from your excel file then you will put it into your text box?

If so, then try to do this:

Object excelData = ExcelFactory.getExcelDataWithDefaultSheet(excelPath, sheetName, true)
for(int row = 1; row <= excelData.getRowNumbers(); row++)
{
//your additional commands here
WebUI.setText(findTestObject(‘Object Repository/Content_App/i_text_input_box’), excelData.getValue(columnName, row))
}

Hope that helps. . .

Thanks for the help. Here is the final code:

import com.kms.katalon.core.testdata.ExcelData as ExcelData

import com.kms.katalon.core.testdata.reader.ExcelFactory as ExcelFactory

‘Global variable for env and nav to app’

Site = GlobalVariable.url_target

WebUI.openBrowser(Site + ‘app’)

WebUI.waitForPageLoad(30)

Object excelData = ExcelFactory.getExcelDataWithDefaultSheet(“Data Files/Sample_text_2.xlsx”, ‘Sheet1’ , true)

for(int row = 1; row <= excelData.getRowNumbers(); row++)

{

WebUI.sendKeys(findTestObject(‘Object Repository/Content_App/i_text_input_box’), Keys.chord(Keys.ENTER))

WebUI.sendKeys(findTestObject(‘Object Repository/Content_App/i_text_input_box’), Keys.chord(Keys.COMMAND, ‘a’))

WebUI.clearText(findTestObject(‘Object Repository/Content_App/i_text_input_box’))

WebUI.setText(findTestObject(‘Object Repository/Content_App/i_text_input_box’), excelData.getValue(“input_text_sample”, row))

CustomKeywords.‘com.clickhelper.clickHelper.clickUsingJS’(findTestObject(‘Object Repository/Content_main_func/a_summarize’),

WebUI.refresh()

}

Glad it works! You’re welcome. :slight_smile: