FBElementSwipingTests.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import <XCTest/XCTest.h>
  10. #import "FBIntegrationTestCase.h"
  11. #import "FBTestMacros.h"
  12. #import "XCUIElement+FBWebDriverAttributes.h"
  13. #import "FBXCodeCompatibility.h"
  14. #import "XCUIElement+FBSwiping.h"
  15. @interface FBElementSwipingTests : FBIntegrationTestCase
  16. @property (nonatomic, strong) XCUIElement *scrollView;
  17. - (void)openScrollView;
  18. @end
  19. @implementation FBElementSwipingTests
  20. - (void)openScrollView
  21. {
  22. [self launchApplication];
  23. [self goToScrollPageWithCells:YES];
  24. self.scrollView = [[self.testedApplication.query descendantsMatchingType:XCUIElementTypeAny] matchingIdentifier:@"scrollView"].element;
  25. }
  26. - (void)setUp
  27. {
  28. [super setUp];
  29. if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"15.0")) {
  30. [self openScrollView];
  31. } else {
  32. static dispatch_once_t onceToken;
  33. dispatch_once(&onceToken, ^{
  34. [self openScrollView];
  35. });
  36. }
  37. }
  38. - (void)tearDown
  39. {
  40. if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"15.0")) {
  41. // Move to top page once to reset the scroll place
  42. // since iOS 15 seems cannot handle cell visibility well when the view keps the view
  43. [self.testedApplication terminate];
  44. }
  45. }
  46. - (void)testSwipeUp
  47. {
  48. [self.scrollView fb_swipeWithDirection:@"up" velocity:nil];
  49. FBAssertInvisibleCell(@"0");
  50. }
  51. - (void)testSwipeDown
  52. {
  53. [self.scrollView fb_swipeWithDirection:@"up" velocity:nil];
  54. FBAssertInvisibleCell(@"0");
  55. [self.scrollView fb_swipeWithDirection:@"down" velocity:nil];
  56. FBAssertVisibleCell(@"0");
  57. }
  58. - (void)testSwipeDownWithVelocity
  59. {
  60. if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
  61. XCTSkip(@"Failed on Azure Pipeline. Local run succeeded.");
  62. }
  63. [self.scrollView fb_swipeWithDirection:@"up" velocity:@2500];
  64. FBAssertInvisibleCell(@"0");
  65. [self.scrollView fb_swipeWithDirection:@"down" velocity:@3000];
  66. FBAssertVisibleCell(@"0");
  67. }
  68. @end
  69. @interface FBElementSwipingApplicationTests : FBIntegrationTestCase
  70. @property (nonatomic, strong) XCUIElement *scrollView;
  71. - (void)openScrollView;
  72. @end
  73. @implementation FBElementSwipingApplicationTests
  74. - (void)openScrollView
  75. {
  76. [self launchApplication];
  77. [self goToScrollPageWithCells:YES];
  78. }
  79. - (void)setUp
  80. {
  81. [super setUp];
  82. static dispatch_once_t onceToken;
  83. dispatch_once(&onceToken, ^{
  84. [self openScrollView];
  85. });
  86. }
  87. - (void)testSwipeUp
  88. {
  89. [self.testedApplication fb_swipeWithDirection:@"up" velocity:nil];
  90. FBAssertInvisibleCell(@"0");
  91. }
  92. - (void)testSwipeDown
  93. {
  94. [self.testedApplication fb_swipeWithDirection:@"up" velocity:nil];
  95. FBAssertInvisibleCell(@"0");
  96. [self.testedApplication fb_swipeWithDirection:@"down" velocity:nil];
  97. FBAssertVisibleCell(@"0");
  98. }
  99. - (void)testSwipeDownWithVelocity
  100. {
  101. if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
  102. XCTSkip(@"Failed on Azure Pipeline. Local run succeeded.");
  103. }
  104. [self.testedApplication fb_swipeWithDirection:@"up" velocity:@2500];
  105. FBAssertInvisibleCell(@"0");
  106. [self.testedApplication fb_swipeWithDirection:@"down" velocity:@2500];
  107. FBAssertVisibleCell(@"0");
  108. }
  109. @end