8

If I've an AVPlayerItem its status is never reaching .readyToPlay on the Travis VM while running a UI test. Everything works fine locally.

I've set up simple repro:

https://travis-ci.org/gsabran/TestAVItemStatus

https://github.com/gsabran/TestAVItemStatus

This makes my tests fail on Travis because some events are only getting triggered once the video item is ready to play.

Here is my application (a single view controller). Basically it just loads a local video and changes the UI when the video starts playing.

override func viewDidLoad() {
  super.viewDidLoad()

  item = AVPlayerItem(url: URL(fileURLWithPath: Bundle.main.path(forResource: "video", ofType: "mp4")!))
  player = AVPlayer(playerItem: item)

  item.addObserver(
    self,
    forKeyPath: #keyPath(AVPlayerItem.status),
    options: [.initial, .old, .new],
    context: nil)

  if player.currentItem?.status == .readyToPlay {
    videoDidLoad()
  }
  player.play()
}

override func observeValue(forKeyPath keyPath: String?,
                           of object: Any?,
                           change: [NSKeyValueChangeKey : Any]?,
                           context: UnsafeMutableRawPointer?) {

  guard let item = object as? AVPlayerItem else { return }

  if item.status == .readyToPlay {
    DispatchQueue.main.async {
      self.videoDidLoad()
    }
  }
}

func videoDidLoad() {
  // Not triggered on Travis VM, while working fine on local simulator and device
  label.text = "video ready"
}

Here is the test, simply checking for a label after a while:

class TestAVItemStatusUITests: XCTestCase {

    override func setUp() {
        super.setUp()
        continueAfterFailure = false
        XCUIApplication().launch()
    }

    func testExample() {
        sleep(5)
        if !XCUIApplication().staticTexts["video ready"].exists {
            XCTFail()
        }
    }
}

It's not working on Travis.

Guig
  • 9,891
  • 7
  • 64
  • 126
  • actually i am not getting clear from your question. what you want to achieve? – Code Hunterr Apr 11 '17 at 05:28
  • The code should work fine, and I've written a test that just tests that: https://github.com/gsabran/TestAVItemStatus/blob/master/TestAVItemStatusUITests/TestAVItemStatusUITests.swift. The test runs well on my computer but not on travis. – Guig Apr 11 '17 at 20:39
  • have you tried any of the suggestions from here http://stackoverflow.com/q/28794243/22147 and here https://github.com/travis-ci/travis-ci/issues/6675 – Rhythmic Fistman Apr 12 '17 at 00:17
  • I don't think it's related to the simulator not building properly, but just the test running and failing. The VM logs `testExample, failed - TestAVItemStatusUITests.swift:22` which refers to the test line where I do `XCTFail()`: https://github.com/gsabran/TestAVItemStatus/blob/master/TestAVItemStatusUITests/TestAVItemStatusUITests.swift#L22 – Guig Apr 12 '17 at 22:12

0 Answers0