Skip to content

Commit ab1582c

Browse files
committed
Simplify iOS screenshot pipeline
1 parent 7462daa commit ab1582c

File tree

3 files changed

+113
-274
lines changed

3 files changed

+113
-274
lines changed

docs/demos/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<module>common</module>
2020
</modules>
2121
<properties>
22-
<cn1.plugin.version>7.0.208</cn1.plugin.version>
23-
<cn1.version>7.0.208</cn1.version>
22+
<cn1.plugin.version>7.0.209</cn1.plugin.version>
23+
<cn1.version>7.0.209</cn1.version>
2424
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2525
<java.version>1.8</java.version>
2626
<java-tests.version>11</java-tests.version>

scripts/ios/tests/HelloCodenameOneUITests.swift.tmpl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ final class HelloCodenameOneUITests: XCTestCase {
3737
}
3838

3939
private func captureScreenshot(named name: String) throws {
40-
let shot = XCUIScreen.main.screenshot()
40+
let shot = bestScreenshot()
4141

4242
// Save into sandbox tmp (optional – mainly for local debugging)
4343
let pngURL = outputDirectory.appendingPathComponent("\(name).png")
@@ -52,6 +52,24 @@ final class HelloCodenameOneUITests: XCTestCase {
5252
emitScreenshotPayloads(for: shot, name: name)
5353
}
5454

55+
private func bestScreenshot() -> XCUIScreenshot {
56+
let screenShot = XCUIScreen.main.screenshot()
57+
let appShot = app.screenshot()
58+
let screenBytes = screenShot.pngRepresentation.count
59+
let appBytes = appShot.pngRepresentation.count
60+
61+
if appBytes > screenBytes && appBytes > 0 {
62+
return appShot
63+
}
64+
if screenBytes == 0 && appBytes > 0 {
65+
return appShot
66+
}
67+
if appBytes == 0 && screenBytes > 0 {
68+
return screenShot
69+
}
70+
return screenBytes >= appBytes ? screenShot : appShot
71+
}
72+
5573
/// Wait for foreground + a short settle time
5674
private func waitForStableFrame(timeout: TimeInterval = 30, settle: TimeInterval = 1.2) {
5775
_ = app.wait(for: .runningForeground, timeout: timeout)

0 commit comments

Comments
 (0)