File upload Windows

I am trying to find out how I can upload files. In Selenium it is possible to run an .exe file created with AutoIT. For Katalon I find the article below, but I don’t quite understand how to manage the file upload

http://forum.katalon.com/questions/how-to-upload-a-file-from-windows-explorer/

The flow in my case is

  1. Click Browse in the web application, ref. attachment UploadFilesDialogWeb
  2. Select file in Windows through Windows upload dialog, ref. attachment UploadFilesDialogWindows
  3. Click orange button in web application ref. attachment UploadFilesDialogWeb

I am trying to find out how I can upload files. In Selenium it is possible to run an .exe file created with AutoIT. For Katalon I find the article below, but I don’t quite understand how to manage the file upload

http://forum.katalon.com/questions/how-to-upload-a-file-from-windows-explorer/

The flow in my case is

  1. Click Browse in the web application, ref. attachment UploadFilesDialogWeb
  2. Select file in Windows through Windows upload dialog, ref. attachment UploadFilesDialogWindows
  3. Click orange button in web application ref. attachment UploadFilesDialogWeb

Hi there,

In your case, the flow should be:
1. Add ‘Upload File’ step to select the file.
2. Add ‘Click’ step to click on the orange button.

So the example should be:
WebUI.uploadFile(findTestObject(‘btn_UploadFile’),‘C:\\your_file.png’))
WebUI.clickl(findTestObjec(‘btn_doneButton’))

That’s all you need you to do in Katalon Studio.

Thanks

____________________
Thank you for choosing Katalon Studio as your automation solution.
Your feedback is needed to make Katalon Studio a better tool, take the survey at: https://goo.gl/S25NVO

Hmm, is the problem that the object is null. What should I use as object for the windows dialog part of the upload?

Wbr

Vegar

Fra: Katalon Studio Support [mailto:support@katalonhelp.zendesk.com]
Sendt: tirsdag 27. juni 2017 18.02
Til: Vegar Warhuus
Emne: [Ticket awaiting] We are waiting for your response: File upload Windows

Hi there,

The object you need to pass here is the ‘Browse’ button which will open ‘Select File’ form from your web application. Please add ‘Browse’ test object and use it in ‘Upload File’ keyword, you can refer to the example from this page:
https://docs.katalon.com/display/KD/[WebUI]+Upload+File

Thanks

Hi there,

The object you need to pass here is the ‘Browse’ button which will open ‘Select File’ form from your web application. Please add ‘Browse’ test object and use it in ‘Upload File’ keyword, you can refer to the example from this page:
https://docs.katalon.com/display/KD/[WebUI]+Upload+File

Thanks

____________________
Thank you for choosing Katalon Studio as your automation solution.
Your feedback is needed to make Katalon Studio a better tool, take the survey at: https://goo.gl/S25NVO

Hi

I am sorry, but his doesn’t work. After clicking the browse button, Katalon studio is not able to enter/pass filename to this dialog in windows. Browse button is probably not the right element to use as target in this case.

Wbr

Vegar

Fra: Oliver Howard (Katalon Studio Support) [mailto:support@katalonhelp.zendesk.com]
Sendt: mandag 3. juli 2017 04.57
Til: Vegar Warhuus
Emne: [Katalon Studio Customer Support] Ticket answered. Re: File upload Windows 1094

Hi there,

Please remove step 9 (‘Click’ on the Browse button) and try again. ‘Upload File’ keyword has already included click simulation on that button.
If the issue is still happens again, can you help to send me the full error message from that ‘Upload File’ keyword

Thanks

____________________
Thank you for choosing Katalon Studio as your automation solution.
Your feedback is needed to make Katalon Studio a better tool, take the survey at: https://goo.gl/S25NVO

Without step 9 à The test remains in the web window, and doesnt open the windows «file open» dialog

Unable to upload file ‘C:\\Users\\vewa\\Documents\\Tesdata\\Test20170601_A.pdf’ to object ‘Object Repository/UploadWebPart/BrowseButtonWebPart’ (Root cause: org.openqa.selenium.WebDriverException: unknown error: cannot focus element

(Session info: chrome=59.0.3071.115)

(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)

Command duration or timeout: 60 milliseconds

Build info: version: ‘2.53.0’, revision: ‘35ae25b’, time: ‘2016-03-15 17:00:58’

System info: host: ‘01-270417-vewa’, ip: ‘10.50.10.124’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_102’

Driver info: org.openqa.selenium.chrome.ChromeDriver

Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233), userDataDir=C:\Users\vewa\AppData\Local\Temp\scoped_dir14112_19608}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=59.0.3071.115, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]

Session ID: 6f7b171828ffdd28ed98056984c10cf2)

With step 9 à The windows file dialog is opened, but the test fails without being able to give filename as input

Unable to upload file ‘C:\\Users\\vewa\\Documents\\Tesdata\\Test20170601_A.pdf’ to object ‘Object Repository/UploadWebPart/BrowseButtonWebPart’ (Root cause: org.openqa.selenium.WebDriverException: unknown error: cannot focus element

(Session info: chrome=59.0.3071.115)

(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)

Command duration or timeout: 50 milliseconds

Build info: version: ‘2.53.0’, revision: ‘35ae25b’, time: ‘2016-03-15 17:00:58’

System info: host: ‘01-270417-vewa’, ip: ‘10.50.10.124’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_102’

Driver info: org.openqa.selenium.chrome.ChromeDriver

Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233), userDataDir=C:\Users\vewa\AppData\Local\Temp\scoped_dir15668_23880}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=59.0.3071.115, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]

Session ID: a9b9385db59c111aa567d249711015b8)

It is the same for Firefox and Chrome

Wbr

Vegar

Fra: Oliver Howard (Katalon Studio Support) [mailto:support@katalonhelp.zendesk.com]
Sendt: tirsdag 4. juli 2017 08.42
Til: Vegar Warhuus
Emne: [Katalon Studio Customer Support] Ticket answered. Re: File upload Windows 1094

Hi there,

I see, that keyword can’t focus on the element to pass in uploaded file. So in that case, please do the following:
1. Create the following custom keyword (https://docs.katalon.com/display/KD/Define+custom+keywords):

import java.awt.Robot
import java.awt.Toolkit
import java.awt.datatransfer.StringSelection
import java.awt.event.KeyEvent

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

public class WebUICustomKeyword {
@Keyword
def uploadFile(TestObject to, String filePath) {
WebUI.click(to)
StringSelection ss = new StringSelection(filePath);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
}
}

2. Replace ‘Upload File’ step with that custom keyword in your test case instead, e.g:
CustomKeywords.‘com.katalon.WebUICustomKeyword.uploadFile’(findTestObject(‘BrowseButton’), ‘yourFileHere’)

More details about creating and managing custom keywords can be found on this page: https://docs.katalon.com/display/KD/Define+custom+keywords

Thanks

____________________
Thank you for choosing Katalon Studio as your automation solution.
Your feedback is needed to make Katalon Studio a better tool, take the survey at: https://goo.gl/S25NVO

2 Likes

Thanks

This worked fairly well. In fact it works 100% when using Firefox, but when using Chrome nothing is entered in the Windows file path unless I use double slashes, and then the filepath is doomed invalid by Windows.

Wbr

Vegar

Fra: Oliver Howard (Katalon Studio Support) [mailto:support@katalonhelp.zendesk.com]
Sendt: tirsdag 4. juli 2017 09.17
Til: Vegar Warhuus
Emne: [Katalon Studio Customer Support] Ticket answered. Re: File upload Windows 1094

Hi

Any idea why it only works only for Firefox, and not Chrome, IE and Edge?

Wbr

Vegar

Fra: Oliver Howard (Katalon Studio Support) [mailto:support@katalonhelp.zendesk.com]
Sendt: onsdag 5. juli 2017 04.40
Til: Vegar Warhuus
Emne: [Katalon Studio Customer Support] Ticket solved. Re: File upload Windows

Hi there,

Can you show me your input filePath? What is the value when you specify it to use on Chrome?

Thanks

____________________
Thank you for choosing Katalon Studio as your automation solution.
Your feedback is needed to make Katalon Studio a better tool, take the survey at: https://goo.gl/S25NVO

The filepath is the same in all cases

«C:\Users\vewa\Documents\Tesdata\Test20170601_A.pdf»

The test only works for me when the browser is Firefox. The weird thing is that Katalon logs the upload step as green, even though filepath is actually not entered in the Windows dialog for file upload when my browser is Edge, IE or Chrome. Maybe some kind of custom wait should added between pressing the browse button in the web UI and execution the custom file upload step?

Wbr

Vegar

Fra: Oliver Howard (Katalon Studio Support) [mailto:support@katalonhelp.zendesk.com]
Sendt: onsdag 5. juli 2017 09.28
Til: Vegar Warhuus
Emne: [Katalon Studio Customer Support] Ticket answered. Re: File upload Windows 1094

Hi there,

Is that the original filepath you’ve used? I don’t think so because you need to pass in double splashses to escape it, e.g:
C:\\Users\\vewa\\Documents\\Tesdata\\Test20170601_A.pdf
If you pass that as filePath value, it’s doomed by Windows?

Thanks

____________________
Thank you for choosing Katalon Studio as your automation solution.
Your feedback is needed to make Katalon Studio a better tool, take the survey at: https://goo.gl/S25NVO

Yes, double splashes are actually entered in the dialog, and ends in «filename is not valid» for the test. Single splashes works for Firefox

Vegar

Fra: Oliver Howard (Katalon Studio Support) [mailto:support@katalonhelp.zendesk.com]
Sendt: onsdag 5. juli 2017 10.51
Til: Vegar Warhuus
Emne: [Katalon Studio Customer Support] Ticket answered. Re: File upload Windows 1094

Hi there,

Can I ask which keyboard you’ve used? I suppose it’s not English keyboard, right?

Thanks

____________________
Thank you for choosing Katalon Studio as your automation solution.
Your feedback is needed to make Katalon Studio a better tool, take the survey at: https://goo.gl/S25NVO

Yes, I am from Norway so I already had a case with you where I had to change the capture object keyboardshortcut.

If this is a keyboard issue, this will typically be an issue for the Nordic countries.

Wbr

Vegar

Fra: Oliver Howard (Katalon Studio Support) [mailto:support@katalonhelp.zendesk.com]
Sendt: onsdag 5. juli 2017 11.29
Til: Vegar Warhuus
Emne: [Katalon Studio Customer Support] Ticket answered. Re: File upload Windows 1094

Hi there,

Here is another workaround solution: Please add replaceAll("\\\\\\", “\\\”) next to the input filePath, e.g:
CustomKeywords.‘com.katalon.keywords.WebUICustomKeyword.uploadFile’(findTestObject(‘upload’), filePath.replaceAll("\\\\\\", “\\\”))

Thanks

____________________
Thank you for choosing Katalon Studio as your automation solution.
Your feedback is needed to make Katalon Studio a better tool, take the survey at: https://goo.gl/S25NVO

I’m affraid I don’t understand where to add this replaceAll thing. Shall I open a script file from anywhere or add this from the Katalon UI somwhere?

Thanks for brilliant support and patience by the way