Detecting video playback in iOS XCUI test

I have a simple ui test that determines video playback has started (using the native iOS video player) via occasionally checking the elapsed time of the video player. This works fine and dandy locally but in CircleCI I consistently get a failure stating “XCTAssertTrue failed - Couldn’t find video player”. I’m hoping someone has some idea as to why this behavior would happen only in CI or alternatively if there is a smarter way to detect video playback has started.

func testVideo() {
let timeout = 20.0
let app = XCUIApplication()
let timeElapsed = app.otherElements[“Time Elapsed”]
let videoPlayer = app.otherElements[“Video”]
XCUIApplication().buttons[“Button”].tap()
XCTAssert(timeElapsed.waitForExistence(timeout: timeout), “Couldn’t find time”)
let timeValue1 = Int(timeElapsed.label.replacingOccurrences(of: “:”, with: “”)) ?? 0
XCTAssert(videoPlayer.waitForExistence(timeout: timeout), “Couldn’t find video player”)
sleep(10)
videoPlayer.tap()
XCTAssert(timeElapsed.waitForExistence(timeout: timeout), “Couldn’t find time”)
let timeValue2 = Int(timeElapsed.label.replacingOccurrences(of: “:”, with: “”)) ?? 0
XCTAssert(timeValue2 > timeValue1)
}

edit: I figure it might be worth noting that the video is not local

What happens if you flip the order of these two lines?

You are trying to tap on videoPlayer. So, it makes more sense to do your assertion after you execute sleep(10).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.