如何在微调器/加载器中验证文本?

时间:2019-09-12 16:02:30

标签: katalon-studio

我试图捕获并验证单击链接后出现在微调器中的文本。是否可以在Katalon中进行此类测试?

我创建了以下关键字:

@Keyword
    def activitySpinner(){

        def activSpinner = WebUI.getText(findTestObject('Object Repository/WMS/Page_Dashboard/div_System Activity Loading Please Wait )'))
        return activSpinner
    }

然后我尝试使用以下脚本使用关键字:

def actSpinner = CustomKeywords.'com.wms.modules.general.ModuleKeywords.activitySpinner'()

if (WebUI.verifyMatch(actSpinner, 'System Activity Loading... Please Wait :).*', true, FailureHandling.STOP_ON_FAILURE)){
    println("The spinner shows the text: " + actSpinner)
}

DOM显示以下内容:

<script type="text/javascript" src="http://10.150.2.43:10093/js/jquery/jquery.page.1562162263.js"></script>

当我右键单击并打开上面的内容时,该特定链接会显示以下内容:

$j(document).on("click", "#system_activity", function() {
            showLoader('System Activity Loading...');
            window.location=BASE_URL + "erp/wms/statistics";

“请稍等:)”部分显示在页面上:

function showLoader(msgText,visible){

            if(typeof(msgText)==='undefined') msgText = "Loading...";
            var theme = "a",
            textVisible = true,
            textonly = false;
            html = "";
            msgText = msgText + ' Please Wait :)';
            if(typeof(visible)==='undefined'){
                $j.mobile.loading( 'show', {
                    text: msgText,
                    textVisible: textVisible,
                    theme: theme,
                    textonly: textonly,
                    html: html
                });
            }else{
                $j.mobile.loading( 'hide' );
            }

微调器显示文本“正在加载系统活动...,请稍候:)”,这是我需要在Katalon Studio中验证的内容,但是在运行脚本后出现以下错误:

09-12-2019 10:55:07 AM Test Cases/regression/WMS/C16320 - Activity Module

Elapsed time: 1m - 4.408s

com.wms.modules.general.ModuleKeywords.activitySpinner:92

com.wms.modules.general.ModuleKeywords.invokeMethod:0

Test Cases/regression/WMS/C16320 - Activity Module FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to get text of object 'Object Repository/WMS/Page_Dashboard/div_System Activity Loading Please Wait )'
    at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
    at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
    at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword.getText(GetTextKeyword.groovy:88)
com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
    at TempTestCase1568303703564.run(TempTestCase1568303703564.groovy:21)
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'Object Repository/WMS/Page_Dashboard/div_System Activity Loading Please Wait )' located by 'By.xpath: //*[(text() = 'System Activity Loading... Please Wait :)' or . = 'System Activity Loading... Please Wait :)')]' not found

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您将获得com.kms.katalon.core.webui.exception.WebElementNotFoundException异常,该异常基本上表明元素当时不在DOM中。可能尚未加载。

首先,由于我不确定findTestObject('Object Repository/WMS/Page_Dashboard/div_System Activity Loading Please Wait )')是否正确定义了元素,所以让我们用以下内容进行更改:

TestObject spinner = new TestObject().addProperty("css", ConditionType.EQUALS, ".ui-icon-loading")

下一步是尝试获取元素文本之前添加一个等待条件(等待30秒钟,元素出现)。两者结合会导致类似的情况

@Keyword
def activitySpinner(){
    WebUI.waitForElementVisible(spinner, 30)
    def activSpinner = WebUI.getText(spinner)
    return activSpinner
}

WebUI.waitForElementVisible()的Katalon文档。