可以使用KIF点击UITextViews中的链接吗?使用可访问性检查器似乎将UITextView视为单个视图,并且似乎无法识别链接。
发布于 2015-09-11 03:57:23
似乎UITextView对象中的链接需要比使用KIF的标准点击更长的按键才能激活。我通过使用KIFUITestActor上的一个类别编写自己的测试步骤解决了这个问题。代码试图在UITextView中找到您想要点击的文本,然后长按它。
- (void)tapText:(NSString *)text inTextViewWithAccessibilityIdentifier:(NSString *)identifier
{
[self runBlock:^KIFTestStepResult(NSError *__autoreleasing *error) {
UITextView *textView = nil;
UIAccessibilityElement *element = nil;
[self waitForAccessibilityElement:&element view:&textView withIdentifier:identifier tappable:YES];
KIFTestCondition([textView isKindOfClass:[UITextView class]], error, @"The accessibility element is not a UITextView");
NSRange range = [[textView.textStorage string] rangeOfString:text];
KIFTestCondition(range.length > 0, error, @"The text '%@' was not found in UITextView with accessibility identifier: %@", text, identifier);
range.length = 1;
range = [textView.layoutManager glyphRangeForCharacterRange:range actualCharacterRange:nil];
CGRect rect = [textView.layoutManager boundingRectForGlyphRange:range inTextContainer:textView.textContainer];
rect = CGRectOffset(rect, textView.textContainerInset.left, textView.textContainerInset.top);
CGPoint point = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
[textView longPressAtPoint:point duration:0.1f];
return KIFTestStepResultSuccess;
}];
}https://stackoverflow.com/questions/28201958
复制相似问题