diff --git a/TBUIAutoTest.podspec b/TBUIAutoTest.podspec index 97f6e84..7a26437 100644 --- a/TBUIAutoTest.podspec +++ b/TBUIAutoTest.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "TBUIAutoTest" -s.version = "1.1.5" +s.version = "1.1.6" s.summary = "Generating accessibilityIdentifier for UIAutomation." s.description = <<-DESC TBUIAutoTest generates UIAutomation `accessibilityIdentifier` for you. diff --git a/TBUIAutoTest/UIView+TBUIAutoTest.m b/TBUIAutoTest/UIView+TBUIAutoTest.m index 5a550e5..0eaf335 100644 --- a/TBUIAutoTest/UIView+TBUIAutoTest.m +++ b/TBUIAutoTest/UIView+TBUIAutoTest.m @@ -104,7 +104,22 @@ - (NSString *)tb_accessibilityLabel } } if ([self isKindOfClass:[UITableViewCell class]]) {//UITableViewCell 特殊处理 - self.accessibilityIdentifier = [NSString stringWithFormat:@"(%@)",((UITableViewCell *)self).reuseIdentifier]; + UIView *view = [self superview]; + while (view && [view isKindOfClass:[UITableView class]] == NO) { + view = [view superview]; + } + UITableView *tableView = (UITableView *)view; + NSIndexPath *indexPath = [tableView indexPathForCell:(UITableViewCell *)self]; + self.accessibilityIdentifier = [NSString stringWithFormat:@"(%@-%ld.%ld)", ((UITableViewCell *)self).reuseIdentifier, (long)indexPath.section, (long)indexPath.row]; + } + if ([self isKindOfClass:[UICollectionViewCell class]]) {//UICollectionViewCell 特殊处理 + UIView *view = [self superview]; + while (view && [view isKindOfClass:[UICollectionView class]] == NO) { + view = [view superview]; + } + UICollectionView *collectionView = (UICollectionView *)view; + NSIndexPath *indexPath = [collectionView indexPathForCell:(UICollectionViewCell *)self]; + self.accessibilityIdentifier = [NSString stringWithFormat:@"(%@-%ld.%ld)", ((UICollectionViewCell *)self).reuseIdentifier, (long)indexPath.section, (long)indexPath.row]; } return [self tb_accessibilityLabel]; }