| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- //
- // JXShortDramaUITests.m
- // AICityUITests
- //
- // Feature: 010-ui-ios
- // 短剧浏览页面UI测试 - Phase 2 UI层
- //
- #import <XCTest/XCTest.h>
- @interface JXShortDramaUITests : XCTestCase
- @end
- @implementation JXShortDramaUITests
- - (void)setUp {
- [super setUp];
-
- // 在setUp中设置
- self.continueAfterFailure = NO;
-
- // 启动应用
- [[[XCUIApplication alloc] init] launch];
- }
- - (void)tearDown {
- [super tearDown];
- }
- #pragma mark - 启动测试
- - (void)testLaunchPerformance {
- if (@available(iOS 13.0, *)) {
- [self measureWithMetrics:@[[[XCTApplicationLaunchMetric alloc] init]] block:^{
- [[[XCUIApplication alloc] init] launch];
- }];
- }
- }
- #pragma mark - 短剧列表UI测试
- - (void)testShortDramaListVisible {
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- // 等待列表加载
- XCUIElement *collectionView = app.collectionViews.firstMatch;
- BOOL exists = [collectionView waitForExistenceWithTimeout:10.0];
-
- XCTAssertTrue(exists, @"短剧列表应该可见");
- }
- - (void)testShortDramaVerticalScroll {
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- XCUIElement *collectionView = app.collectionViews.firstMatch;
- if ([collectionView waitForExistenceWithTimeout:10.0]) {
- // 测试垂直滑动
- [collectionView swipeUp];
-
- // 等待动画完成
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
-
- NSLog(@"✅ 垂直滑动测试完成");
- }
- }
- - (void)testVideoAutoPlay {
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- // 等待播放器加载
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:3.0]];
-
- // 检查是否有播放控件(播放按钮、进度条等)
- // 注意:实际的元素名称需要根据SuperPlayer的实现调整
- NSLog(@"✅ 视频自动播放测试(需要在真机上验证)");
- }
- #pragma mark - 交互按钮测试
- - (void)testLikeButton {
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- // 查找点赞按钮(根据accessibility identifier)
- XCUIElement *likeButton = app.buttons[@"likeButton"];
- if ([likeButton waitForExistenceWithTimeout:5.0]) {
- [likeButton tap];
- NSLog(@"✅ 点赞按钮点击测试完成");
- }
- }
- - (void)testFavoriteButton {
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- // 查找收藏按钮
- XCUIElement *favoriteButton = app.buttons[@"favoriteButton"];
- if ([favoriteButton waitForExistenceWithTimeout:5.0]) {
- [favoriteButton tap];
- NSLog(@"✅ 收藏按钮点击测试完成");
- }
- }
- - (void)testCommentButton {
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- // 查找评论按钮
- XCUIElement *commentButton = app.buttons[@"commentButton"];
- if ([commentButton waitForExistenceWithTimeout:5.0]) {
- [commentButton tap];
-
- // 等待评论弹窗出现
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
-
- NSLog(@"✅ 评论按钮点击测试完成");
- }
- }
- - (void)testCollectionButton {
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- // 查找合集按钮
- XCUIElement *collectionButton = app.buttons[@"collectionButton"];
- if ([collectionButton waitForExistenceWithTimeout:5.0]) {
- [collectionButton tap];
-
- // 等待合集弹窗出现
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
-
- NSLog(@"✅ 合集按钮点击测试完成");
- }
- }
- #pragma mark - 评论弹窗UI测试
- - (void)testCommentDialog {
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- // 打开评论弹窗
- XCUIElement *commentButton = app.buttons[@"commentButton"];
- if ([commentButton waitForExistenceWithTimeout:5.0]) {
- [commentButton tap];
-
- // 等待弹窗出现
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
-
- // 检查评论输入框
- XCUIElement *commentTextField = app.textFields[@"commentTextField"];
- BOOL textFieldExists = [commentTextField waitForExistenceWithTimeout:3.0];
-
- if (textFieldExists) {
- // 输入评论
- [commentTextField tap];
- [commentTextField typeText:@"UI测试评论"];
-
- // 查找发送按钮
- XCUIElement *sendButton = app.buttons[@"sendButton"];
- if ([sendButton waitForExistenceWithTimeout:2.0]) {
- [sendButton tap];
- }
- }
-
- NSLog(@"✅ 评论弹窗UI测试完成");
- }
- }
- #pragma mark - 合集弹窗UI测试
- - (void)testCollectionDialog {
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- // 打开合集弹窗
- XCUIElement *collectionButton = app.buttons[@"collectionButton"];
- if ([collectionButton waitForExistenceWithTimeout:5.0]) {
- [collectionButton tap];
-
- // 等待弹窗出现
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
-
- // 检查剧集列表
- XCUIElement *episodeCollectionView = app.collectionViews[@"episodeCollectionView"];
- BOOL exists = [episodeCollectionView waitForExistenceWithTimeout:3.0];
-
- if (exists) {
- // 点击第一个剧集
- XCUIElement *firstEpisode = episodeCollectionView.cells.firstMatch;
- if (firstEpisode.exists) {
- [firstEpisode tap];
- NSLog(@"✅ 点击剧集测试完成");
- }
- }
-
- NSLog(@"✅ 合集弹窗UI测试完成");
- }
- }
- #pragma mark - 搜索页面UI测试
- - (void)testSearchPage {
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- // 查找搜索按钮或搜索入口
- XCUIElement *searchButton = app.buttons[@"searchButton"];
- if ([searchButton waitForExistenceWithTimeout:5.0]) {
- [searchButton tap];
-
- // 等待搜索页面出现
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
-
- // 查找搜索输入框
- XCUIElement *searchField = app.searchFields.firstMatch;
- if ([searchField waitForExistenceWithTimeout:3.0]) {
- [searchField tap];
- [searchField typeText:@"爱情"];
-
- // 点击搜索按钮
- [app.buttons[@"search"] tap];
-
- // 等待搜索结果
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]];
- }
-
- NSLog(@"✅ 搜索页面UI测试完成");
- }
- }
- #pragma mark - 分类筛选UI测试
- - (void)testCategoryPage {
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- // 查找分类按钮
- XCUIElement *categoryButton = app.buttons[@"categoryButton"];
- if ([categoryButton waitForExistenceWithTimeout:5.0]) {
- [categoryButton tap];
-
- // 等待分类页面出现
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
-
- // 查找分类横向滚动视图
- XCUIElement *categoryCollectionView = app.collectionViews[@"categoryCollectionView"];
- if ([categoryCollectionView waitForExistenceWithTimeout:3.0]) {
- // 点击第二个分类
- if (categoryCollectionView.cells.count > 1) {
- [categoryCollectionView.cells.allElementsBoundByIndex[1] tap];
-
- // 等待列表刷新
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
- }
- }
-
- NSLog(@"✅ 分类筛选UI测试完成");
- }
- }
- #pragma mark - 播放历史UI测试
- - (void)testHistoryPage {
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- // 查找历史按钮
- XCUIElement *historyButton = app.buttons[@"historyButton"];
- if ([historyButton waitForExistenceWithTimeout:5.0]) {
- [historyButton tap];
-
- // 等待历史页面出现
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
-
- // 检查清空按钮
- XCUIElement *clearButton = app.buttons[@"清空"];
- BOOL exists = [clearButton waitForExistenceWithTimeout:3.0];
-
- if (exists) {
- NSLog(@"✅ 历史页面加载成功");
- }
-
- NSLog(@"✅ 播放历史UI测试完成");
- }
- }
- #pragma mark - 收藏页面UI测试
- - (void)testFavoritePage {
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- // 查找收藏按钮
- XCUIElement *myFavoriteButton = app.buttons[@"myFavoriteButton"];
- if ([myFavoriteButton waitForExistenceWithTimeout:5.0]) {
- [myFavoriteButton tap];
-
- // 等待收藏页面出现
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
-
- // 检查管理按钮
- XCUIElement *manageButton = app.buttons[@"管理"];
- BOOL exists = [manageButton waitForExistenceWithTimeout:3.0];
-
- if (exists) {
- // 进入编辑模式
- [manageButton tap];
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
-
- // 退出编辑模式
- XCUIElement *cancelButton = app.buttons[@"取消"];
- if ([cancelButton waitForExistenceWithTimeout:2.0]) {
- [cancelButton tap];
- }
- }
-
- NSLog(@"✅ 收藏页面UI测试完成");
- }
- }
- #pragma mark - 性能测试
- - (void)testScrollPerformance {
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- XCUIElement *collectionView = app.collectionViews.firstMatch;
- if ([collectionView waitForExistenceWithTimeout:10.0]) {
- [self measureBlock:^{
- // 连续滑动5次
- for (int i = 0; i < 5; i++) {
- [collectionView swipeUp];
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
- }
- }];
- }
- }
- #pragma mark - 网络异常UI测试
- - (void)testNoNetworkUI {
- // 此测试需要手动在设置中关闭网络,或使用Network Link Conditioner
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- // 下拉刷新
- XCUIElement *collectionView = app.collectionViews.firstMatch;
- if ([collectionView waitForExistenceWithTimeout:10.0]) {
- [collectionView swipeDown];
-
- // 等待错误提示
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:3.0]];
-
- NSLog(@"✅ 网络异常UI测试完成(需手动验证)");
- }
- }
- #pragma mark - 完整流程测试
- - (void)testCompleteUserFlow {
- XCUIApplication *app = [[XCUIApplication alloc] init];
-
- // 1. 等待列表加载
- XCUIElement *collectionView = app.collectionViews.firstMatch;
- if ([collectionView waitForExistenceWithTimeout:10.0]) {
-
- // 2. 滑动到下一个视频
- [collectionView swipeUp];
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]];
-
- // 3. 点赞
- XCUIElement *likeButton = app.buttons[@"likeButton"];
- if ([likeButton waitForExistenceWithTimeout:3.0]) {
- [likeButton tap];
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
- }
-
- // 4. 打开评论
- XCUIElement *commentButton = app.buttons[@"commentButton"];
- if ([commentButton waitForExistenceWithTimeout:3.0]) {
- [commentButton tap];
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
-
- // 关闭评论弹窗
- [app swipeDown];
- }
-
- // 5. 打开合集
- XCUIElement *collectionButton = app.buttons[@"collectionButton"];
- if ([collectionButton waitForExistenceWithTimeout:3.0]) {
- [collectionButton tap];
- [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
-
- // 关闭合集弹窗
- [app swipeDown];
- }
-
- NSLog(@"✅ 完整用户流程测试完成");
- }
- }
- @end
|