Skip to content

Commit f399299

Browse files
Fix BrowserTest screenshot timing issue (#4329)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent d43688a commit f399299

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/BrowserComponentScreenshotTest.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
import com.codename1.ui.Form;
55
import com.codename1.ui.layouts.BorderLayout;
66
import com.codename1.ui.util.UITimer;
7+
import com.codename1.util.SuccessCallback;
78

89
public class BrowserComponentScreenshotTest extends BaseTest {
910
private BrowserComponent browser;
1011
private boolean loaded;
1112
private Runnable readyRunnable;
1213
private Form form;
14+
private boolean jsReady;
15+
private boolean jsCheckPending;
1316

1417
@Override
1518
public boolean runTest() throws Exception {
@@ -36,10 +39,25 @@ protected void registerReadyCallback(Form parent, final Runnable run) {
3639
}
3740

3841
private void checkReady() {
39-
if (loaded && readyRunnable != null) {
40-
UITimer.timer(500, false, form, readyRunnable);
41-
readyRunnable = null;
42+
if (!loaded || readyRunnable == null) {
43+
return;
4244
}
45+
if (!jsReady) {
46+
if (!jsCheckPending) {
47+
jsCheckPending = true;
48+
// Verify content is actually present in the DOM
49+
browser.execute("callback.onSuccess(document.body.innerText)", new SuccessCallback<BrowserComponent.JSRef>() {
50+
public void onSucess(BrowserComponent.JSRef result) {
51+
jsReady = true;
52+
checkReady();
53+
}
54+
});
55+
}
56+
return;
57+
}
58+
59+
UITimer.timer(2000, false, form, readyRunnable);
60+
readyRunnable = null;
4361
}
4462

4563
private static String buildHtml() {

0 commit comments

Comments
 (0)