FBTapTest.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 "FBElementCache.h"
  12. #import "FBTestMacros.h"
  13. #import "XCUIDevice+FBRotation.h"
  14. #import "XCUIElement+FBIsVisible.h"
  15. @interface FBTapTest : FBIntegrationTestCase
  16. @end
  17. // It is recommnded to verify these tests with different iOS versions
  18. @implementation FBTapTest
  19. - (void)verifyTapWithOrientation:(UIDeviceOrientation)orientation
  20. {
  21. [[XCUIDevice sharedDevice] fb_setDeviceInterfaceOrientation:orientation];
  22. [self.testedApplication.buttons[FBShowAlertButtonName] tap];
  23. FBAssertWaitTillBecomesTrue(self.testedApplication.alerts.count > 0);
  24. }
  25. - (void)setUp
  26. {
  27. // Launch the app everytime to ensure the orientation for each test.
  28. [super setUp];
  29. [self launchApplication];
  30. [self goToAlertsPage];
  31. [self clearAlert];
  32. }
  33. - (void)tearDown
  34. {
  35. [self clearAlert];
  36. [self resetOrientation];
  37. [super tearDown];
  38. }
  39. - (void)testTap
  40. {
  41. [self verifyTapWithOrientation:UIDeviceOrientationPortrait];
  42. }
  43. - (void)testTapInLandscapeLeft
  44. {
  45. [self verifyTapWithOrientation:UIDeviceOrientationLandscapeLeft];
  46. }
  47. - (void)testTapInLandscapeRight
  48. {
  49. [self verifyTapWithOrientation:UIDeviceOrientationLandscapeRight];
  50. }
  51. - (void)testTapInPortraitUpsideDown
  52. {
  53. if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
  54. XCTSkip(@"Failed on Azure Pipeline. Local run succeeded.");
  55. }
  56. [self verifyTapWithOrientation:UIDeviceOrientationPortraitUpsideDown];
  57. }
  58. - (void)verifyTapByCoordinatesWithOrientation:(UIDeviceOrientation)orientation
  59. {
  60. [[XCUIDevice sharedDevice] fb_setDeviceInterfaceOrientation:orientation];
  61. XCUIElement *dstButton = self.testedApplication.buttons[FBShowAlertButtonName];
  62. [[dstButton coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)] tap];
  63. FBAssertWaitTillBecomesTrue(self.testedApplication.alerts.count > 0);
  64. }
  65. - (void)testTapCoordinates
  66. {
  67. [self verifyTapByCoordinatesWithOrientation:UIDeviceOrientationPortrait];
  68. }
  69. - (void)testTapCoordinatesInLandscapeLeft
  70. {
  71. [self verifyTapByCoordinatesWithOrientation:UIDeviceOrientationLandscapeLeft];
  72. }
  73. - (void)testTapCoordinatesInLandscapeRight
  74. {
  75. [self verifyTapByCoordinatesWithOrientation:UIDeviceOrientationLandscapeRight];
  76. }
  77. - (void)testTapCoordinatesInPortraitUpsideDown
  78. {
  79. if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
  80. XCTSkip(@"Failed on Azure Pipeline. Local run succeeded.");
  81. }
  82. [self verifyTapByCoordinatesWithOrientation:UIDeviceOrientationPortraitUpsideDown];
  83. }
  84. @end