Hello,
I am attempting to following the directions at this website to upload a file, but am not having success. Any help is appreciated…
An object on my website has type = “file” as the website specifies:
Hello,
I am attempting to following the directions at this website to upload a file, but am not having success. Any help is appreciated…
An object on my website has type = “file” as the website specifies:
First, create a keyword to the file upload button or link, something like: “Object Repository/Page_Add_Document_To_Current_Account/lnk_choose_a_file”
Next, create a method call for which will handle the upload, like
class uploadNewFile {
/**
This method will be used to upload file
*/ @Keyword
def uploadFileToTest(TestObject to, String filePath){
WebUI.click(to)
WebUI.delay(3) //i’d recommend adding this delay to give the code time to run
StringSelection ss = new StringSelection(filePath)
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null)
WebUI.delay(2) //same reason as above
Next, call the method where it needs to be in your code and it will appear something like:
CustomKeywords.‘methodCalls.uploadNewFile.uploadFileToTest’(findTestObject(null), ‘’)
Next, replace null in 3 above with the keyword you created in 1 above, then insert the filepath of the file to be uploaded into the ‘’ in 3 above.
UPDATE:
//KS seems to have an issue with selecting the correct path to the file, so the best solution, for me, was to include the desired docs to be added into the Data Files container in KS, then call it from there. This ensures that the same doc is called, no matter who or where the test is being run from
WebUI.delay(2)
//this string will replace the user/system path being used to run the test at any particular time
String textDir = RunConfiguration.getProjectDir()
//the default path connectors were failing in the tests, so, it was necessary to replace them, which worked for me
String replaced = textDir.replace(’/’, ‘\’)
//_please note that the single backslash in code above should be double, as in \ \ , but when entered into the comments here, it’s represented as a single backslash. Not sure why this is the case… _
The final statement would be something like:
CustomKeywords.‘methodCalls.uploadNewFile.uploadFileToTest’(findTestObject(‘Object Repository/Page_Add_Document_To_Current_Account/lnk_choose_a_file’),
replaced + ‘\Data Files\name-of-file.txt/png/doc/etc’)
//_please note that the single backslash before and after Data Files, and for all paths to the file to be uploaded, should be double, as in \ \ , but when entered into the comments here, it’s represented as a single backslash. Not sure why this is the case… _
All the best
Even I am having similar problem. Am not able to upload the file even thought it clicks on an object but doesn’t enter the path not uploading document.
I tried also this way but it doesn’t like file name after filepath and where filename starts and my file name is blankpage.pdf.
CustomKeywords.‘methodCalls.uploadNewFile.uploadFileToTest’(findTestObject(‘objectname’), ‘D:/Sample Document/blankpage.pdf’)
expecting ‘)’, found ‘blankpage’ @ line 55, column 111
I didn’t get this part of you update.
//KS seems to have an issue with selecting the correct path to the file, so the best solution, for me, was to include the desired docs to be added into the Data Files container in KS, then call it from there. This ensures that the same doc is called, no matter who or where the test is being run from.
Please provide in detail how to add desired docs into the Data Files as I can only add excel or csv filed in Data Files.