Closed Przemyslaw-Wosko closed 8 years ago
Since collectionViewCells are UIViews you should just be able to search for the specified AccessibilityIdentifier/Label using the standard methods. Do you have a situation where that isn't working?
ok, i have 20 items in collection view, each collection view cell contains exactly the same set of Accesibility/Identifier labels, what kinda methods should i use to search only in specified cell by index path ?
I would suggest setting the identifier to include the index path in cellForItemAtIndexPath:
, that way you can look for it specifically.
ok, then i have UICollectionViewCell instance returned by this method, and my question was - how to inspect this cell without knowing about implementation? I mean, this cell contains UILabel with some amount, and this label have assigned AccessibilityIdentifier / AccessibilityLabel, i want to search in this specific cell, to get value of this label and validate it using those AccessibilityIdentifier / AccessibilityLabel instead of
MyCell *cell = (MyCell *)[tester cellForItemAtIndexPath:[NSIndexPath cellForRow:0 inSection:0]]
NSString *amount = cell.myLabel.text;
assertThat(amount, is(@"1234,213"));
i want to make something more into back box testing
UICollectionViewCell *cell = [tester cellForItemAtIndexPath:[NSIndexPath cellForRow:0 inSection:0]]
UILabel *myLabel = // something that will find my label in cell / or will return me text of this label
String *amount = myLabel.text; //
// do some assertions
i hope that this example illustrate my needs.
What you're describing seems like it would be trouble for accessibility. If every cell contains a UILabel with the same accessibilityLabel the accessibility user won't have any context about what is currently selected.
I would suggest making your cells accessibility elements, and setting the accessibilityLabel or accessibilityValue as appropriate and then using the accessibilityIdentifier to specify the index path.
that way you can validate it using [viewTester usingIdentifier:{index path}] usingLabel:{what you're trying to validate} ] waitForView];
@RoyalPineapple
[viewTester usingIdentifier:{index path}]
in function usingIdentifier
i have to pass NSString, how to pass NSIndexPath?
edit: i don't know how to make it. but seems to be impossible. view testers chaining functions depends on Predicate, that means to find collection view cell, i will have to pass predicate that will find cell 🎱 i dont know how to do it, or it's even possible
@phatmann @bnickel
is there any possibility to add to viewTester methods that will allow to find elements in UICollectionView/UITableView using NSIndexPath and return KIFUIViewTestActor?
Then those methods could be chained till the last desired element.
i think that this approach could be new big feature for KIF in back-box style tests
@CurlyHeir You would set the indexPath as a string representation in the accessibilityIdentifier of the element and then pass the indexPath as a string representation into KIF.
thx for reply, but probably i don't get it ;( could you explain entire flow?
@CurlyHeir you need to change the accessibility of your collection view. You are trying to verify something on a specific cell but don't have any unique accessibility properties available for KIF to find the specific cell.
My suggestion would be to make sure your UICollectionViewCell
s adhere to the UIAccessibilityProtocol
and have isAccessibilityElement
set to YES
. When you configure the cells in the collectionViewDataSource
you would then set some sort of unique string for each cell in the accessibilityIdentifer
. You could use something like [NSString stringWithFormat:@"%d-%d", indexPath.section, indexPath.row]
to convert your index path into a string. You would then set the cell's accessibilityLabel
to match that of the UILabel
contained within the cell. This will allow you to query for the specific cell and then verify it's accessibility information using a query like this
NSString *index = [NSString stringWithFormat:@"%d-%d", indexPath.section, indexPath.row];
[viewTester usingIdentifier: index] usingLabel: @"My accessibilityLabel" ] waitForView];
this will only match on the cell that has both the accessibilityIdentifier
AND accessibilityLabel
and will fail if it cant be found.
I also recommend these resources for further information https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAccessibility_Protocol/ http://nshipster.com/uiaccessibility/
i ended up by writing some shitty code: i'm passing cell as container and then looking for element with desired identifier in child views
- (UIView *)getViewByAccessibilityIdentifier:(NSString *)identifier inContainer:(UIView *)container {
UIView *view = nil;
[self findViewInContainer:container identifier:identifier foundView:&view];
return view;
}
- (void)findViewInContainer:(UIView *)container identifier:(NSString *)identifier foundView:(out UIView **)item {
NSArray *subviews = [container subviews];
for (UIView *subview in subviews) {
if ([subview.accessibilityIdentifier isEqualToString:identifier]) {
*item = subview;
return;
}
[self findViewInContainer:subview identifier:identifier foundView:item];
}
}
i wanted to avoid implementing something in production code too, but your solution sounds like nice way to handle views through viewTester @RoyalPineapple Thank you for your detailed answer
@kudlaty, Just remember that accessibility labels are read aloud to users who turn on the accessibility feature. This is an opportunity to make your app accessible to visually impaired.
Sent from my iPhone
On Jun 29, 2016, at 3:57 PM, Kudłaty notifications@github.com wrote:
i ended up by writing some shitty code: i'm passing cell as container and then looking for element with desired identifier in child views
- (UIView )getViewByAccessibilityIdentifier:(NSString )identifier inContainer:(UIView )container { UIView view = nil; [self findViewInContainer:container identifier:identifier foundView:&view]; return view; }
- (void)findViewInContainer:(UIView )container identifier:(NSString )identifier foundView:(out UIView )item { NSArray subviews = [container subviews]; for (UIView subview in subviews) { if ([subview.accessibilityIdentifier isEqualToString:identifier]) { *item = subview; return; } [self findViewInContainer:subview identifier:identifier foundView:item]; } } i wanted to avoid implementing something in production code too, but your solution sounds like nice way to handle views through viewTester @RoyalPineapple Thank you for your detailed answer
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
@mikelupo thats way i'm gonna use only accessibility identifiers ;)
@kudlaty Perfect!
-----Original Message----- From: Kudłaty notifications@github.com To: kif-framework/KIF KIF@noreply.github.com Cc: mikelupo mikelupo@aol.com; Mention mention@noreply.github.com Sent: Thu, Jun 30, 2016 7:29 am Subject: Re: [kif-framework/KIF] Check CollectionViewCells content with KIF (#881)
@mikelupo thats way i'm gonna use only accessibility identifiers ;) — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
KIF only gives you methods to tap / wait for collectionViewCell for given index path and identifier.
How to property check content of cell? I'm looking for solution that not includes getting views through reference, but through AccessibilityIdentifiers / AccessibilityLabels.
Is there any standard approach for that?