// TAP TO PLAY, timed (NEXT.md, 26 Nov: the player took 4 to 8 s to come up). On Cinemas Dev against the dev server's // invented +1555 account, holding one invented film (scripts: `-cinemas-add-file`), the featured title's Play is // tapped cold (the app just launched) and warm (the same launch, played again), with the player closed in between. // The app writes each step's time since the tap to Library/Caches/play-clock.log (PlayClock in FilmStream.swift); // the test asserts only that the player comes up, and the walk script reads the table back. import XCTest final class CinemasPlayClockTests: XCTestCase { override func setUp() { continueAfterFailure = false } @MainActor private func element(_ app: XCUIApplication, _ id: String) -> XCUIElement { app.descendants(matching: .any)[id].firstMatch } @MainActor private func playOnce(_ app: XCUIApplication, _ name: String) { let play = element(app, "cinemas-featured-play") XCTAssertTrue(play.waitForExistence(timeout: 30)) play.tap() // Up on the tap: by the time the tap has gone in, the player is there, not seconds later after the core and the // stream (the app's own clock, play-clock.log, says under 300 ms; this reading adds the test's snapshot time). let tapped = Date() XCTAssertTrue(element(app, "film-player").waitForExistence(timeout: 20), "the player comes up") XCTAssertLessThan(Date().timeIntervalSince(tapped), 1.5, "the player is up at once") Thread.sleep(forTimeInterval: 6) let shot = XCTAttachment(screenshot: app.screenshot()) shot.name = name shot.lifetime = .keepAlways add(shot) // Closed as a thumb does: the player's own close, else a swipe down. let close = app.buttons["Close"].firstMatch if close.waitForExistence(timeout: 3) { close.tap() } else { app.swipeDown(velocity: .fast) } XCTAssertTrue(play.waitForExistence(timeout: 10)) Thread.sleep(forTimeInterval: 2) } /// Before timing a streamed play: the featured film's page, and its Remove download, so it is no longer held here. @MainActor func testRemoveTheDownloadFirst() throws { let app = XCUIApplication() app.launch() let title = element(app, "cinemas-featured-title") XCTAssertTrue(title.waitForExistence(timeout: 30)) title.tap() let remove = element(app, "cinemas-act-remove_download") XCTAssertTrue(remove.waitForExistence(timeout: 10), "the film is held on this phone") remove.tap() Thread.sleep(forTimeInterval: 2) let shot = XCTAttachment(screenshot: app.screenshot()) shot.name = "After Remove download" shot.lifetime = .keepAlways add(shot) XCTAssertTrue(element(app, "cinemas-act-keep").waitForExistence(timeout: 10), "Keep is offered again: the film streams") } /// The overlay as it stands (NEXT-PLAYER.md): the start, the controls shown, our "more" menu, the system's own menu. @MainActor func testTheOverlay() throws { let app = XCUIApplication() app.launch() let play = element(app, "cinemas-featured-play") XCTAssertTrue(play.waitForExistence(timeout: 30)) play.tap() XCTAssertTrue(element(app, "film-player").waitForExistence(timeout: 20)) func shot(_ name: String) { let attachment = XCTAttachment(screenshot: app.screenshot()) attachment.name = name attachment.lifetime = .keepAlways add(attachment) } Thread.sleep(forTimeInterval: 1.2) shot("overlay 1 start") Thread.sleep(forTimeInterval: 8) app.tap() Thread.sleep(forTimeInterval: 0.8) shot("overlay 2 controls") let more = element(app, "film-more-open") if more.exists, more.isHittable { more.tap() Thread.sleep(forTimeInterval: 0.8) shot("overlay 3 more menu") if element(app, "film-more-close").exists { element(app, "film-more-close").tap() } } app.tap() Thread.sleep(forTimeInterval: 0.5) let ours = element(app, "film-subtitles-open") if ours.exists, ours.isHittable { ours.tap() XCTAssertTrue(element(app, "cinemas-subtitles").waitForExistence(timeout: 6), "Cinemas' own Subtitles sheet") Thread.sleep(forTimeInterval: 1) shot("overlay 5 subtitles sheet") app.swipeDown(velocity: .fast) Thread.sleep(forTimeInterval: 0.8) } let subtitles = app.buttons.matching(NSPredicate(format: "label CONTAINS[c] %@ OR label CONTAINS[c] %@", "Subtitle", "Audio")).firstMatch if subtitles.waitForExistence(timeout: 3) { subtitles.tap() Thread.sleep(forTimeInterval: 0.8) shot("overlay 4 system menu") } } /// The same, with the player's stall-avoidance wait off (a Dev experiment: `-play-no-wait`). @MainActor func testTapToPlayWithoutTheWait() throws { let app = XCUIApplication() app.launchArguments += ["-play-no-wait"] app.launch() playOnce(app, "Cold, no wait") playOnce(app, "Warm, no wait") } /// Play from the start, from the title's page: no resume point to seek to. @MainActor func testPlayFromTheStart() throws { let app = XCUIApplication() app.launch() let title = element(app, "cinemas-featured-title") XCTAssertTrue(title.waitForExistence(timeout: 30)) title.tap() let start = element(app, "cinemas-title-from-start") XCTAssertTrue(start.waitForExistence(timeout: 10)) start.tap() XCTAssertTrue(element(app, "film-player").waitForExistence(timeout: 20)) Thread.sleep(forTimeInterval: 10) } /// From the title's page, as a person plays (PLAYER START 2): the page opens and prepares its play /// (`shell.player prepare`) while it is read, a few seconds, then Play. Cold, then warm. @MainActor func testTapToPlayFromThePage() throws { let app = XCUIApplication() app.launch() for name in ["Cold, from the page", "Warm, from the page"] { // The invented film (a series' page prepares nothing: its episode's page does). let title = app.descendants(matching: .any) .matching(NSPredicate(format: "identifier BEGINSWITH %@ AND label CONTAINS[c] %@", "cinemas-poster-", "Quiet Signal")).firstMatch XCTAssertTrue(title.waitForExistence(timeout: 30)) title.tap() let play = element(app, "cinemas-title-play") XCTAssertTrue(play.waitForExistence(timeout: 10)) // Read as a person reads a page before Play. Thread.sleep(forTimeInterval: 4) play.tap() let tapped = Date() XCTAssertTrue(element(app, "film-player").waitForExistence(timeout: 20), "the player comes up") XCTAssertLessThan(Date().timeIntervalSince(tapped), 1.5, "the player is up at once") Thread.sleep(forTimeInterval: 6) let shot = XCTAttachment(screenshot: app.screenshot()) shot.name = name shot.lifetime = .keepAlways add(shot) let close = app.buttons["Close"].firstMatch if close.waitForExistence(timeout: 3) { close.tap() } else { app.swipeDown(velocity: .fast) } XCTAssertTrue(play.waitForExistence(timeout: 10)) // Back to Home: the page let go of what it prepared. let back = app.navigationBars.buttons.firstMatch if back.exists && back.isHittable { back.tap() } else { app.coordinate(withNormalizedOffset: CGVector(dx: 0.01, dy: 0.5)) .press(forDuration: 0.1, thenDragTo: app.coordinate(withNormalizedOffset: CGVector(dx: 0.85, dy: 0.5))) } Thread.sleep(forTimeInterval: 2) } } @MainActor func testTapToPlayColdThenWarm() throws { let app = XCUIApplication() app.launch() playOnce(app, "Cold") playOnce(app, "Warm") } /// From Home, as a person plays (PLAYER START 3): Home shows and prepares Featured's play, read a few seconds, /// then Featured's Play (a resume). Cold, then warm; then a series' page, whose Play is the episode the core chose. @MainActor func testTapToPlayFromHome() throws { try fromHome(prepared: true) } /// The same walk with prepare off (`-play-no-prepare`): the before. @MainActor func testTapToPlayFromHomeUnprepared() throws { try fromHome(prepared: false) } @MainActor private func fromHome(prepared: Bool) throws { let app = XCUIApplication() if !prepared { app.launchArguments += ["-play-no-prepare"] } app.launch() func timed(_ play: XCUIElement, _ name: String) { XCTAssertTrue(play.waitForExistence(timeout: 30)) // Read as a person looks at Home before Play. Thread.sleep(forTimeInterval: 4) play.tap() let tapped = Date() XCTAssertTrue(element(app, "film-player").waitForExistence(timeout: 20), "the player comes up") XCTAssertLessThan(Date().timeIntervalSince(tapped), 1.5, "the player is up at once") Thread.sleep(forTimeInterval: 6) let shot = XCTAttachment(screenshot: app.screenshot()) shot.name = name shot.lifetime = .keepAlways add(shot) let close = app.buttons["Close"].firstMatch if close.waitForExistence(timeout: 3) { close.tap() } else { app.swipeDown(velocity: .fast) } Thread.sleep(forTimeInterval: 2) } timed(element(app, "cinemas-featured-play"), "Cold, Featured on Home") timed(element(app, "cinemas-featured-play"), "Warm, Featured on Home") // The series' page: its Play is the episode the core chose, prepared as the page opens. let title = element(app, "cinemas-featured-title") XCTAssertTrue(title.waitForExistence(timeout: 10)) title.tap() timed(element(app, "cinemas-title-play"), "The series' page") } /// Setup for the timed walks on a fresh dev account: the invented film added from this phone (`-cinemas-add-file`) /// is let go from the phone (it streams), and played a few seconds, so it is Carry on and Home's Featured. @MainActor func testMakeTheInventedFilmFeatured() throws { let app = XCUIApplication() app.launch() let poster = app.descendants(matching: .any) .matching(NSPredicate(format: "identifier BEGINSWITH %@ AND label CONTAINS[c] %@", "cinemas-poster-", "Quiet Signal")).firstMatch var swipes = 0 let bar = element(app, "cinemas-tab-home").frame.minY - 20 while (!poster.waitForExistence(timeout: 3) || !poster.isHittable || poster.frame.maxY > bar) && swipes < 8 { app.swipeUp(velocity: .slow) swipes += 1 } XCTAssertTrue(poster.isHittable, "the invented film on Home") poster.tap() let remove = element(app, "cinemas-act-remove_download") if remove.waitForExistence(timeout: 60) { remove.tap() XCTAssertTrue(element(app, "cinemas-act-keep").waitForExistence(timeout: 20), "it streams now") } let play = element(app, "cinemas-title-play") XCTAssertTrue(play.waitForExistence(timeout: 10)) play.tap() XCTAssertTrue(element(app, "film-player").waitForExistence(timeout: 20)) Thread.sleep(forTimeInterval: 10) let close = app.buttons["Close"].firstMatch if close.waitForExistence(timeout: 3) { close.tap() } else { app.swipeDown(velocity: .fast) } Thread.sleep(forTimeInterval: 2) let shot = XCTAttachment(screenshot: app.screenshot()) shot.name = "After the setup" shot.lifetime = .keepAlways add(shot) } }