FBTypingTest.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. @interface FBTypingTest : FBIntegrationTestCase
  14. @end
  15. @implementation FBTypingTest
  16. - (void)setUp
  17. {
  18. [super setUp];
  19. [self launchApplication];
  20. [self goToAttributesPage];
  21. }
  22. - (void)testTextTyping
  23. {
  24. NSString *text = @"Happy typing";
  25. XCUIElement *textField = self.testedApplication.textFields[@"aIdentifier"];
  26. NSError *error;
  27. XCTAssertTrue([textField fb_typeText:text shouldClear:NO error:&error]);
  28. XCTAssertNil(error);
  29. XCTAssertEqualObjects(textField.value, text);
  30. }
  31. - (void)testTextTypingOnFocusedElement
  32. {
  33. NSString *text = @"Happy typing";
  34. XCUIElement *textField = self.testedApplication.textFields[@"aIdentifier"];
  35. [textField tap];
  36. XCTAssertTrue(textField.hasKeyboardFocus);
  37. NSError *error;
  38. XCTAssertTrue([textField fb_typeText:text shouldClear:NO error:&error]);
  39. XCTAssertNil(error);
  40. XCTAssertTrue([textField fb_typeText:text shouldClear:NO error:&error]);
  41. XCTAssertNil(error);
  42. NSString *expectedText = [NSString stringWithFormat:@"%@%@", text, text];
  43. XCTAssertEqualObjects(textField.value, expectedText);
  44. }
  45. - (void)testTextClearing
  46. {
  47. XCUIElement *textField = self.testedApplication.textFields[@"aIdentifier"];
  48. [textField tap];
  49. [textField typeText:@"Happy typing"];
  50. XCTAssertTrue([textField.value length] > 0);
  51. NSError *error;
  52. XCTAssertTrue([textField fb_clearTextWithError:&error]);
  53. XCTAssertNil(error);
  54. XCTAssertEqualObjects(textField.value, @"");
  55. XCTAssertTrue([textField fb_typeText:@"Happy typing" shouldClear:YES error:&error]);
  56. XCTAssertTrue([textField fb_typeText:@"Happy typing 2" shouldClear:YES error:&error]);
  57. XCTAssertEqualObjects(textField.value, @"Happy typing 2");
  58. XCTAssertNil(error);
  59. }
  60. @end