katalon-studio - 如何使用关键字验证页面上的文本?
问题描述
我正在尝试验证微调器完成加载后出现的页面上的一些文本。是否可以在 Katalon 中执行此类测试?
我尝试创建一个关键字然后使用它,但不知道下一步该做什么。
public class ModuleKeywords {
@Keyword
def myText(String){
myText = WebUI.getText(findTestObject('Object Repository/WMS/Page_/li_System Activity'))
return myText
}
}
def sysText = CustomKeywords.'com.wms.modules.general.ModuleKeywords.myText'()
if (sysText == 'System Activity') {
println("The text displayed is = " + sysText)
}
else
println('Activity page did not load')
我希望代码能够在单击链接并完成加载微调器后在页面上找到并验证文本“系统活动”。
运行脚本后出现以下错误:2019-09-10 13:52:42.921 错误 kkcmCustomKeywordDelegatingMetaClass - ❌ 没有此类属性:myText for class: com.wms.modules.general.ModuleKeywords 2019-09-10 13:52: 42.925 错误 ckkatalon.core.main.TestCaseExecutor - ❌ 测试用例/回归/WMS/C16320 - 活动模块失败。原因:groovy.lang.MissingPropertyException:没有这样的属性:类的 myText:com.wms.modules.general.ModuleKeywords.myText(ModuleKeywords.groovy:26) 在 com.wms.modules 的 com.wms.modules.general.ModuleKeywords .general.ModuleKeywords.invokeMethod(ModuleKeywords.groovy) 在 com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50) 在 C16320 - Activity Module.run(C16320 - Activity Module:23) 在 com。 kms.katalon.core.main.ScriptEngine。
解决方案
There is some confusion on what myText
means. It is unclear if it is a method name or a property name.
So, I suggest you change the name of the text variable (I'll name it just text
) inside of your method. Be sure to add the def
keyword, as well.
Finally, when writing a method with this signature def myText(String)
you are saying the method accepts a string parameter, but you are not providing the parameter in your example so it is not needed.
Your method will then look like this:
@Keyword
def myText(){
def text = WebUI.getText(findTestObject('Object Repository/WMS/Page_/li_System Activity'))
return text
}
推荐阅读
- angular - 如何从 Angular(或另一个 SPA)对 Asp.Net Core Identity 进行身份验证?
- typescript - 输入 'ClassA<{ id: number; 名称:字符串;}>' 不可分配给类型 'ClassA
>' - java - 如何从字符串中删除字母值以及如何在描述中获得所需的字符串?
- powerbi - TopN 品牌与图例条形图
- gremlin - 为什么 Gremlin Server / JanusGraph 会忽略我的一些请求?
- javascript - 设置活动工作表未在 UI 中打开工作表
- python - Python Xarray 相关(corr)函数给出了不需要的输出
- google-apps-script - getRange 和 setValues 函数返回数据和列数之间的不匹配
- r - normalizePath("report.Rmd") 中的警告:path[1]="report.Rmd": No such file or directory
- html - Base64 PDF 无法在基于 Chromium 的浏览器上打开