@@ -29,19 +29,23 @@ public class @MAIN_NAME@UiTest {
2929
3030 @Test
3131 public void mainFormScreenshotContainsRenderedContent() throws Exception {
32+ log("Starting Robolectric activity for screenshot test");
3233 ActivityController<@MAIN_NAME@Stub> controller = Robolectric.buildActivity(@
[email protected] ).setup().visible();
3334 try {
35+ log("Waiting for Codename One main form to be displayed");
3436 Form displayed = waitForDisplayedForm(5000L);
3537 assertNotNull("Codename One form should be displayed", displayed);
3638
3739 @MAIN_NAME@Stub activity = controller.get();
40+ log("Captured Codename One form; capturing decor view screenshot");
3841 Bitmap screenshot = captureScreenshot(activity);
3942 assertNotNull("Screenshot capture should succeed", screenshot);
4043 assertTrue("Screenshot width should be positive", screenshot.getWidth() > 0);
4144 assertTrue("Screenshot height should be positive", screenshot.getHeight() > 0);
4245 assertTrue("Screenshot should contain rendered content beyond the background", hasRenderableContent(screenshot));
4346
4447 File screenshotFile = saveScreenshot(screenshot);
48+ log("Screenshot stored at " + screenshotFile.getAbsolutePath());
4549 assertTrue("Screenshot file should exist", screenshotFile.isFile());
4650 assertTrue("Screenshot file should not be empty", screenshotFile.length() > 0L);
4751 } finally {
@@ -51,6 +55,7 @@ public class @MAIN_NAME@UiTest {
5155
5256 private static Form waitForDisplayedForm(long timeoutMillis) throws InterruptedException {
5357 long deadline = SystemClock.uptimeMillis() + timeoutMillis;
58+ long nextLog = SystemClock.uptimeMillis();
5459 while (SystemClock.uptimeMillis() < deadline) {
5560 ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
5661 if (Display.isInitialized()) {
@@ -60,6 +65,11 @@ public class @MAIN_NAME@UiTest {
6065 }
6166 }
6267 Thread.sleep(50L);
68+ long now = SystemClock.uptimeMillis();
69+ if (now >= nextLog) {
70+ log("Still waiting for Codename One form; displayInitialized=" + Display.isInitialized());
71+ nextLog = now + 1000L;
72+ }
6373 }
6474 throw new AssertionError("Timed out waiting for Codename One form to be displayed");
6575 }
@@ -117,6 +127,7 @@ public class @MAIN_NAME@UiTest {
117127
118128 private static View waitForDecorViewWithDimensions(@MAIN_NAME@Stub activity, long timeoutMillis) throws InterruptedException {
119129 long deadline = SystemClock.uptimeMillis() + timeoutMillis;
130+ long nextLog = SystemClock.uptimeMillis();
120131 while (SystemClock.uptimeMillis() < deadline) {
121132 View decorView = activity.getWindow().getDecorView();
122133 if (decorView != null) {
@@ -127,6 +138,12 @@ public class @MAIN_NAME@UiTest {
127138 }
128139 ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
129140 Thread.sleep(50L);
141+ long now = SystemClock.uptimeMillis();
142+ if (now >= nextLog) {
143+ log("Waiting for decor view layout; width=" + (decorView != null ? decorView.getWidth() : 0)
144+ + " height=" + (decorView != null ? decorView.getHeight() : 0));
145+ nextLog = now + 1000L;
146+ }
130147 }
131148 throw new AssertionError("Timed out waiting for decor view layout");
132149 }
@@ -141,4 +158,8 @@ public class @MAIN_NAME@UiTest {
141158 view.measure(widthSpec, heightSpec);
142159 view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
143160 }
161+
162+ private static void log(String message) {
163+ System.out.println("[@MAIN_NAME@UiTest] " + message);
164+ }
144165}
0 commit comments