Katalon custom" uploadFiles"关键字不加载文件

时间:2018-01-22 02:04:16

标签: testing automation web-testing katalon-studio

Katalon custom" uploadFiles"关键字未加载文件。

Katalon网站指出Katalon关键字" UploadFile "当标记存在于页面上时,会工作(标记在我的测试页上存在 NOT )。

建议的解决方法是使用以下自定义关键字;我已添加到我的项目中。当我运行脚本时," uploadFile" keyword找到对象并打开" Windows资源管理器" &安培;就坐在那里我认为问题在于" uploadFile"关键字永远不会传递"文件"到" Windows资源管理器"用于装载。 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 \\下载\\ TestFiles \\ BlankCheque.png&#39)

Windows Explorer opens without file name

谢谢戴夫

1 个答案:

答案 0 :(得分:1)

<强>&#34; uploadFiles&#34;现在可以解决一些问题

Keywords.tools.uploadFiles.groovy
//Added for use with "uploadFiles"
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.delay(1000)
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_V);
    robot.delay(1000)
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);        
    }
}

注意:确保使用正确的对象定位器,在我的情况下,以下情况适用于&#34; label_upload fa fa-upload fa-l&#34;

// [@ class =&#39; upload fa fa-upload fa-lg pull-right&#39;] [count(。| // [@ for =&#39; chooseFile0&#39;])= count(// * [@ for =&#39; chooseFile0&#39;])]

脚本标题......

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

脚本摘要......

WebUI.delay(GlobalVariable.shortDelay) WebUI.comment(&#39;在脚本运行时不要点击进入Katalon。这样做会导致uploadFiles无法正常工作。&#39;)

CustomKeywords。&#39; tools.uploadFiles.uploadFile&#39;(findTestObject(&#39; FILE_UPLOAD / Page_VirtualWealth / label_upload fa fa-upload fa-l&#39;),     &#39; C:\ Users \用户jd​​oe的\下载\ TestFiles \ TestLicense.jpg&#39;) Thread.sleep(2000)//等待&#34;打开&#34;对话

WebUI.switchToWindowIndex(&#39; 0&#39)

CustomKeywords。&#39; tools.uploadFiles.uploadFile&#39;(findTestObject(&#39; FILE_UPLOAD / Page_VirtualWealth / label_upload fa fa-upload fa-l2&#39;),     &#39; C:\ Users \用户jd​​oe的\下载\ TestFiles \ TestPassport.png&#39;) Thread.sleep(2000)//等待&#34;打开&#34;对话

WebUI.switchToWindowIndex(0)

CustomKeywords。&#39; tools.uploadFiles.uploadFile&#39;(findTestObject(&#39; FILE_UPLOAD / Page_VirtualWealth / label_upload fa fa-upload fa-l_1&#39;),     &#39; C:\ Users \用户jd​​oe的\下载\ TestFiles \ Bank.pdf&#39;) Thread.sleep(2000)//等待&#34;打开&#34;对话

WebUI.switchToWindowIndex(0)

CustomKeywords。&#39; tools.uploadFiles.uploadFile&#39;(findTestObject(&#39; FILE_UPLOAD / Page_VirtualWealth / label_upload fa fa-upload fa-l_12&#39;),     &#39; C:\ Users \用户jd​​oe的\下载\ TestFiles \ Bill.pdf&#39;) Thread.sleep(2000)//等待&#34;打开&#34;对话

WebUI.switchToWindowIndex(0) ...