FBPasteboardTests.m 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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+FBTyping.h"
  12. #import "FBPasteboard.h"
  13. #import "FBTestMacros.h"
  14. #import "FBXCodeCompatibility.h"
  15. @interface FBPasteboardTests : FBIntegrationTestCase
  16. @end
  17. @implementation FBPasteboardTests
  18. - (void)setUp
  19. {
  20. [super setUp];
  21. [self launchApplication];
  22. [self goToAttributesPage];
  23. }
  24. - (void)testSetPasteboard
  25. {
  26. NSString *text = @"Happy pasting";
  27. XCUIElement *textField = self.testedApplication.textFields[@"aIdentifier"];
  28. NSError *error;
  29. BOOL result = [FBPasteboard setData:(NSData *)[text dataUsingEncoding:NSUTF8StringEncoding]
  30. forType:@"plaintext"
  31. error:&error];
  32. XCTAssertTrue(result);
  33. XCTAssertNil(error);
  34. [textField tap];
  35. XCTAssertTrue([textField fb_clearTextWithError:&error]);
  36. [textField pressForDuration:2.0];
  37. XCUIElementQuery *pastItemsQuery = [[self.testedApplication descendantsMatchingType:XCUIElementTypeAny] matchingIdentifier:@"Paste"];
  38. if (![pastItemsQuery.firstMatch waitForExistenceWithTimeout:2.0]) {
  39. XCTFail(@"No matched element named 'Paste'");
  40. }
  41. XCUIElement *pasteItem = pastItemsQuery.firstMatch;
  42. XCTAssertNotNil(pasteItem);
  43. [pasteItem tap];
  44. FBAssertWaitTillBecomesTrue([textField.value isEqualToString:text]);
  45. }
  46. - (void)testGetPasteboard
  47. {
  48. NSString *text = @"Happy copying";
  49. XCUIElement *textField = self.testedApplication.textFields[@"aIdentifier"];
  50. NSError *error;
  51. XCTAssertTrue([textField fb_typeText:text shouldClear:NO error:&error]);
  52. [textField pressForDuration:2.0];
  53. XCUIElement *selectAllItem = [[self.testedApplication descendantsMatchingType:XCUIElementTypeAny]
  54. matchingIdentifier:@"Select All"].firstMatch;
  55. XCTAssertTrue([selectAllItem waitForExistenceWithTimeout:5]);
  56. [selectAllItem tap];
  57. if (SYSTEM_VERSION_LESS_THAN(@"16.0")) {
  58. [textField pressForDuration:2.0];
  59. }
  60. XCUIElement *copyItem = [[self.testedApplication descendantsMatchingType:XCUIElementTypeAny]
  61. matchingIdentifier:@"Copy"].firstMatch;
  62. XCTAssertTrue([copyItem waitForExistenceWithTimeout:5]);
  63. [copyItem tap];
  64. FBWaitExact(1.0);
  65. NSData *result = [FBPasteboard dataForType:@"plaintext" error:&error];
  66. XCTAssertNil(error);
  67. XCTAssertEqualObjects(textField.value, [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding]);
  68. }
  69. - (void)testUrlCopyPaste
  70. {
  71. NSString *urlString = @"http://appium.io?some=value";
  72. NSError *error;
  73. XCTAssertTrue([FBPasteboard setData:(NSData *)[urlString dataUsingEncoding:NSUTF8StringEncoding]
  74. forType:@"url"
  75. error:&error]);
  76. XCTAssertNil(error);
  77. NSData *result = [FBPasteboard dataForType:@"url" error:&error];
  78. XCTAssertNil(error);
  79. XCTAssertEqualObjects(urlString, [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding]);
  80. }
  81. @end