如何处理卡塔隆工作室的Zoho CRM自动完成案例
我要测试的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
}
这似乎是答案,直到我一直在处理,关闭几个月...
...它选择“选择”错误的“下拉选项!例如,在会员类别自动完成中,我们键入“会员资格”,然后在第一个成员类别下拉选项可用之前,它将选择[具有“成员资格”的其他下拉选项。
昨晚,我直到凌晨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);
}
这是地狱的速度,而不是默默地执行不正确的行为(即选择错误的下拉选项),而是会引发异常。它应该只是工作!!! (似乎实际的下拉选项尚未准备好在我们进行检查时检查...)
来对其进行补救
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);
}
我尝试通过调整waitforelementHastext()
:没有骰子 。它有时仍然会失败,并且似乎对此我无法做任何该死的事情。...
或者在那里?
除了切换到更复杂的模态视图之外,我们可以一劳永逸地处理自动完成吗?
I'm at an impasse on this ever-present autocomplete widget in the Zoho app that I'm to test. It pops up on the CRM pages under test, and to handle it, I had the following util method:
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
}
This seemed like the answer, until I have been dealing with, off and on for several month...
...it select "the wrong" dropdown option! For example, on a membership category autocomplete, we type in "Membership", and it would select [some other dropdown option with "Membership" in the name], before the first member category dropdown option became available.
Last night, I was up til 2am working on this and test cases that were using it. I ended up changing the code to:
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);
}
This is way the hell faster, and instead of silently doing incorrect behavior (i.e. selecting the wrong dropdown option), it will throw exception. It should just work!!! (It seems like the actual dropdown option isn't ready to be checked by the time we go to check it...)
I tried remedying it by tweaking 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);
}
No dice. It will still sometimes fail, and there doesn't seem to be a damn thing I can do about it....
....or is there?
How, outside of switching to modal view, which is more complicated to handle, can we handle the autocomplete once and for all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论我多么努力,我都无法以传统的方式解决这一点:使用策略模式。
为什么?因为,当我去记录
dropdownoption
和loader
的初始状态时,无论自动完整处理程序是否最终会成功或失败,它们都是完全相同的。看来我无法控制
dropdownoption
“闪烁”即使我们等待它存在!因此,我必须发挥创意:
重新进行测试多次,一切都很好!
No matter how hard I tried, I couldn't solve this the traditional way: using strategy patterns.
Why? Because, when I went to log the initial states of
dropdownOption
andloader
, they were the exact same, regardless of whether the autocomplete handler was going to end up succeeding, or failing.It looks like I have no control over the
dropdownOption
"flickers" even after we wait on it to exist!So, I had to get creative:
re-ran the test several times, and all was well!