FBW3CTypeActionsTests.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 "XCUIElement.h"
  12. #import "XCUIElement+FBTyping.h"
  13. #import "XCUIApplication+FBTouchAction.h"
  14. #import "XCUIElement+FBWebDriverAttributes.h"
  15. #import "FBRuntimeUtils.h"
  16. #import "FBXCodeCompatibility.h"
  17. @interface FBW3CTypeActionsTests : FBIntegrationTestCase
  18. @end
  19. @implementation FBW3CTypeActionsTests
  20. - (void)setUp
  21. {
  22. [super setUp];
  23. [self launchApplication];
  24. [self goToAttributesPage];
  25. }
  26. - (void)testErroneousGestures
  27. {
  28. if (![XCPointerEvent.class fb_areKeyEventsSupported]) {
  29. return;
  30. }
  31. NSArray<NSArray<NSDictionary<NSString *, id> *> *> *invalidGestures =
  32. @[
  33. // missing balance 1
  34. @[@{
  35. @"type": @"key",
  36. @"id": @"keyboard",
  37. @"actions": @[
  38. @{@"type": @"keyDown", @"value": @"h"},
  39. @{@"type": @"keyUp", @"value": @"k"},
  40. ],
  41. },
  42. ],
  43. // missing balance 2
  44. @[@{
  45. @"type": @"key",
  46. @"id": @"keyboard",
  47. @"actions": @[
  48. @{@"type": @"keyDown", @"value": @"h"},
  49. ],
  50. },
  51. ],
  52. // missing balance 3
  53. @[@{
  54. @"type": @"key",
  55. @"id": @"keyboard",
  56. @"actions": @[
  57. @{@"type": @"keyUp", @"value": @"h"},
  58. ],
  59. },
  60. ],
  61. // missing key value
  62. @[@{
  63. @"type": @"key",
  64. @"id": @"keyboard",
  65. @"actions": @[
  66. @{@"type": @"keyUp"},
  67. ],
  68. },
  69. ],
  70. // wrong key value
  71. @[@{
  72. @"type": @"key",
  73. @"id": @"keyboard",
  74. @"actions": @[
  75. @{@"type": @"keyUp", @"value": @500},
  76. ],
  77. },
  78. ],
  79. // missing duration value
  80. @[@{
  81. @"type": @"key",
  82. @"id": @"keyboard",
  83. @"actions": @[
  84. @{@"type": @"pause"},
  85. ],
  86. },
  87. ],
  88. // wrong duration value
  89. @[@{
  90. @"type": @"key",
  91. @"id": @"keyboard",
  92. @"actions": @[
  93. @{@"type": @"duration", @"duration": @"bla"},
  94. ],
  95. },
  96. ],
  97. ];
  98. for (NSArray<NSDictionary<NSString *, id> *> *invalidGesture in invalidGestures) {
  99. NSError *error;
  100. XCTAssertFalse([self.testedApplication fb_performW3CActions:invalidGesture elementCache:nil error:&error]);
  101. XCTAssertNotNil(error);
  102. }
  103. }
  104. - (void)testTextTyping
  105. {
  106. if (![XCPointerEvent.class fb_areKeyEventsSupported]) {
  107. return;
  108. }
  109. XCUIElement *textField = self.testedApplication.textFields[@"aIdentifier"];
  110. [textField tap];
  111. NSArray<NSDictionary<NSString *, id> *> *typeAction =
  112. @[
  113. @{
  114. @"type": @"key",
  115. @"id": @"keyboard2",
  116. @"actions": @[
  117. @{@"type": @"pause", @"duration": @500},
  118. @{@"type": @"keyDown", @"value": @"🏀"},
  119. @{@"type": @"keyUp", @"value": @"🏀"},
  120. @{@"type": @"keyDown", @"value": @"N"},
  121. @{@"type": @"keyUp", @"value": @"N"},
  122. @{@"type": @"keyDown", @"value": @"B"},
  123. @{@"type": @"keyUp", @"value": @"B"},
  124. @{@"type": @"keyDown", @"value": @"A"},
  125. @{@"type": @"keyUp", @"value": @"A"},
  126. @{@"type": @"keyDown", @"value": @"a"},
  127. @{@"type": @"keyUp", @"value": @"a"},
  128. @{@"type": @"keyDown", @"value": [NSString stringWithFormat:@"%C", 0xE003]},
  129. @{@"type": @"keyUp", @"value": [NSString stringWithFormat:@"%C", 0xE003]},
  130. @{@"type": @"pause", @"duration": @500},
  131. ],
  132. },
  133. ];
  134. NSError *error;
  135. XCTAssertTrue([self.testedApplication fb_performW3CActions:typeAction
  136. elementCache:nil
  137. error:&error]);
  138. XCTAssertNil(error);
  139. XCTAssertEqualObjects(textField.wdValue, @"🏀NBA");
  140. }
  141. - (void)testTextTypingWithEmptyActions
  142. {
  143. if (![XCPointerEvent.class fb_areKeyEventsSupported]) {
  144. return;
  145. }
  146. XCUIElement *textField = self.testedApplication.textFields[@"aIdentifier"];
  147. [textField tap];
  148. NSArray<NSDictionary<NSString *, id> *> *typeAction =
  149. @[
  150. @{
  151. @"type": @"pointer",
  152. @"id": @"touch",
  153. @"actions": @[],
  154. },
  155. ];
  156. NSError *error;
  157. XCTAssertTrue([self.testedApplication fb_performW3CActions:typeAction
  158. elementCache:nil
  159. error:&error]);
  160. XCTAssertNil(error);
  161. XCTAssertEqualObjects(textField.value, @"");
  162. }
  163. @end