FBIntegrationTestCase.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 "FBAlert.h"
  11. #import "FBTestMacros.h"
  12. #import "FBIntegrationTestCase.h"
  13. #import "FBConfiguration.h"
  14. #import "FBMacros.h"
  15. #import "FBRunLoopSpinner.h"
  16. #import "XCUIApplication+FBHelpers.h"
  17. #import "XCUIDevice+FBRotation.h"
  18. #import "XCUIElement.h"
  19. #import "XCUIElement+FBIsVisible.h"
  20. #import "XCUIElement+FBUtilities.h"
  21. #import "XCTestConfiguration.h"
  22. NSString *const FBShowAlertButtonName = @"Create App Alert";
  23. NSString *const FBShowSheetAlertButtonName = @"Create Sheet Alert";
  24. NSString *const FBShowAlertForceTouchButtonName = @"Create Alert (Force Touch)";
  25. NSString *const FBTouchesCountLabelIdentifier = @"numberOfTouchesLabel";
  26. NSString *const FBTapsCountLabelIdentifier = @"numberOfTapsLabel";
  27. @interface FBIntegrationTestCase ()
  28. @property (nonatomic, strong) XCUIApplication *testedApplication;
  29. @property (nonatomic, strong) XCUIApplication *springboard;
  30. @end
  31. @implementation FBIntegrationTestCase
  32. - (void)setUp
  33. {
  34. // Enable it to get extended XCTest logs printed into the console
  35. // [FBConfiguration enableXcTestDebugLogs];
  36. [super setUp];
  37. [FBConfiguration disableRemoteQueryEvaluation];
  38. [FBConfiguration disableAttributeKeyPathAnalysis];
  39. [FBConfiguration configureDefaultKeyboardPreferences];
  40. [FBConfiguration disableApplicationUIInterruptionsHandling];
  41. [FBConfiguration disableScreenshots];
  42. self.continueAfterFailure = NO;
  43. self.springboard = XCUIApplication.fb_systemApplication;
  44. self.testedApplication = [XCUIApplication new];
  45. }
  46. - (void)resetOrientation
  47. {
  48. if ([XCUIDevice sharedDevice].orientation != UIDeviceOrientationPortrait) {
  49. [[XCUIDevice sharedDevice] fb_setDeviceInterfaceOrientation:UIDeviceOrientationPortrait];
  50. }
  51. }
  52. - (void)launchApplication
  53. {
  54. [self.testedApplication launch];
  55. [self.testedApplication fb_waitUntilStable];
  56. FBAssertWaitTillBecomesTrue(self.testedApplication.buttons[@"Alerts"].fb_isVisible);
  57. }
  58. - (void)goToAttributesPage
  59. {
  60. [self.testedApplication.buttons[@"Attributes"] tap];
  61. [self.testedApplication fb_waitUntilStable];
  62. FBAssertWaitTillBecomesTrue(self.testedApplication.buttons[@"Button"].fb_isVisible);
  63. }
  64. - (void)goToAlertsPage
  65. {
  66. [self.testedApplication.buttons[@"Alerts"] tap];
  67. [self.testedApplication fb_waitUntilStable];
  68. FBAssertWaitTillBecomesTrue(self.testedApplication.buttons[FBShowAlertButtonName].fb_isVisible);
  69. FBAssertWaitTillBecomesTrue(self.testedApplication.buttons[FBShowSheetAlertButtonName].fb_isVisible);
  70. }
  71. - (void)goToTouchPage
  72. {
  73. [self.testedApplication.buttons[@"Touch"] tap];
  74. [self.testedApplication fb_waitUntilStable];
  75. FBAssertWaitTillBecomesTrue(self.testedApplication.staticTexts[FBTouchesCountLabelIdentifier].fb_isVisible);
  76. FBAssertWaitTillBecomesTrue(self.testedApplication.staticTexts[FBTapsCountLabelIdentifier].fb_isVisible);
  77. }
  78. - (void)goToSpringBoardFirstPage
  79. {
  80. [[XCUIDevice sharedDevice] pressButton:XCUIDeviceButtonHome];
  81. [self.testedApplication fb_waitUntilStable];
  82. FBAssertWaitTillBecomesTrue(XCUIApplication.fb_systemApplication.icons[@"Safari"].exists);
  83. [[XCUIDevice sharedDevice] pressButton:XCUIDeviceButtonHome];
  84. [self.testedApplication fb_waitUntilStable];
  85. FBAssertWaitTillBecomesTrue(XCUIApplication.fb_systemApplication.icons[@"Calendar"].firstMatch.fb_isVisible);
  86. }
  87. - (void)goToSpringBoardExtras
  88. {
  89. [self goToSpringBoardFirstPage];
  90. [self.springboard swipeLeft];
  91. [self.testedApplication fb_waitUntilStable];
  92. FBAssertWaitTillBecomesTrue(self.springboard.icons[@"Extras"].fb_isVisible);
  93. }
  94. - (void)goToSpringBoardDashboard
  95. {
  96. [self goToSpringBoardFirstPage];
  97. [self.springboard swipeRight];
  98. [self.testedApplication fb_waitUntilStable];
  99. NSPredicate *predicate =
  100. [NSPredicate predicateWithFormat:
  101. @"%K IN %@",
  102. FBStringify(XCUIElement, identifier),
  103. @[@"SBSearchEtceteraIsolatedView", @"SpotlightSearchField"]
  104. ];
  105. FBAssertWaitTillBecomesTrue([[self.springboard descendantsMatchingType:XCUIElementTypeAny] elementMatchingPredicate:predicate].fb_isVisible);
  106. FBAssertWaitTillBecomesTrue(!self.springboard.icons[@"Calendar"].fb_isVisible);
  107. }
  108. - (void)goToScrollPageWithCells:(BOOL)showCells
  109. {
  110. [self.testedApplication.buttons[@"Scrolling"] tap];
  111. [self.testedApplication fb_waitUntilStable];
  112. FBAssertWaitTillBecomesTrue(self.testedApplication.buttons[@"TableView"].fb_isVisible);
  113. [self.testedApplication.buttons[showCells ? @"TableView": @"ScrollView"] tap];
  114. [self.testedApplication fb_waitUntilStable];
  115. FBAssertWaitTillBecomesTrue(self.testedApplication.staticTexts[@"3"].fb_isVisible);
  116. }
  117. - (void)clearAlert
  118. {
  119. [self.testedApplication fb_waitUntilStable];
  120. [[FBAlert alertWithApplication:self.testedApplication] dismissWithError:nil];
  121. [self.testedApplication fb_waitUntilStable];
  122. FBAssertWaitTillBecomesTrue(self.testedApplication.alerts.count == 0);
  123. }
  124. @end