AVPlayer项目在Travis上的UI文本期间无法启动

Gui*_*uig 8 virtual-machine avfoundation ios ios-simulator travis-ci

如果我的AVPlayerItem状态是.readyToPlay在运行UI测试时从未到达Travis VM.一切都在当地很好.

我已经设置了简单的repro:

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

https://github.com/gsabran/TestAVItemStatus

这使得我的测试在Travis上失败,因为一些事件只有在视频项目准备好播放时才会被触发.

这是我的应用程序(单个视图控制器).基本上它只是加载本地视频并在视频开始播放时更改UI.

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"
}
Run Code Online (Sandbox Code Playgroud)

这是测试,一段时间后只需检查标签:

class TestAVItemStatusUITests: XCTestCase {

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

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

它不适用于特拉维斯.