Skip to content

Commit

Permalink
Merge pull request #72 from geteduroam/feature/screenshots
Browse files Browse the repository at this point in the history
Code to create screenshots
  • Loading branch information
johankool authored Dec 7, 2023
2 parents 34d78a6 + 98bffb4 commit 584b9d7
Show file tree
Hide file tree
Showing 20 changed files with 1,072 additions and 54 deletions.
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

0 comments on commit 584b9d7

Please sign in to comment.