FBElementAttributeTests.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 "FBFindElementCommands.h"
  12. #import "FBTestMacros.h"
  13. #import "FBXCodeCompatibility.h"
  14. #import "XCUIElement+FBAccessibility.h"
  15. #import "XCUIElement+FBIsVisible.h"
  16. #import "XCUIElement+FBWebDriverAttributes.h"
  17. #import "FBXCodeCompatibility.h"
  18. @interface FBElementAttributeTests : FBIntegrationTestCase
  19. @end
  20. @implementation FBElementAttributeTests
  21. - (void)setUp
  22. {
  23. [super setUp];
  24. static dispatch_once_t onceToken;
  25. dispatch_once(&onceToken, ^{
  26. [self launchApplication];
  27. [self goToAttributesPage];
  28. });
  29. }
  30. - (void)testElementAccessibilityAttributes
  31. {
  32. // "Button" is accessibility element, and therefore isn't accessibility container
  33. XCUIElement *buttonElement = self.testedApplication.buttons[@"Button"];
  34. XCTAssertTrue(buttonElement.exists);
  35. XCTAssertTrue(buttonElement.fb_isAccessibilityElement);
  36. XCTAssertFalse(buttonElement.isWDAccessibilityContainer);
  37. }
  38. - (void)testContainerAccessibilityAttributes
  39. {
  40. // "not_accessible" isn't accessibility element, but contains accessibility elements, so it is accessibility container
  41. XCUIElement *inaccessibleButtonElement = self.testedApplication.buttons[@"not_accessible"];
  42. XCTAssertTrue(inaccessibleButtonElement.exists);
  43. XCTAssertFalse(inaccessibleButtonElement.fb_isAccessibilityElement);
  44. if (@available(iOS 13.0, *)) {
  45. // FIXME: Xcode 11 environment returns false even if iOS 12
  46. // We must fix here to XCTAssertTrue if Xcode version will return the value properly
  47. XCTAssertFalse(inaccessibleButtonElement.isWDAccessibilityContainer);
  48. } else {
  49. // Xcode 10 and the below works fine
  50. XCTAssertTrue(inaccessibleButtonElement.isWDAccessibilityContainer);
  51. }
  52. }
  53. - (void)testIgnoredAccessibilityAttributes
  54. {
  55. // Images are neither accessibility elements nor contain them, so both checks should fail
  56. XCUIElement *imageElement = self.testedApplication.images.allElementsBoundByIndex.firstObject;
  57. XCTAssertTrue(imageElement.exists);
  58. XCTAssertFalse(imageElement.fb_isAccessibilityElement);
  59. XCTAssertFalse(imageElement.isWDAccessibilityContainer);
  60. }
  61. - (void)testButtonAttributes
  62. {
  63. XCUIElement *element = self.testedApplication.buttons[@"Button"];
  64. XCTAssertTrue(element.exists);
  65. XCTAssertEqualObjects(element.wdType, @"XCUIElementTypeButton");
  66. XCTAssertEqualObjects(element.wdName, @"Button");
  67. XCTAssertEqualObjects(element.wdLabel, @"Button");
  68. XCTAssertNil(element.wdValue);
  69. XCTAssertFalse(element.wdSelected);
  70. [element tap];
  71. XCTAssertTrue(element.wdValue.boolValue);
  72. XCTAssertTrue(element.wdSelected);
  73. }
  74. - (void)testLabelAttributes
  75. {
  76. XCUIElement *element = self.testedApplication.staticTexts[@"Label"];
  77. XCTAssertTrue(element.exists);
  78. XCTAssertEqualObjects(element.wdType, @"XCUIElementTypeStaticText");
  79. XCTAssertEqualObjects(element.wdName, @"Label");
  80. XCTAssertEqualObjects(element.wdLabel, @"Label");
  81. XCTAssertEqualObjects(element.wdValue, @"Label");
  82. }
  83. - (void)testIndexAttributes
  84. {
  85. XCUIElement *element = self.testedApplication.buttons[@"Button"];
  86. XCTAssertTrue(element.exists);
  87. XCTAssertEqual(element.wdIndex, 2);
  88. XCUIElement *element2 = self.testedApplication;
  89. XCTAssertTrue(element2.exists);
  90. XCTAssertEqual(element2.wdIndex, 0);
  91. }
  92. - (void)testTextFieldAttributes
  93. {
  94. XCUIElement *element = self.testedApplication.textFields[@"Value"];
  95. XCTAssertTrue(element.exists);
  96. XCTAssertEqualObjects(element.wdType, @"XCUIElementTypeTextField");
  97. XCTAssertNil(element.wdName);
  98. XCTAssertEqualObjects(element.wdLabel, @"");
  99. XCTAssertEqualObjects(element.wdValue, @"Value");
  100. }
  101. - (void)testTextFieldWithAccessibilityIdentifiersAttributes
  102. {
  103. XCUIElement *element = self.testedApplication.textFields[@"aIdentifier"];
  104. XCTAssertTrue(element.exists);
  105. XCTAssertEqualObjects(element.wdType, @"XCUIElementTypeTextField");
  106. XCTAssertEqualObjects(element.wdName, @"aIdentifier");
  107. XCTAssertEqualObjects(element.wdLabel, @"aLabel");
  108. XCTAssertEqualObjects(element.wdValue, @"Value2");
  109. }
  110. - (void)testSegmentedControlAttributes
  111. {
  112. XCUIElement *element = self.testedApplication.segmentedControls.element;
  113. XCTAssertTrue(element.exists);
  114. XCTAssertEqualObjects(element.wdType, @"XCUIElementTypeSegmentedControl");
  115. XCTAssertNil(element.wdName);
  116. XCTAssertNil(element.wdLabel);
  117. XCTAssertNil(element.wdValue);
  118. }
  119. - (void)testSliderAttributes
  120. {
  121. XCUIElement *element = self.testedApplication.sliders.element;
  122. XCTAssertTrue(element.exists);
  123. XCTAssertEqualObjects(element.wdType, @"XCUIElementTypeSlider");
  124. XCTAssertNil(element.wdName);
  125. XCTAssertNil(element.wdLabel);
  126. XCTAssertEqualObjects(element.wdValue, @"50%");
  127. }
  128. - (void)testActivityIndicatorAttributes
  129. {
  130. XCUIElement *element = self.testedApplication.activityIndicators.element;
  131. XCTAssertTrue(element.exists);
  132. XCTAssertEqualObjects(element.wdType, @"XCUIElementTypeActivityIndicator");
  133. XCTAssertEqualObjects(element.wdName, @"Progress halted");
  134. XCTAssertEqualObjects(element.wdLabel, @"Progress halted");
  135. XCTAssertEqualObjects(element.wdValue, @"0");
  136. }
  137. - (void)testSwitchAttributes
  138. {
  139. XCUIElement *element = self.testedApplication.switches.element;
  140. XCTAssertTrue(element.exists);
  141. XCTAssertEqualObjects(element.wdType, @"XCUIElementTypeSwitch");
  142. XCTAssertNil(element.wdName);
  143. XCTAssertNil(element.wdLabel);
  144. XCTAssertEqualObjects(element.wdValue, @"1");
  145. XCTAssertFalse(element.wdSelected);
  146. XCTAssertTrue(element.wdHittable);
  147. [element tap];
  148. XCTAssertEqualObjects(element.wdValue, @"0");
  149. XCTAssertFalse(element.wdSelected);
  150. }
  151. - (void)testPickerWheelAttributes
  152. {
  153. XCUIElement *element = self.testedApplication.pickerWheels[@"Today"];
  154. XCTAssertTrue(element.exists);
  155. XCTAssertEqualObjects(element.wdType, @"XCUIElementTypePickerWheel");
  156. XCTAssertNil(element.wdName);
  157. XCTAssertNil(element.wdLabel);
  158. XCTAssertEqualObjects(element.wdValue, @"Today");
  159. }
  160. - (void)testPageIndicatorAttributes
  161. {
  162. XCUIElement *element = self.testedApplication.pageIndicators.element;
  163. XCTAssertTrue(element.exists);
  164. XCTAssertEqualObjects(element.wdType, @"XCUIElementTypePageIndicator");
  165. XCTAssertNil(element.wdName);
  166. XCTAssertNil(element.wdLabel);
  167. XCTAssertEqualObjects(element.wdValue, @"page 1 of 3");
  168. }
  169. - (void)testTextViewAttributes
  170. {
  171. XCUIElement *element = self.testedApplication.textViews.element;
  172. XCTAssertTrue(element.exists);
  173. XCTAssertEqualObjects(element.wdType, @"XCUIElementTypeTextView");
  174. XCTAssertNil(element.wdName);
  175. XCTAssertNil(element.wdLabel);
  176. XCTAssertEqualObjects(element.wdValue, @"Text Field long text");
  177. }
  178. @end