groovy.lang.MissingMethodException:没有方法签名:使用机械手类上传文件时出现以下错误

时间:2019-05-02 09:22:58

标签: selenium groovy katalon-studio

我正在尝试使用机械手类从本地计算机上载文件,但出现以下错误。

  

groovy.lang.MissingMethodException:方法的无签名:java.awt.datatransfer.StringSelection.positive()适用于参数类型:()值:[]   可能的解决方案:notify()

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
import java.awt.Robot
import java.awt.Toolkit
//import java.awt.datatransfer.Clipboard
import java.awt.datatransfer.StringSelection
import java.awt.event.KeyEvent

public class RobotClass {
    @Keyword
    def uploadFile(TestObject to, String filePath) {
        WebUI.click(to)
        StringSelection ss = new StringSelection(filePath);
        //r=java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
        println "The copied path is" :+ss
        /*  Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
         // clipboard.setContents(ss, null);*/
        println "The clipboard is " +clipboard
        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_CONTROL);
        robot.keyRelease(KeyEvent.VK_V);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
    }

=============================

Calling this tc: 

    CustomKeywords.'custom.RobotClass.uploadFile'(findTestObject('Object'), "Path")

1 个答案:

答案 0 :(得分:1)

您有错字

println "The copied path is" :+ss

应该是

println "The copied path is:" + ss