Skip to content

Commit

Permalink
fine tune waitRespone() for more stable and add client mvvm detection
Browse files Browse the repository at this point in the history
  • Loading branch information
jumperchen committed Nov 5, 2024
1 parent 8fbe211 commit 4b5bc9b
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/main/java/org/zkoss/test/webdriver/BaseTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public WebDriver connect(String location) {
}
webDriver.get(loc);
}

waitForAjaxResponse(2, getTimeout(), System.currentTimeMillis(), "!window.zk || window.zk.loading");
return webDriver;
}

Expand Down Expand Up @@ -347,25 +347,36 @@ protected int getSpeed() {
*
*/
protected void waitResponse(int timeout, boolean includingAnimation) {
long s = System.currentTimeMillis();
int i = 0;
int ms = getSpeed();

String scripts = includingAnimation ? "!!zAu.processing() || !!jq.timers.length" : "!!zAu.processing()";
sleep(getSpeed() / 2); // take a break first.
String defaultScript = "!!zAu.processing() || (window.mobx && window.mobx._getGlobalState() && window.mobx._getGlobalState().isRunningReactions)";
waitForAjaxResponse(getRetryCount(includingAnimation), timeout, System.currentTimeMillis(),
includingAnimation
? defaultScript + " || !!jq.timers.length"
: defaultScript);
}

sleep(ms / 2); // take a break first.
/**
* Returns the retry count for waiting for Ajax response.
* Default: 3 and if including animation, 5.
*/
protected int getRetryCount(boolean includingAnimation) {
return includingAnimation ? 5 : 3;
}

while (i < 2) { // make sure the command is triggered.
while (Boolean.valueOf(this.getEval(scripts))) {
if (System.currentTimeMillis() - s > timeout) {
assertTrue(false, "Test case timeout!");
private void waitForAjaxResponse(int loopCount, int timeout, long startTime, String waitForScript) {
int ms = getSpeed();
int i = 0;
while (i < loopCount) { // make sure the command is triggered.
while (Boolean.parseBoolean(getEval(waitForScript))) {
if (System.currentTimeMillis() - startTime > timeout) {
fail("Test case timeout!");
break;
}
i = 0;//reset
i = 0; // reset
sleep(ms);
}
i++;
sleep(includingAnimation ? ms * 2 : ms);
sleep(ms);
}
}

Expand Down

0 comments on commit 4b5bc9b

Please sign in to comment.