-
Notifications
You must be signed in to change notification settings - Fork 433
Fix CI screenshot capture on simulator #4113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix CI screenshot capture on simulator #4113
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| scenario.onActivity(activity -> Display.getInstance().callSerially(() -> { | ||
| try { | ||
| View root = activity.getWindow().getDecorView().getRootView(); | ||
| int w = root.getWidth(); | ||
| int h = root.getHeight(); | ||
| if (w <= 0 || h <= 0) { | ||
| DisplayMetrics dm = activity.getResources().getDisplayMetrics(); | ||
| w = Math.max(1, dm.widthPixels); | ||
| h = Math.max(1, dm.heightPixels); | ||
| int sw = View.MeasureSpec.makeMeasureSpec(w, View.MeasureSpec.EXACTLY); | ||
| int sh = View.MeasureSpec.makeMeasureSpec(h, View.MeasureSpec.EXACTLY); | ||
| root.measure(sw, sh); | ||
| root.layout(0, 0, w, h); | ||
| println("CN1SS:INFO:test=" + testName + " forced layout to " + w + "x" + h); | ||
| // Use Codename One screenshot API which properly captures PeerComponents | ||
| final com.codename1.ui.Image[] screenshotHolder = new com.codename1.ui.Image[1]; | ||
| Display.getInstance().screenshot(img -> { | ||
| screenshotHolder[0] = img; | ||
| }); | ||
|
|
||
| // Wait for screenshot to complete (with timeout) | ||
| long startTime = System.currentTimeMillis(); | ||
| while (screenshotHolder[0] == null) { | ||
| try { | ||
| Thread.sleep(50); | ||
| } catch (InterruptedException ie) { | ||
| Thread.currentThread().interrupt(); | ||
| break; | ||
| } | ||
| if (System.currentTimeMillis() - startTime > 5000) { | ||
| println("CN1SS:ERR:test=" + testName + " screenshot timeout"); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (screenshotHolder[0] == null) { | ||
| println("CN1SS:ERR:test=" + testName + " screenshot returned null"); | ||
| return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting loop blocks screenshot callback
The new screenshot logic calls Display.getInstance().screenshot() from inside a callSerially block and then busy‑waits with Thread.sleep() until the callback fills screenshotHolder. The screenshot task posts its callback back onto the Codename One EDT (Display.callSerially in AndroidScreenshotTask.postSuccess), but this loop is running on that same EDT. While the loop is sleeping, the EDT cannot execute the callback, so screenshotHolder never becomes non‑null and the loop always times out, leaving holder[0] unset and no screenshot captured. This breaks the test on all devices. The wait needs to occur off the EDT (e.g., by using invokeAndBlock or a latch completed from the screenshot callback) so the callback can run.
Useful? React with 👍 / 👎.
The CI instrumentation test was using Android's native View.draw() method to capture screenshots, which doesn't properly include PeerComponents like BrowserComponent (native WebView). This change updates the test to use Codename One's screenshot API (Display.getInstance().screenshot()) which properly captures native widgets via the AndroidScreenshotTask implementation that was fixed in PR #4107. Key changes: - Replace direct View.draw() with CN1 screenshot API - Add proper synchronization using CountDownLatch - Convert CN1 Image to Android Bitmap for encoding - Maintain same output format for CI pipeline compatibility This ensures BrowserComponent and other native widgets are now visible in CI screenshots.
6f512b9 to
2364454
Compare

The CI instrumentation test was using Android's native View.draw() method to capture screenshots, which doesn't properly include PeerComponents like BrowserComponent (native WebView).
This change updates the test to use Codename One's screenshot API (Display.getInstance().screenshot()) which properly captures native widgets via the AndroidScreenshotTask implementation that was fixed in PR #4107.
Key changes:
This ensures BrowserComponent and other native widgets are now visible in CI screenshots.