【问题标题】:How to verify text in a spinner/loader?如何验证微调器/加载器中的文本?
【发布时间】:2019-09-12 16:02:30
【问题描述】:

我正在尝试捕获并验证单击链接后出现在微调器中的文本。是否可以在 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' );
            }

微调器显示文本“System Activity Loading... Please Wait :)”,这是我需要在 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

有什么想法吗?

【问题讨论】:

    标签: katalon-studio


    【解决方案1】:

    您收到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 文档。

    【讨论】:

    • 我尝试了上面的代码并得到了关于“无法获取对象文本”的相同错误。由于点击链接后会出现微调器,因此是否需要将 waitForElementVisible 放置在脚本中而不是关键字中?
    • 您也可以将等待放入脚本中。尝试手动运行脚本时确定该元素存在吗?也有可能该元素位于单击链接后打开的 iframe 内。
    • 我也将等待放入脚本中并得到了同样的错误。在引用自定义关键字之前,它是否必须放在脚本的开头?尝试手动运行脚本时,该元素就在那里。有一种叫做“bgiframe:true”的东西,我认为它与 iframe 不同,但如果我错了,请纠正我。
    • 您可以在与元素交互之前放置等待条件。此外,如果那是 iframe,请在等待之前添加 WebUI.switchToFrame() 命令。如果您需要更多详细信息,则需要共享相关页面的 HTML。
    • 我确认页面上没有 iframe。我分享了上面的一些 HTML 代码,所以我不确定你还想看到多少代码。告诉我,我会分享。
    猜你喜欢
    • 2014-12-07
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2013-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多