Katalon 自定义“uploadFiles”关键字不加载文件。
Katalon 网站声明 Katalon 关键字“ UploadFile ”仅在页面上存在标签时才有效(我的测试页面上不存在该标签)。
建议的解决方法是使用以下自定义关键字;我已添加到我的项目中。当我运行脚本时,“uploadFile”关键字会找到对象并打开“Windows 资源管理器”,然后就坐在那里。我认为问题在于“uploadFile”关键字从不将“文件”传递给“Windows Explorer”进行加载。Katalon 通过了这一步,因为它找到了对象。不知道为什么“关键字”不起作用......谁能看到我哪里出错了?
Package=tools.uploadFiles
//Added for uploadFiles keyword
import java.awt.Robot
import java.awt.Toolkit
import java.awt.datatransfer.StringSelection
import java.awt.event.KeyEvent
public class uploadFiles {
@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);
}
}
//Added the following lines to the script's "import" header section
import com.kms.katalon.core.annotation.Keyword as Keyword
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
//Script test steps
WebUI.openBrowser('')
WebUI.navigateToUrl(GlobalVariable.testURL)
WebUI.maximizeWindow()
WebUI.delay(GlobalVariable.shortDelay)
调用关键字的行:CustomKeywords.'tools.uploadFiles.uploadFile'(findTestObject('FILE_UPLOAD/Page_VirtualWealth/UploadFile0'),'C:\\Users\\eversda\\Downloads\\TestFiles\\BlankCheque.png')
谢谢戴夫