How to Upload a file from windows explorer


#41

@emine : It doesn’t happen simultaneously in this example. Here is a site as an example: https://ec.europa.eu/cefdigital/DSS/webapp-demo/validation - “Original file(s)” field can handle more than one file at the same time.


#43

Hello Again @plaidshirtakos I have defined a custom keyword to add 2 files.

@Keyword
def uploadFile2 (TestObject to, String filePath , String file) {
WebUI.click(to)
StringSelection ss = new StringSelection(filePath);
StringSelection ss1 = new StringSelection("""+file+"" ")
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);

  Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss1, null);

  Robot Robotw = new Robot();

  Robotw.keyPress(KeyEvent.VK_CONTROL);
  Robotw.keyPress(KeyEvent.VK_V);
  Robotw.keyRelease(KeyEvent.VK_V);
  Robotw.keyRelease(KeyEvent.VK_CONTROL);

  robot.keyPress(KeyEvent.VK_ENTER);
  robot.keyRelease(KeyEvent.VK_ENTER);

}

My Test Case code for page https://ec.europa.eu/cefdigital/DSS/webapp-demo/validation

WebUI.openBrowser(’’)

WebUI.navigateToUrl(‘https://ec.europa.eu/cefdigital/DSS/webapp-demo/validation’)

not_run: WebUI.delay(2)

not_run: CustomKeywords.‘dosya.dosyayukleme.uploadFile’(findTestObject(‘Object Repository/test case 2/Page_DSS Demonstration WebApp/input_Signed file_signedFile’),
‘C:\Users\test\Desktop\1.PNG’)

not_run: WebUI.delay(3)

CustomKeywords.‘dosya.dosyayukleme.uploadFile2’(findTestObject(‘Object Repository/test case 2/Page_DSS Demonstration WebApp/input_Original file(s)_origina’),
‘C:\Users\test\Desktop\1.PNG’, ‘C:\Users\test\Desktop\2.PNG’)

WebUI.delay(2)

WebUI.click(findTestObject(‘Object Repository/test case 2/Page_DSS Demonstration WebApp/button_Submit’))

You must type your own file path in the C: // … fields.


#44

Hello Again @plaidshirtakos
I wrote code for page https://gofile.io/?t=uploadFiles that loads 3 files at the same time.
Custom Keyword Code for 3 file :

@Keyword
def uploadFile2 (TestObject to, String filePath , String file , String file2) {
WebUI.click(to)
StringSelection ss = new StringSelection("""+filePath+"" " +"""+ file +"" "+ file2 );
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);
}
}

And Test Case Code :

WebUI.openBrowser(’’)

WebUI.maximizeWindow()

WebUI.navigateToUrl(‘https://gofile.io/?t=uploadFiles’)

WebUI.click(findTestObject(‘Object Repository/Test Case 3/Page_Gofile - File sharing platform/p_Upload files’))

WebUI.delay(2)

CustomKeywords.‘dosya.dosyayukleme.uploadFile2’(findTestObject(‘Test Case 3/Page_Gofile - File sharing platform/button_Click here’),
‘C:\Users\test\Desktop\1.PNG’, ‘C:\Users\test\Desktop\2.PNG’, ‘C:\Users\test\Desktop\3.PNG’)

And test case result screen shot :


#45

I try to use your code, but got error message:
Groovy:unexpected char: 0xFFFF @ line 47, column 1

package uploadFile

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 com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.checkpoint.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
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable

public class upload2Files{
	@Keyword
	def upload(TestObject to, String filePath , String file) {
		WebUI.click(to);
		StringSelection ss = new StringSelection(filePath);
		StringSelection ss1 = new StringSelection("""+file+"" ");
			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);
			
			  Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss1, null);
			
			  Robot Robotw = new Robot();
			
			  Robotw.keyPress(KeyEvent.VK_CONTROL);
			  Robotw.keyPress(KeyEvent.VK_V);
			  Robotw.keyRelease(KeyEvent.VK_V);
			  Robotw.keyRelease(KeyEvent.VK_CONTROL);
			
			  robot.keyPress(KeyEvent.VK_ENTER);
			  robot.keyRelease(KeyEvent.VK_ENTER);
	      }
}

#46

Hello @plaidshirtakos

@Keyword
def uploadFile2 (TestObject to, String filePath , String file , String file2) {
WebUI.click(to)
StringSelection ss = new StringSelection("""+filePath+"" " +"""+ file +"" "+ file2 );
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);
}
} 

please try this code for the custom keyword.
Uploads 3 files at the same time.

Custom keyword full code:
UploadFile.txt (1.9 KB)


#47

@emine That part is ok, but get error during I try to call keyword:groovy.lang.MissingPropertyException: No such property: CustomKeywords for class:


#48

Hello Again @plaidshirtakos

Refresh the Keywords folder after all stages.

And Then :
Open your Test Case page and add a custom keyword. Follow the steps below.


This marked step must be added to the contents of the Test Case.


#49

I have a question! can the upload file plugin replace these steps? or do I still need to create a custom keyword so that the native windows popup will be passed through katalon?

thanks so much!


#50

hello @marias
If you added a file upload plugin, you don’t need to create a custom keyword, of course. You define Custom Keyword to create your own plugin.


#51

Hello @emine !
Thanks for imformation. Problem is here, that I try to call this custom keyword from another custom keyword. Both keywords are in the same package.


#52

Hello @plaidshirtakos
please , see below in link :

I also have more than one custom keyword definition in the same package. Please see the picture below.


When I add a custom keyword during the Test Case, they both appear
image


#53

@emine : I see, but you call it from a testcase. I call one of my custom keywords from a testcase, which should call another custom keyword.


#54

@plaidshirtakos

I’m sorry but I didn’t quite understand.


#55

@emine : I marked order of method calls. So as I mentioned, I has to call custom keyword from another custom keyword.

N%C3%A9vtelen


#56

@emine : I try something ike this: How to use @Keyword in other file


#57

@emine : Could you please share your sample project to try it on my side?


#58

hello @plaidshirtakos
As I have shown in the visual, I have 2 functions in a single custom keyword.


#59

Hi Friends,

Thanks in Advance

In my scenario: i need to upload a TXT file Through Windows Dialogue box .Auto IT Feature is not allowed in my Organization.

Can’t we upload without Auto IT.???

if so ,kindly suggest the code to keyin the file path into the windows dialogue box .

Scenario 2:If the Above Scenario Works, can we give path of the txt file from Excel File also…???

if it is yes …kindly suggest the way or code .

Thanq

with Regards,
Mikky…!


#60

hello @mikkili.rahul.tej
The following spelling will be useful.

You can also pull the file path from excel.

CustomKeywords. 'dosya.dosyayukleme.uploadFile(findTestObject(testobject),C: \ Users \ Desktop \ test data file )

In the test case step, you can point to the parameter in the excel data instead of the local file path as the second parameter.

First, create an excel locally and write the path information of the test file to txt and save it.

In the second step, as you can see in the screenshot, include this file in your Katalon project.

Finally, instead of directly typing the file path where you call custom keyword, you should pull it from excel.

CustomKeywords.‘dosya.dosyayukleme.uploadFile’(findTestObject(testobject), findTestData(‘New Test Data’).getValue(1, 1) )


#61

Hi Emine,

Thanq for the Response …

In my Scenario:I am using Iterations …as My data is 50 Rows in Excel and Each row will be having one TXT file .

Does ur Scenario Works for this design…??

Note:I am Already calling my excel data sheet from local drive.

Thanq

With Regards,
Mikky .