Skip to content
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

Code to create screenshots #72

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,28 @@ Models used throughout the app.
### NotificationClient

Schedules reminders for when network configurations expire.

## Creating screenshots

To facilitate creating screenshots for the App Store, use these steps:

1. In MainView.swift: comment out sending the `searchQueryChangeDebounced` action
2. In Screenshots.swift: verify `screenshotsFolder` goes to an existing folder
3. Select the `geteduroam/getgovroam Screenshots` target
4. Select the desired destination
5. Use Product > Test (cmd-U)

If the tests hang, try running the app on that particular simulator first. Check that the simulator is in the desired orientation: portrait for this app.

Refer to the [Screenshot specifications](https://developer.apple.com/help/app-store-connect/reference/screenshot-specifications) to pick the desired destinations.

Currently we use:

- iPhone 15 Pro Max
- iPhone 8 Plus
- iPad Pro (12.9-inch) (6th generation)
- iPad Pro (12.9-inch) (2nd generation)
- Mac with 1280 x 800 pixels

Currently we don't use:
- iPhone 15: generates screenshots with size 1178 x 2556, but App Store wants 1179 x 2556
97 changes: 97 additions & 0 deletions Screenshots/Screenshots.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import XCTest

final class Screenshots: XCTestCase {

enum Language: String {
case en
case nl
}

enum Scenario: String, CaseIterable {
case main
case search
case connect
case connected

var appearance: XCUIDevice.Appearance {
switch self {
case .main:
.light
case .search:
.light
case .connect:
.light
case .connected:
.dark
}
}
}

#if os(iOS)
func testScreenshots() throws {
let screenshotsFolder = URL(fileURLWithPath: "/Users/jkool/geteduroam-screenshots")
let simulator = ProcessInfo().environment["SIMULATOR_DEVICE_NAME"]!.replacingOccurrences(of: " ", with: "_")
let host = ProcessInfo().environment["XCTestBundlePath"]!.contains("getgovroam") ? "getgovroam" : "geteduroam"
let languages: [Language] = [.en, .nl]
let scenarios = Scenario.allCases
for language in languages {
for (index, scenario) in scenarios.enumerated() {
XCUIDevice.shared.appearance = scenario.appearance


let app = XCUIApplication()
app.launchArguments += ["-AppleLanguages", "(\(language))"]
app.launchArguments += ["-AppleLocale", "\"\(language)\""]
app.launchArguments += ["-Scenario", "\(scenario)"]
app.launch()

let screenshot = app.screenshot()
let attachment = XCTAttachment(screenshot: screenshot)
let name = "\(host)-\(simulator)-\(language)-\(index)-\(scenario)"
attachment.name = name
attachment.lifetime = .keepAlways
add(attachment)

let path = screenshotsFolder.appendingPathComponent("\(name).png")
try screenshot.image.pngData()?.write(to: path, options: .atomic)
}
}
}
#elseif os(macOS)
func testScreenshots() throws {
let languages: [Language] = [.en, .nl]
let scenarios = Scenario.allCases
for language in languages {
for (index, scenario) in scenarios.enumerated() {
XCUIDevice.shared.appearance = scenario.appearance

let app = XCUIApplication()
app.launchArguments += ["-AppleLanguages", "(\(language))"]
app.launchArguments += ["-AppleLocale", "\"\(language)\""]
app.launchArguments += ["-Scenario", "\(scenario)"]
app.launch()

let screenshot = app.screenshot()
let attachment = XCTAttachment(screenshot: screenshot)
let name = "mac-\(language)-\(index)-\(scenario)"
attachment.name = name
attachment.lifetime = .keepAlways
add(attachment)

// Due to sandbox restrictions writing to disk doens't work on macOS, navigate to the test results and find the attachments there
}
}
}
#endif
}

#if os(macOS)
extension NSImage {
func pngData() -> Data? {
guard let imageData = tiffRepresentation, let imageRep = NSBitmapImageRep(data: imageData) else {
return nil
}
return imageRep.representation(using: .png, properties: [NSBitmapImageRep.PropertyKey.compressionFactor: 1.0])
}
}
#endif
Loading