在UI Test中访问MPMoviePlayerController的playbackState

时间:2017-04-11 05:22:16

标签: xcode mpmovieplayercontroller xctest xcode-ui-testing

有没有办法评估MPMoviePlayerViewController是否正在使用XCTest的UI测试框架播放或暂停?

我可以通过录音机吐出的这段漂亮的代码来管理视频元素

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

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

1 个答案:

答案 0 :(得分:0)

结束设置accessibilityValue视图控制器视图的MPMoviePlayerViewController,如此

- (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"];