Skip to content

Conversation

@shai-almog
Copy link
Collaborator

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.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

Comment on lines 89 to 117
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@shai-almog
Copy link
Collaborator Author

shai-almog commented Nov 8, 2025

Android screenshot updates

  • BrowserComponent — updated screenshot. Screenshot differs (320x616 px, bit depth 8).

    BrowserComponent
    Preview info: JPEG preview quality 70; JPEG preview quality 70.
    Full-resolution PNG saved as BrowserComponent.png in workflow artifacts.

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.
@shai-almog shai-almog force-pushed the claude/ci-simulator-screenshot-011CUvE5gnvjdJLcSK33z9BK branch from 6f512b9 to 2364454 Compare November 8, 2025 10:14
@shai-almog shai-almog merged commit e4ae347 into master Nov 8, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants