Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @implementation XCUIElement (XCUIElement_IHateApple)
- - (void)forceTap {
- if (self.hittable) {
- [self tap];
- } else {
- XCUICoordinate *coordinate = [self coordinateWithNormalizedOffset:CGVectorMake(0, 0)];
- [coordinate tap];
- }
- }
- - (void)waitForHittable:(XCTestCase *)delegate {
- [self waitExists:delegate];
- [self waitFor:@"isHittable == true" Application:delegate];
- }
- - (void)waitExists:(XCTestCase *)delegate {
- [self waitFor:@"exists == true" Application:delegate];
- }
- - (void)waitNoHittable:(XCTestCase *)delegate {
- [self waitFor:@"isHittable == false" Application:delegate];
- }
- - (void)waitFor:(NSString *)predicateString Application:(XCTestCase *)delegate {
- NSUInteger line = __LINE__;
- NSString *file = [NSString stringWithUTF8String:__FILE__];
- NSPredicate *existsPredicate = [NSPredicate predicateWithFormat:predicateString];
- [delegate expectationForPredicate:existsPredicate evaluatedWithObject:self handler:nil];
- [delegate waitForExpectationsWithTimeout:15 handler:^(NSError *_Nullable error) {
- if (error != nil) {
- NSString *message = [NSString stringWithFormat:@"Failed to find %@ after %d seconds", self, 15];
- [delegate recordFailureWithDescription:message inFile:file atLine:line expected:YES];
- }
- }];
- }
- - (BOOL)cleanTextField {
- NSString *textFieldString = [self value];
- if ([textFieldString length] > 0) {
- [self tap];
- NSMutableString *deleteString = [[NSMutableString alloc] init];
- NSUInteger length = textFieldString.length;
- unichar buffer[length + 1];
- [textFieldString getCharacters:buffer range:NSMakeRange(0, length)];
- for (int i = 0; i < length; i++) {// NSLog(@"%C", buffer[i]);
- [deleteString appendString:XCUIKeyboardKeyDelete];
- }
- [self typeText:deleteString];
- return YES;
- }
- return NO;
- }
- - (void)enterTextWithClean:(NSString *)data {
- if (![self cleanTextField])
- [self tap];
- [self typeText:data];
- XCTAssertTrue([[self value] isEqualToString:data]);
- }
- - (void)clickNext {
- [self.buttons[@"Next"] tap];
- }
- - (void)clickDone {
- [self.buttons[@"Done"] tap];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement