簡體   English   中英

如何在 Katalon Studio 測試用例中處理 Zoho CRM 自動完成

[英]How to handle a Zoho CRM autocomplete in Katalon Studio test cases

對於我要測試的 Zoho 應用程序中這個始終存在的自動完成小部件,我陷入了僵局。 它會在正在測試的 CRM 頁面上彈出,為了處理它,我使用了以下 util 方法:

public final class GeneralWebUIUtils {

   // ... other utils

   public static void HandleAutoComplete(TestObject textField, String input, TestObject loader, TestObject dropdownOption, boolean doScroll = false) {
        WebUI.click(textField)

        WebUI.setText(textField, input)

        TimeLoggerUtil.LogAction({
            WebUI.waitForElementVisible(loader, 3)

            // TODO: somehow this is not working for state; // it ends up selecting the first dropdown value
            return WebUI.waitForElementNotVisible(loader, 3)
        },
        "Loader",
        "appear and disappear");

        // TODO: do we really need if-condition here?
        if (doScroll) {
            this.ScrollDropdownOptionIntoView(dropdownOption)
        }

        WebUI.waitForElementVisible(dropdownOption, 3, FailureHandling.STOP_ON_FAILURE)

        WebUI.click(dropdownOption)
    }

   public static void ScrollDropdownOptionIntoView(TestObject to) {
        WebUI.executeJavaScript("arguments[0].scrollIntoView({block: 'center'})", [WebUiCommonHelper.findWebElement(to, 1)])
    }

    // ... other util methods
}

這似乎是答案,直到我斷斷續續地處理了幾個月......

...它是 select“錯誤的”下拉選項,例如,在會員類別自動完成中,我們輸入“會員資格”,它會是 select [其他一些名稱中帶有“會員資格”的下拉選項]。 在第一個成員類別下拉選項可用之前。

昨晚,我一直忙到凌晨 2 點才處理這個和正在使用它的測試用例。 我最終將代碼更改為:

public static void HandleAutoComplete(TestObject textField, String input, TestObject loader, TestObject dropdownOption, boolean doScroll = false) throws StepFailedException {
        WebUI.click(textField)

        WebUI.setText(textField, input)

        TimeLoggerUtil.LogAction({
            return WebUI.waitForElementNotVisible(loader, 3)
        },
        "Loader",
        "disappear");

        // TODO: do we really need if-condition here?
        if (doScroll) {
            this.ScrollDropdownOptionIntoView(dropdownOption)
        }

        TimeLoggerUtil.LogAction({
            WebUI.waitForElementVisible(dropdownOption, 3);
            return this.WaitForElementHasText(dropdownOption, input, 5, FailureHandling.STOP_ON_FAILURE);
        },
        "Dropdown option",
        "become visible")

        WebUI.verifyElementText(dropdownOption, input)

        WebUI.click(dropdownOption)
    }

   public static boolean WaitForElementCondition(Closure<Boolean> onCheckCondition, TestObject to, int timeOut, FailureHandling failureHandling = FailureHandling.STOP_ON_FAILURE) {
        final long startTime = System.currentTimeMillis()
        boolean isConditionSatisfied = false;
        while ((System.currentTimeMillis() < startTime + timeOut * 1000) && (!isConditionSatisfied)) {
            isConditionSatisfied = onCheckCondition(to);
        }
        if ((!isConditionSatisfied) && (failureHandling.equals(FailureHandling.STOP_ON_FAILURE))) {
            KeywordUtil.markFailedAndStop("Condition for TestObject '${to.getObjectId()}' not met after ${(System.currentTimeMillis() - startTime) / 1000} seconds");
        }
        return isConditionSatisfied;
    }

   public static boolean WaitForElementHasText(TestObject to, String expectedText, int timeOut, FailureHandling failureHandling = FailureHandling.STOP_ON_FAILURE) {
        return this.WaitForElementCondition({ TestObject testObj ->
            return WebUI.getText(testObj).contains(expectedText);
        },
        to,
        timeOut,
        failureHandling);
    }

這真是太快了,而且它不會默默地做不正確的行為(即選擇錯誤的下拉選項),而是會拋出異常。 它應該可以正常工作......(看起來實際的下拉選項還沒有准備好在我們 go 檢查它時檢查它......)

我嘗試通過調整WaitForElementHasText()來補救它:

public static boolean WaitForElementHasText(TestObject to, String expectedText, int timeOut, FailureHandling failureHandling = FailureHandling.STOP_ON_FAILURE) {
        return this.WaitForElementCondition({ TestObject testObj ->
            return WebUI.verifyElementPresent(testObj, 1) && WebUI.getText(testObj).contains(expectedText);
        },
        to,
        timeOut,
        failureHandling);
    }

沒有骰子。 它有時仍然會失敗,而且我似乎對此無能為力......

....或者有嗎?

除了切換到處理起來更復雜的模式視圖之外,我們如何一勞永逸地處理自動完成?

無論我多么努力,我都無法通過傳統方式解決這個問題:使用策略模式。

為什么? 因為,當我去記錄dropdownOptionloader的初始狀態時,它們完全相同,無論自動完成處理程序最終是成功還是失敗。

看起來我無法控制dropdownOption “閃爍”,即使我們等待它存在!

所以,我必須發揮創意:

   public static boolean WaitForElementCondition(Closure<Boolean> onCheckCondition, Closure onContinue, TestObject to, int timeOut, FailureHandling failureHandling = FailureHandling.STOP_ON_FAILURE) {
        final long startTime = System.currentTimeMillis()
        boolean isConditionSatisfied = false;
        while ((System.currentTimeMillis() < startTime + timeOut * 1000) && (!isConditionSatisfied)) {
            isConditionSatisfied = onCheckCondition(to);
            onContinue(isConditionSatisfied, to);
        }
        if ((!isConditionSatisfied) && (failureHandling.equals(FailureHandling.STOP_ON_FAILURE))) {
            KeywordUtil.markFailedAndStop("Condition for TestObject '${to.getObjectId()}' not met after ${(System.currentTimeMillis() - startTime) / 1000} seconds");
        }
        return isConditionSatisfied;
    }

   public static boolean WaitForElementHasText(TestObject to, String expectedText, int timeOut, FailureHandling failureHandling = FailureHandling.STOP_ON_FAILURE) {
        return this.WaitForElementCondition({ TestObject testObj ->
            return WebUI.getText(testObj).contains(expectedText);
        },
        { boolean success, TestObject tObj ->
            if (!success) {
                WebUI.waitForElementNotPresent(tObj, 1);

                WebUI.waitForElementPresent(tObj, timeOut);
            }
        },
        to,
        timeOut,
        failureHandling);
    }

重新運行了幾次測試,一切都很好!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM