// WALKING CINEMAS BY HAND, as a finger would, on Cinemas Dev's invented library (`-cinemas-invent`: made-up films// with drawn posters, nothing of anyone's): Home scrolled and a row scrolled sideways, a poster opened into its page// and back, a film played and closed half way and its Resume seen, a poster held and put in a new group, Search, a// series' season switch, and the TV picker. Each step leaves a screenshot in the result; the screen video is taken// around the run (scripts/cinemas-walk.sh).import XCTestfinalclassCinemasWalkTests: XCTestCase {overridefunc setUp() { continueAfterFailure = false } @MainActor privatefunc element(_ app: XCUIApplication, _ id: String) -> XCUIElement { app.descendants(matching: .any)[id].firstMatch } @MainActor privatefunc shot(_ app: XCUIApplication, _ name: String) {let attachment = XCTAttachment(screenshot: app.screenshot()) attachment.name = name attachment.lifetime = .keepAlways add(attachment) }privatefunc pause(_ seconds: Double) {Thread.sleep(forTimeInterval: seconds) }/// Back as a thumb does it: from the left edge across. @MainActor privatefunc back(_ app: XCUIApplication) {let edge = app.coordinate(withNormalizedOffset: CGVector(dx: 0.01, dy: 0.45)) edge.press(forDuration: 0.05, thenDragTo: app.coordinate(withNormalizedOffset: CGVector(dx: 0.85, dy: 0.45))) } @MainActor func testWalkByHand() throws {let app = XCUIApplication() app.launchArguments += ["-cinemas-invent"] app.launch()// Home: the featured title settles in; the page scrolls and comes back. XCTAssertTrue(element(app, "cinemas-featured").waitForExistence(timeout: 30), "Home stands") pause(2) shot(app, "01 Home") app.swipeUp(velocity: .slow) pause(1.2) shot(app, "02 Home scrolled")// A row sideways, with its snap.let films = element(app, "cinemas-row-films")if films.waitForExistence(timeout: 5) { films.swipeLeft(velocity: .slow) pause(1.2) films.swipeLeft(velocity: .fast) pause(1.2) shot(app, "03 Films row scrolled") } app.swipeDown(velocity: .slow) pause(1)// A poster grows into its page, and the page goes back into it.let poster = element(app, "cinemas-poster-carry_on-f-ferry") XCTAssertTrue(poster.waitForExistence(timeout: 10), "Carry on's first poster") poster.tap() XCTAssertTrue(element(app, "cinemas-title-play").waitForExistence(timeout: 10), "the title's page") pause(1.5) shot(app, "04 A title's page") app.swipeUp(velocity: .slow) pause(1.2) shot(app, "05 The page scrolled (the backdrop fades)") app.swipeDown(velocity: .slow) pause(1) back(app) XCTAssertTrue(element(app, "cinemas-featured").waitForExistence(timeout: 10), "back on Home") pause(1.5)// Films opened whole from its chip, scrolled; then a film with no place yet: played, closed half way, and// Resume names the place.let chip = element(app, "cinemas-chip-films") XCTAssertTrue(chip.waitForExistence(timeout: 6), "the Films chip") chip.tap() XCTAssertTrue(element(app, "cinemas-row-screen").waitForExistence(timeout: 8), "Films opened whole") pause(1.2) shot(app, "06 Films opened whole") app.swipeUp(velocity: .slow) pause(1) app.swipeDown(velocity: .slow) pause(1)let lantern = element(app, "cinemas-poster-films-f-lantern") XCTAssertTrue(lantern.waitForExistence(timeout: 6), "Lantern Street in Films") lantern.tap()let play = element(app, "cinemas-title-play") XCTAssertTrue(play.waitForExistence(timeout: 10)) pause(1) play.tap() pause(9) shot(app, "06 Playing")let close = app.buttons.matching(NSPredicate(format: "label IN %@", ["Close", "Done", "Dismiss"])).firstMatchif close.waitForExistence(timeout: 4) { close.tap() } else { app.tap()if close.waitForExistence(timeout: 3) { close.tap() } else { app.swipeDown(velocity: .fast) } }let resume = app.buttons.matching(NSPredicate(format: "label BEGINSWITH 'Resume'")).firstMatch XCTAssertTrue(resume.waitForExistence(timeout: 10), "Resume after closing half way") pause(1.5) shot(app, "07 Resume after closing") back(app) pause(1.2) back(app) pause(1.5)// A poster held: the one sheet, a new group, Done. app.swipeDown(velocity: .fast) pause(1)let held = element(app, "cinemas-poster-carry_on-f-ferry") XCTAssertTrue(held.waitForExistence(timeout: 8)) held.press(forDuration: 0.8) XCTAssertTrue(element(app, "cinemas-item-sheet").waitForExistence(timeout: 6), "the hold's sheet") pause(1.2) shot(app, "08 Held: the sheet") element(app, "cinemas-sheet-new-group").tap()let name = element(app, "cinemas-sheet-name") XCTAssertTrue(name.waitForExistence(timeout: 4)) name.tap() name.typeText("Late shows\n") pause(1.5) shot(app, "09 New group made")let done = element(app, "cinemas-sheet-done")if done.waitForExistence(timeout: 3) { done.tap() } pause(1.5) shot(app, "10 Home with the new group")// Search.let searchTab = element(app, "cinemas-tab-search") XCTAssertTrue(searchTab.waitForExistence(timeout: 5), "each tab is its own element, for VoiceOver as for a test") searchTab.tap()let field = element(app, "cinemas-search-field") XCTAssertTrue(field.waitForExistence(timeout: 6)) field.tap() field.typeText("low") pause(2) shot(app, "11 Search")// A series: its page, and the season switch.// Lowmarsh is the top result.let series = element(app, "cinemas-search-top") XCTAssertTrue(series.waitForExistence(timeout: 6), "Lowmarsh found") series.tap() XCTAssertTrue(element(app, "cinemas-title-play").waitForExistence(timeout: 10)) pause(1) app.swipeUp(velocity: .slow) pause(1)let seasons = element(app, "cinemas-season-switch")if !seasons.waitForExistence(timeout: 3) { app.swipeUp(velocity: .slow) } XCTAssertTrue(seasons.waitForExistence(timeout: 4), "the season switch") shot(app, "12 Season 1")let segments = seasons.buttonsif segments.count > 1 { segments.element(boundBy: 1).tap() } pause(1.5) shot(app, "13 Season 2") app.swipeDown(velocity: .fast) pause(1)// The TV picker, from Play on TV.let tv = element(app, "cinemas-title-tv") XCTAssertTrue(tv.waitForExistence(timeout: 6)) tv.tap() pause(3) shot(app, "14 The TV picker") app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.08)).tap() pause(2) shot(app, "15 After the picker") }}