在 UI 测试中访问 MPMoviePlayerController 的 playbackState

Access playbackState of MPMoviePlayerController within UI Test

有没有一种方法可以使用 XCTest 的 UI 测试框架来评估 MPMoviePlayerViewController 是否正在播放或暂停?

我可以通过记录器吐出的这段漂亮代码设法访问视频元素

[[[[[[[[app.otherElements[@"VideoPlayer_ViewController"] childrenMatchingType:XCUIElementTypeOther] elementBoundByIndex:0]
                                                         childrenMatchingType:XCUIElementTypeOther].element
                                                         childrenMatchingType:XCUIElementTypeOther].element
                                                         childrenMatchingType:XCUIElementTypeOther] matchingIdentifier:@"Video"]

但我在 XCUIElement 界面或 XCUIElementAttributes 协议中没有看到任何可以帮助我断言播放器正在播放或暂停的内容。有什么建议吗?

像这样设置呈现 MPMoviePlayerViewController 的视图控制器视图的 accessibilityValue

- (void)moviePlayerPlaybackStateDidChange:(NSNotification *)notification
{
    if (self.player.playbackState == MPMoviePlaybackStatePlaying) {
        self.view.accessibilityValue = @"MPMoviePlaybackStatePlaying";
    }

    if (self.player.playbackState == MPMoviePlaybackStatePaused) {
        self.view.accessibilityValue = @"MPMoviePlaybackStatePaused";
    }
}

然后我可以像这样访问值

// Playing
[[[XCUIApplication alloc] init].otherElements[@"VideoPlayer_ViewController"].value isEqualToString:@"MPMoviePlaybackStatePlaying"];
// Paused
[[[XCUIApplication alloc] init].otherElements[@"VideoPlayer_ViewController"].value isEqualToString:@"MPMoviePlaybackStatePaused"];