Skip to content

Commit 1d5e511

Browse files
committed
Trying to fix the browser component delay logic
1 parent e17ec30 commit 1d5e511

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

scripts/device-runner-app/tests/BaseTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ protected Form createForm(String title, Layout layout, final String imageName) {
1313
return new Form(title, layout) {
1414
@Override
1515
protected void onShowCompleted() {
16-
UITimer.timer(500, false, this, () -> {
16+
registerReadyCallbackthis, () -> {
1717
Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot(imageName);
1818
done = true;
1919
});
2020
}
2121
};
2222
}
2323

24+
protected void registerReadyCallback(Form parent, Runnable run) {
25+
UITimer.timer(500, false, parent, run);
26+
}
27+
2428
protected boolean waitForDone() {
2529
int timeout = 100;
2630
while(!done) {

scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,27 @@
44
import com.codename1.testing.TestUtils;
55
import com.codename1.ui.BrowserComponent;
66
import com.codename1.ui.Form;
7+
import com.codename1.ui.CN;
78
import com.codename1.ui.layouts.BorderLayout;
89

910
public class BrowserComponentScreenshotTest extends BaseTest {
11+
private BrowserComponent browser;
1012
@Override
1113
public boolean runTest() throws Exception {
1214
if (!BrowserComponent.isNativeBrowserSupported()) {
1315
return true;
1416
}
1517
Form form = createForm("Browser Test", new BorderLayout(), "BrowserComponent");
16-
BrowserComponent browser = new BrowserComponent();
18+
browser = new BrowserComponent();
1719
browser.setPage(buildHtml(), null);
1820
form.add(BorderLayout.CENTER, browser);
1921
form.show();
2022
return waitForDone();
2123
}
24+
25+
protected void registerReadyCallback(Form parent, final Runnable run) {
26+
browser.addWebEventListener(BrowserComponent.onLoad, evt -> CN.callSerially(run));
27+
}
2228

2329
private static String buildHtml() {
2430
return "<html><head><meta charset='utf-8'/>"

0 commit comments

Comments
 (0)