Katalon使用自定义关键字实现下载(Assert Statement)
该图是完整的下载流程:
操作步骤如下:
1.在keywords-testclass(右键-new-keyword)-myKeywords(输入名称,不选择任何筛选项,点击报错)
mykeywords文件下输入js代码:
package testclass 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 static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject 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 com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows import internal.GlobalVariable public class myKeywords { @Keyword def boolean isFileExist(String filePath,String fileName) { boolean flag = false File dir = new File(filePath) File[] dir_contents = dir.listFiles() for(int i = 0;i < dir_contents.length; i++) { println('File Name at 0 is :' + dir_contents[i].getName()) if(dir_contents[i].getName().contains(fileName)) { return flag = true } } return flag } }
需要提前配置内容:
点击如下:Project-settings-Desired Capabilities
点击add:(备注:直接复制Name后面的内容就行)
Name=prefs
Type=Dictionary;
点击Value:
点击add:()
name=profile.default_content_settings.popups
Type=Number
Value:0.0
在点击add:
name=download.default_directory
Type=String
Value=D:\Katalon---\upload
进行保存