I have to upload one file in different places on the web using katalon
I am using:
'Upload test-photo.png to input_browse'
WebUI.uploadFile(findTestObject('input_browse'), 'D:\\test-photo.png'
I have to upload the same file on below places
'Upload test-photo.png to Object Repository/TKM/Page_/upload_AB_log'
WebUI.uploadFile(findTestObject('Object Repository/TKM/Page_/upload_AB_log'), 'D:\\test-photo.png'
'Upload test-photo.png to Object Repository/TKM/Page_/Upload_BC_logo'
WebUI.uploadFile(findTestObject('Object Repository/TKM/Page_/Upload_BC_logo'), 'D:\\test-photo.png'
'Upload test-photo.png to Object Repository/TKM/Page_/upload_CD_log'
WebUI.uploadFile(findTestObject('Object Repository/TKM/Page_/upload_CD_log'), 'D:\\test-photo.png'
'Upload test-photo.png to 'Object Repository/TKM/Page_/upload_EF_logo'
WebUI.uploadFile(findTestObject('Object Repository/TKM/Page_/upload_EF_logo'), 'D:\\test-photo.png'
The path/file to upload is the same but needs to upload in different places/input.
I am trying to create the keyword but due to the change of object/input, it's not working for all.
Is there a way to create the keyword that will work for all uploads in katalon studio?
The purpose of writing keywords is code reusability - you can use the same code multiple times but with different parameters.
You could use something like this:
uploadfile(testObject, pathToUploadFile) {
// add some more code if needed
WebUI.uploadFile(testObject, pathToUploadFile)
}
so you are passing testObject
and pathToUploadFile
as parameters.
For example, to upload Logo.png
you would use
uploadfile(WebUI.uploadFile(findTestObject('Object'), 'D:\\Users\\Logo.png')
.