这是我在代码中设置它的方式:
let userBarButtonItem = UIBarButtonItem(image: userIcon,style: .Plain,target: self,action: Selector("userButtonTapped:")) userBarButtonItem.accessibilityIdentifier = "userBarButtonItem"
然后在UITestCase里面我需要找到这个:
XCUIApplication().otherElements["userBarButtonItem"] //doesnt work,and the reason is:
Assertion Failure: UI Testing Failure – No matches found for “userBarButtonItem” Other
有没有办法如何使用谓词来找到它?
解决方法
这对我有用:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:UIString(@"Sign In") style:UIBarButtonItemStyleDone target:self action:@selector(submitpressed:)]; self.navigationItem.rightBarButtonItem.accessibilityLabel = @"registration-submit-button";
然后我发现了它
app.navigationBars.buttons["registration-submit-button"]