Hello, I would like to ask about a CSV file that I use to fill in names on a website, then verify them. I need Katalon to mark the names it used in that CSV file.
For example:
Name: Adam, Status: False
When Katalon uses the name ‘Adam’ on the website, it should change the ‘False’ in the CSV file to 'True
1 Like
Hi @matej.kokles,
Welcome to our community. Thank you for sharing your issue.
In terms of your situation, I would like to suggest simply that you read the CSV file and convert it to the list. Then you handle the verification then write back to the file.
Example for verification here:
for (int i = 1; i < csvData.size(); i++) {
String name = csvData[i][0].trim()
String status = csvData[i][1].trim()
if (status == "False") {
// Enter the name on the website (example)
WebUI.setText(findTestObject('Page_Input/NameField'), name)
WebUI.click(findTestObject('Page_Input/SubmitButton'))
// Assume there's a verification step
boolean verificationSuccess = WebUI.verifyElementPresent(findTestObject('Page_Verify/SuccessIndicator'), 5, FailureHandling.OPTIONAL)
if (verificationSuccess) {
csvData[i][1] = "True" // Update status in memory
}
}
}
Hope this can help
Hello,
Thank you very much for your response, but I don’t know how to use it in my script. The script works, it can search and enter names gradually, but I need it to change the statuses from “false” to “true” in the same CSV file after use.
Thank you very much.
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testng.keyword.TestNGBuiltinKeywords as TestNGKW
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys
WebUI.openBrowser('')
WebUI.navigateToUrl('xxx')
WebUI.setText(findTestObject('Object Repository/Page_Sign in to futura-internal/input_Username or email_username'), 'xxx')
WebUI.setEncryptedText(findTestObject('Object Repository/Page_Sign in to futura-internal/input_Password_password'), 'xxx')
WebUI.click(findTestObject('Object Repository/Page_Sign in to futura-internal/input_Password_login'))
WebUI.click(findTestObject('Object Repository/Page_Home - Backoffice - Futura/span_user_attributes CONTACT_c27d1a'))
WebUI.click(findTestObject('Object Repository/Page_Home - Backoffice - Futura/a_Contacts'))
WebUI.setText(findTestObject('Object Repository/Page_Contacts Search Contacts - Backoffic_2e3e5a/input_Client Name_ID_69720'),
menafutura)
WebUI.delay(2)
WebUI.click(findTestObject('Object Repository/Page_Contacts Search Contacts - Backoffic_2e3e5a/a_read_more'))
WebUI.verifyElementText(findTestObject('Object Repository/Page_Drutovi Arpd Person Contacts - Backo_0ec1e5/span_Drutovi Arpd'),
menafutura)
WebUI.closeBrowser()
Katalon Studio provides no builtin support out of box to implement that.
If you want to, you have to develop a Groovy script (test case) that updates the CSV file.
I guess, you want to know how to distinguish if your Test Case has passed or failed, and how to run a series of custom statements only when the test failed.
The following code shows an example.
WebUI.openBrowser('')
WebUI.navigateToUrl('xxx')
...
boolean passed = WebUI.verifyElementText(findTestObject('Object Repository/Page_Drutovi Arpd Person Contacts - Backo_0ec1e5/span_Drutovi Arpd'),
menafutura, FailureHandling.CONTINUE_ON_FAILURE)
if (!passed) {
// you can do anything here
println "could not find \'${menafutura}\' for user \'${user}\'"
// you may want to update the csv file. yes, you can do it.
// you may want to create another CSV file where you would append only the failed user names while ignoring passed users. You can use the output file as the input for the next time run.
}
WebUI.closeBrowser()
Thank you very much, you helped me a lot, I really appreciate it.
Hi @matej.kokles,
We would love to support you in our community
If you have found the solution for your issue, feel free to share it and mark as solution for reference. Thank you
1 Like