Uploading file error

Hello!

Today i try to make automatically upload files my TestCase

  import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
  WebUI.openBrowser('https://transfer.pcloud.com/')
  CustomKeywords.'test.WebUICustomKeyword.uploadFile'(findTestObject('Page_Send large files up to 5GB for free/span_Click here to add files'), 'C:\\Users\\Desktop\\Captcha\\Captcha3.jpg') 

and my keyword is:

package test
   import java.awt.datatransfer.StringSelection

   import com.kms.katalon.core.annotation.Keyword
   import com.kms.katalon.core.testobject.TestObject
   import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
   import com.sun.media.sound.Toolkit
   import com.thoughtworks.selenium.webdriven.commands.KeyEvent
   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.delay(1000); //Millisecond 1 second delay only if needed
   		robot.keyPress(KeyEvent.VK_CONTROL);
   		robot.keyPress(KeyEvent.VK_V);
   		robot.keyRelease(KeyEvent.VK_V);
   		robot.delay(1000); //Millisecond 1 second delay only if needed
   		robot.keyRelease(KeyEvent.VK_CONTROL);
   		robot.keyPress(KeyEvent.VK_ENTER);
   		robot.keyRelease(KeyEvent.VK_ENTER);
   	}
   }

everything seems to be very easy, but i don’t know why i get the following error

     2019-08-23 12:52:08.851 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/upload_test/Upload FAILED.
     Reason:
     org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: static com.sun.media.sound.Toolkit.getDefaultToolkit() is applicable for argument types: () values: []
     	at test.WebUICustomKeyword.invokeMethod(testclass.groovy)
     	at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50)
     	at Upload.run(Upload:7)
     	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
     	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
     	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
     	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
     	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
     	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
     	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
     	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
     	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
     	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
     	at TempTestCase1566553918955.run(TempTestCase1566553918955.groovy:21)
     Caused by: groovy.lang.MissingMethodException: No signature of method: static com.sun.media.sound.Toolkit.getDefaultToolkit() is applicable for argument types: () values: []
     	at test.WebUICustomKeyword.uploadFile(testclass.groovy:16)
     	... 14 more
1 Like

@kazurayam @Russ_Thomas @devalex88 and any … perhaps we should pin this too? even if i attempt to edit an OP post like this, if the format is already broken the result will equal to null …

don’t understand =)

@arturs.pumpa you pasted your code as a quote. that’s why the indentation is broken and the code is hard to read. if you use triple quoting like this:


def something
   some code here

is more readable.unfortunatley i can only copy your code now, whitout indentation. so i cannot make it better

1 Like

i got it =) thank you

2 Likes

@arturs.pumpa yeeey, now looks beautifull!

1 Like

Hi. You’ve imported the wrong class - com.sun.media.sound.Toolkit should be java.awt.Toolkit.

1 Like