Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @implementation XCUIElement (XCUIElement_IHateApple)
  2.  
  3. - (void)forceTap {
  4.     if (self.hittable) {
  5.         [self tap];
  6.     } else {
  7.         XCUICoordinate *coordinate = [self coordinateWithNormalizedOffset:CGVectorMake(0, 0)];
  8.         [coordinate tap];
  9.     }
  10. }
  11.  
  12. - (void)waitForHittable:(XCTestCase *)delegate {
  13.     [self waitExists:delegate];
  14.     [self waitFor:@"isHittable == true" Application:delegate];
  15. }
  16.  
  17.  
  18. - (void)waitExists:(XCTestCase *)delegate {
  19.     [self waitFor:@"exists == true" Application:delegate];
  20. }
  21.  
  22. - (void)waitNoHittable:(XCTestCase *)delegate {
  23.     [self waitFor:@"isHittable == false" Application:delegate];
  24. }
  25.  
  26. - (void)waitFor:(NSString *)predicateString Application:(XCTestCase *)delegate {
  27.     NSUInteger line = __LINE__;
  28.     NSString *file = [NSString stringWithUTF8String:__FILE__];
  29.     NSPredicate *existsPredicate = [NSPredicate predicateWithFormat:predicateString];
  30.  
  31.     [delegate expectationForPredicate:existsPredicate evaluatedWithObject:self handler:nil];
  32.  
  33.     [delegate waitForExpectationsWithTimeout:15 handler:^(NSError *_Nullable error) {
  34.         if (error != nil) {
  35.             NSString *message = [NSString stringWithFormat:@"Failed to find %@ after %d seconds", self, 15];
  36.             [delegate recordFailureWithDescription:message inFile:file atLine:line expected:YES];
  37.         }
  38.     }];
  39. }
  40.  
  41. - (BOOL)cleanTextField {
  42.     NSString *textFieldString = [self value];
  43.     if ([textFieldString length] > 0) {
  44.         [self tap];
  45.         NSMutableString *deleteString = [[NSMutableString alloc] init];
  46.         NSUInteger length = textFieldString.length;
  47.         unichar buffer[length + 1];
  48.         [textFieldString getCharacters:buffer range:NSMakeRange(0, length)];
  49.         for (int i = 0; i < length; i++) {//            NSLog(@"%C", buffer[i]);
  50.             [deleteString appendString:XCUIKeyboardKeyDelete];
  51.         }
  52.         [self typeText:deleteString];
  53.         return YES;
  54.     }
  55.     return NO;
  56. }
  57.  
  58. - (void)enterTextWithClean:(NSString *)data {
  59.     if (![self cleanTextField])
  60.         [self tap];
  61.     [self typeText:data];
  62.     XCTAssertTrue([[self value] isEqualToString:data]);
  63. }
  64.  
  65.  
  66. - (void)clickNext {
  67.     [self.buttons[@"Next"] tap];
  68. }
  69.  
  70. - (void)clickDone {
  71.     [self.buttons[@"Done"] tap];
  72. }
  73.  
  74. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement