JXShortDramaUITests.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. //
  2. // JXShortDramaUITests.m
  3. // AICityUITests
  4. //
  5. // Feature: 010-ui-ios
  6. // 短剧浏览页面UI测试 - Phase 2 UI层
  7. //
  8. #import <XCTest/XCTest.h>
  9. @interface JXShortDramaUITests : XCTestCase
  10. @end
  11. @implementation JXShortDramaUITests
  12. - (void)setUp {
  13. [super setUp];
  14. // 在setUp中设置
  15. self.continueAfterFailure = NO;
  16. // 启动应用
  17. [[[XCUIApplication alloc] init] launch];
  18. }
  19. - (void)tearDown {
  20. [super tearDown];
  21. }
  22. #pragma mark - 启动测试
  23. - (void)testLaunchPerformance {
  24. if (@available(iOS 13.0, *)) {
  25. [self measureWithMetrics:@[[[XCTApplicationLaunchMetric alloc] init]] block:^{
  26. [[[XCUIApplication alloc] init] launch];
  27. }];
  28. }
  29. }
  30. #pragma mark - 短剧列表UI测试
  31. - (void)testShortDramaListVisible {
  32. XCUIApplication *app = [[XCUIApplication alloc] init];
  33. // 等待列表加载
  34. XCUIElement *collectionView = app.collectionViews.firstMatch;
  35. BOOL exists = [collectionView waitForExistenceWithTimeout:10.0];
  36. XCTAssertTrue(exists, @"短剧列表应该可见");
  37. }
  38. - (void)testShortDramaVerticalScroll {
  39. XCUIApplication *app = [[XCUIApplication alloc] init];
  40. XCUIElement *collectionView = app.collectionViews.firstMatch;
  41. if ([collectionView waitForExistenceWithTimeout:10.0]) {
  42. // 测试垂直滑动
  43. [collectionView swipeUp];
  44. // 等待动画完成
  45. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
  46. NSLog(@"✅ 垂直滑动测试完成");
  47. }
  48. }
  49. - (void)testVideoAutoPlay {
  50. XCUIApplication *app = [[XCUIApplication alloc] init];
  51. // 等待播放器加载
  52. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:3.0]];
  53. // 检查是否有播放控件(播放按钮、进度条等)
  54. // 注意:实际的元素名称需要根据SuperPlayer的实现调整
  55. NSLog(@"✅ 视频自动播放测试(需要在真机上验证)");
  56. }
  57. #pragma mark - 交互按钮测试
  58. - (void)testLikeButton {
  59. XCUIApplication *app = [[XCUIApplication alloc] init];
  60. // 查找点赞按钮(根据accessibility identifier)
  61. XCUIElement *likeButton = app.buttons[@"likeButton"];
  62. if ([likeButton waitForExistenceWithTimeout:5.0]) {
  63. [likeButton tap];
  64. NSLog(@"✅ 点赞按钮点击测试完成");
  65. }
  66. }
  67. - (void)testFavoriteButton {
  68. XCUIApplication *app = [[XCUIApplication alloc] init];
  69. // 查找收藏按钮
  70. XCUIElement *favoriteButton = app.buttons[@"favoriteButton"];
  71. if ([favoriteButton waitForExistenceWithTimeout:5.0]) {
  72. [favoriteButton tap];
  73. NSLog(@"✅ 收藏按钮点击测试完成");
  74. }
  75. }
  76. - (void)testCommentButton {
  77. XCUIApplication *app = [[XCUIApplication alloc] init];
  78. // 查找评论按钮
  79. XCUIElement *commentButton = app.buttons[@"commentButton"];
  80. if ([commentButton waitForExistenceWithTimeout:5.0]) {
  81. [commentButton tap];
  82. // 等待评论弹窗出现
  83. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
  84. NSLog(@"✅ 评论按钮点击测试完成");
  85. }
  86. }
  87. - (void)testCollectionButton {
  88. XCUIApplication *app = [[XCUIApplication alloc] init];
  89. // 查找合集按钮
  90. XCUIElement *collectionButton = app.buttons[@"collectionButton"];
  91. if ([collectionButton waitForExistenceWithTimeout:5.0]) {
  92. [collectionButton tap];
  93. // 等待合集弹窗出现
  94. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
  95. NSLog(@"✅ 合集按钮点击测试完成");
  96. }
  97. }
  98. #pragma mark - 评论弹窗UI测试
  99. - (void)testCommentDialog {
  100. XCUIApplication *app = [[XCUIApplication alloc] init];
  101. // 打开评论弹窗
  102. XCUIElement *commentButton = app.buttons[@"commentButton"];
  103. if ([commentButton waitForExistenceWithTimeout:5.0]) {
  104. [commentButton tap];
  105. // 等待弹窗出现
  106. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
  107. // 检查评论输入框
  108. XCUIElement *commentTextField = app.textFields[@"commentTextField"];
  109. BOOL textFieldExists = [commentTextField waitForExistenceWithTimeout:3.0];
  110. if (textFieldExists) {
  111. // 输入评论
  112. [commentTextField tap];
  113. [commentTextField typeText:@"UI测试评论"];
  114. // 查找发送按钮
  115. XCUIElement *sendButton = app.buttons[@"sendButton"];
  116. if ([sendButton waitForExistenceWithTimeout:2.0]) {
  117. [sendButton tap];
  118. }
  119. }
  120. NSLog(@"✅ 评论弹窗UI测试完成");
  121. }
  122. }
  123. #pragma mark - 合集弹窗UI测试
  124. - (void)testCollectionDialog {
  125. XCUIApplication *app = [[XCUIApplication alloc] init];
  126. // 打开合集弹窗
  127. XCUIElement *collectionButton = app.buttons[@"collectionButton"];
  128. if ([collectionButton waitForExistenceWithTimeout:5.0]) {
  129. [collectionButton tap];
  130. // 等待弹窗出现
  131. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
  132. // 检查剧集列表
  133. XCUIElement *episodeCollectionView = app.collectionViews[@"episodeCollectionView"];
  134. BOOL exists = [episodeCollectionView waitForExistenceWithTimeout:3.0];
  135. if (exists) {
  136. // 点击第一个剧集
  137. XCUIElement *firstEpisode = episodeCollectionView.cells.firstMatch;
  138. if (firstEpisode.exists) {
  139. [firstEpisode tap];
  140. NSLog(@"✅ 点击剧集测试完成");
  141. }
  142. }
  143. NSLog(@"✅ 合集弹窗UI测试完成");
  144. }
  145. }
  146. #pragma mark - 搜索页面UI测试
  147. - (void)testSearchPage {
  148. XCUIApplication *app = [[XCUIApplication alloc] init];
  149. // 查找搜索按钮或搜索入口
  150. XCUIElement *searchButton = app.buttons[@"searchButton"];
  151. if ([searchButton waitForExistenceWithTimeout:5.0]) {
  152. [searchButton tap];
  153. // 等待搜索页面出现
  154. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
  155. // 查找搜索输入框
  156. XCUIElement *searchField = app.searchFields.firstMatch;
  157. if ([searchField waitForExistenceWithTimeout:3.0]) {
  158. [searchField tap];
  159. [searchField typeText:@"爱情"];
  160. // 点击搜索按钮
  161. [app.buttons[@"search"] tap];
  162. // 等待搜索结果
  163. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]];
  164. }
  165. NSLog(@"✅ 搜索页面UI测试完成");
  166. }
  167. }
  168. #pragma mark - 分类筛选UI测试
  169. - (void)testCategoryPage {
  170. XCUIApplication *app = [[XCUIApplication alloc] init];
  171. // 查找分类按钮
  172. XCUIElement *categoryButton = app.buttons[@"categoryButton"];
  173. if ([categoryButton waitForExistenceWithTimeout:5.0]) {
  174. [categoryButton tap];
  175. // 等待分类页面出现
  176. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
  177. // 查找分类横向滚动视图
  178. XCUIElement *categoryCollectionView = app.collectionViews[@"categoryCollectionView"];
  179. if ([categoryCollectionView waitForExistenceWithTimeout:3.0]) {
  180. // 点击第二个分类
  181. if (categoryCollectionView.cells.count > 1) {
  182. [categoryCollectionView.cells.allElementsBoundByIndex[1] tap];
  183. // 等待列表刷新
  184. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
  185. }
  186. }
  187. NSLog(@"✅ 分类筛选UI测试完成");
  188. }
  189. }
  190. #pragma mark - 播放历史UI测试
  191. - (void)testHistoryPage {
  192. XCUIApplication *app = [[XCUIApplication alloc] init];
  193. // 查找历史按钮
  194. XCUIElement *historyButton = app.buttons[@"historyButton"];
  195. if ([historyButton waitForExistenceWithTimeout:5.0]) {
  196. [historyButton tap];
  197. // 等待历史页面出现
  198. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
  199. // 检查清空按钮
  200. XCUIElement *clearButton = app.buttons[@"清空"];
  201. BOOL exists = [clearButton waitForExistenceWithTimeout:3.0];
  202. if (exists) {
  203. NSLog(@"✅ 历史页面加载成功");
  204. }
  205. NSLog(@"✅ 播放历史UI测试完成");
  206. }
  207. }
  208. #pragma mark - 收藏页面UI测试
  209. - (void)testFavoritePage {
  210. XCUIApplication *app = [[XCUIApplication alloc] init];
  211. // 查找收藏按钮
  212. XCUIElement *myFavoriteButton = app.buttons[@"myFavoriteButton"];
  213. if ([myFavoriteButton waitForExistenceWithTimeout:5.0]) {
  214. [myFavoriteButton tap];
  215. // 等待收藏页面出现
  216. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
  217. // 检查管理按钮
  218. XCUIElement *manageButton = app.buttons[@"管理"];
  219. BOOL exists = [manageButton waitForExistenceWithTimeout:3.0];
  220. if (exists) {
  221. // 进入编辑模式
  222. [manageButton tap];
  223. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
  224. // 退出编辑模式
  225. XCUIElement *cancelButton = app.buttons[@"取消"];
  226. if ([cancelButton waitForExistenceWithTimeout:2.0]) {
  227. [cancelButton tap];
  228. }
  229. }
  230. NSLog(@"✅ 收藏页面UI测试完成");
  231. }
  232. }
  233. #pragma mark - 性能测试
  234. - (void)testScrollPerformance {
  235. XCUIApplication *app = [[XCUIApplication alloc] init];
  236. XCUIElement *collectionView = app.collectionViews.firstMatch;
  237. if ([collectionView waitForExistenceWithTimeout:10.0]) {
  238. [self measureBlock:^{
  239. // 连续滑动5次
  240. for (int i = 0; i < 5; i++) {
  241. [collectionView swipeUp];
  242. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
  243. }
  244. }];
  245. }
  246. }
  247. #pragma mark - 网络异常UI测试
  248. - (void)testNoNetworkUI {
  249. // 此测试需要手动在设置中关闭网络,或使用Network Link Conditioner
  250. XCUIApplication *app = [[XCUIApplication alloc] init];
  251. // 下拉刷新
  252. XCUIElement *collectionView = app.collectionViews.firstMatch;
  253. if ([collectionView waitForExistenceWithTimeout:10.0]) {
  254. [collectionView swipeDown];
  255. // 等待错误提示
  256. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:3.0]];
  257. NSLog(@"✅ 网络异常UI测试完成(需手动验证)");
  258. }
  259. }
  260. #pragma mark - 完整流程测试
  261. - (void)testCompleteUserFlow {
  262. XCUIApplication *app = [[XCUIApplication alloc] init];
  263. // 1. 等待列表加载
  264. XCUIElement *collectionView = app.collectionViews.firstMatch;
  265. if ([collectionView waitForExistenceWithTimeout:10.0]) {
  266. // 2. 滑动到下一个视频
  267. [collectionView swipeUp];
  268. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]];
  269. // 3. 点赞
  270. XCUIElement *likeButton = app.buttons[@"likeButton"];
  271. if ([likeButton waitForExistenceWithTimeout:3.0]) {
  272. [likeButton tap];
  273. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
  274. }
  275. // 4. 打开评论
  276. XCUIElement *commentButton = app.buttons[@"commentButton"];
  277. if ([commentButton waitForExistenceWithTimeout:3.0]) {
  278. [commentButton tap];
  279. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
  280. // 关闭评论弹窗
  281. [app swipeDown];
  282. }
  283. // 5. 打开合集
  284. XCUIElement *collectionButton = app.buttons[@"collectionButton"];
  285. if ([collectionButton waitForExistenceWithTimeout:3.0]) {
  286. [collectionButton tap];
  287. [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
  288. // 关闭合集弹窗
  289. [app swipeDown];
  290. }
  291. NSLog(@"✅ 完整用户流程测试完成");
  292. }
  293. }
  294. @end