UITest unable to find accessibilityLabel string
up vote
0
down vote
favorite
I am trying to write a test that lets me know that my UIAlertController is on screen. The test successfully displays the alert controller, but when I try to assert that it exists, I get a failure. Why is the test failing?
Here is my alert controller code:
let alertController = UIAlertController(title: nil, message: "Group the posts by...", preferredStyle: .actionSheet)
alertController.accessibilityLabel = "Grouping Options"
present(alertController, animated: true, completion: nil)
Here is my test that fails:
func testThatTappingGroupByButtonPresentsAlertController()
let blogPostsNavigationBar = app.navigationBars["Blog Posts"]
blogPostsNavigationBar.buttons["Group By"].tap()
let sheetsQuery = app.sheets
XCTAssert(sheetsQuery["Grouping Options"].exists)
The test works as expected until the assert. I can see the alertController being presented in the simulator. When I run sheetsQuery.count
, I get 1, which is what I expect. It seems like my alertController's accessibility label is not being found. UIAlertController does not have an accessibilityIdentifier, so that's why I'm using accessibilityLabel.
I've also tried setting alertController.isAccessibilityElement = true
but that didn't help either.
Can anyone see what I'm doing wrong here?
ios swift xcode xcode-ui-testing ui-testing
add a comment |
up vote
0
down vote
favorite
I am trying to write a test that lets me know that my UIAlertController is on screen. The test successfully displays the alert controller, but when I try to assert that it exists, I get a failure. Why is the test failing?
Here is my alert controller code:
let alertController = UIAlertController(title: nil, message: "Group the posts by...", preferredStyle: .actionSheet)
alertController.accessibilityLabel = "Grouping Options"
present(alertController, animated: true, completion: nil)
Here is my test that fails:
func testThatTappingGroupByButtonPresentsAlertController()
let blogPostsNavigationBar = app.navigationBars["Blog Posts"]
blogPostsNavigationBar.buttons["Group By"].tap()
let sheetsQuery = app.sheets
XCTAssert(sheetsQuery["Grouping Options"].exists)
The test works as expected until the assert. I can see the alertController being presented in the simulator. When I run sheetsQuery.count
, I get 1, which is what I expect. It seems like my alertController's accessibility label is not being found. UIAlertController does not have an accessibilityIdentifier, so that's why I'm using accessibilityLabel.
I've also tried setting alertController.isAccessibilityElement = true
but that didn't help either.
Can anyone see what I'm doing wrong here?
ios swift xcode xcode-ui-testing ui-testing
Can you try setting the accessibility label on the alert controller's view instead?alertController.view.accessibilityLabel = "Grouping Options"
? It might also be that you need to wait for the existence of the sheet rather than asserting immediately
– Kane Cheshire
Nov 11 at 15:08
Yes! That fixed it. If you want to leave that as an answer, maybe with some more info on why that fixes it, I'll accept the answer. Thanks @KaneCheshire
– Alan Scarpa
Nov 11 at 15:40
Happy to although not really sure why it fixes it, I just remember having to do it before!
– Kane Cheshire
Nov 11 at 16:55
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to write a test that lets me know that my UIAlertController is on screen. The test successfully displays the alert controller, but when I try to assert that it exists, I get a failure. Why is the test failing?
Here is my alert controller code:
let alertController = UIAlertController(title: nil, message: "Group the posts by...", preferredStyle: .actionSheet)
alertController.accessibilityLabel = "Grouping Options"
present(alertController, animated: true, completion: nil)
Here is my test that fails:
func testThatTappingGroupByButtonPresentsAlertController()
let blogPostsNavigationBar = app.navigationBars["Blog Posts"]
blogPostsNavigationBar.buttons["Group By"].tap()
let sheetsQuery = app.sheets
XCTAssert(sheetsQuery["Grouping Options"].exists)
The test works as expected until the assert. I can see the alertController being presented in the simulator. When I run sheetsQuery.count
, I get 1, which is what I expect. It seems like my alertController's accessibility label is not being found. UIAlertController does not have an accessibilityIdentifier, so that's why I'm using accessibilityLabel.
I've also tried setting alertController.isAccessibilityElement = true
but that didn't help either.
Can anyone see what I'm doing wrong here?
ios swift xcode xcode-ui-testing ui-testing
I am trying to write a test that lets me know that my UIAlertController is on screen. The test successfully displays the alert controller, but when I try to assert that it exists, I get a failure. Why is the test failing?
Here is my alert controller code:
let alertController = UIAlertController(title: nil, message: "Group the posts by...", preferredStyle: .actionSheet)
alertController.accessibilityLabel = "Grouping Options"
present(alertController, animated: true, completion: nil)
Here is my test that fails:
func testThatTappingGroupByButtonPresentsAlertController()
let blogPostsNavigationBar = app.navigationBars["Blog Posts"]
blogPostsNavigationBar.buttons["Group By"].tap()
let sheetsQuery = app.sheets
XCTAssert(sheetsQuery["Grouping Options"].exists)
The test works as expected until the assert. I can see the alertController being presented in the simulator. When I run sheetsQuery.count
, I get 1, which is what I expect. It seems like my alertController's accessibility label is not being found. UIAlertController does not have an accessibilityIdentifier, so that's why I'm using accessibilityLabel.
I've also tried setting alertController.isAccessibilityElement = true
but that didn't help either.
Can anyone see what I'm doing wrong here?
ios swift xcode xcode-ui-testing ui-testing
ios swift xcode xcode-ui-testing ui-testing
asked Nov 11 at 2:45
Alan Scarpa
1,73331340
1,73331340
Can you try setting the accessibility label on the alert controller's view instead?alertController.view.accessibilityLabel = "Grouping Options"
? It might also be that you need to wait for the existence of the sheet rather than asserting immediately
– Kane Cheshire
Nov 11 at 15:08
Yes! That fixed it. If you want to leave that as an answer, maybe with some more info on why that fixes it, I'll accept the answer. Thanks @KaneCheshire
– Alan Scarpa
Nov 11 at 15:40
Happy to although not really sure why it fixes it, I just remember having to do it before!
– Kane Cheshire
Nov 11 at 16:55
add a comment |
Can you try setting the accessibility label on the alert controller's view instead?alertController.view.accessibilityLabel = "Grouping Options"
? It might also be that you need to wait for the existence of the sheet rather than asserting immediately
– Kane Cheshire
Nov 11 at 15:08
Yes! That fixed it. If you want to leave that as an answer, maybe with some more info on why that fixes it, I'll accept the answer. Thanks @KaneCheshire
– Alan Scarpa
Nov 11 at 15:40
Happy to although not really sure why it fixes it, I just remember having to do it before!
– Kane Cheshire
Nov 11 at 16:55
Can you try setting the accessibility label on the alert controller's view instead?
alertController.view.accessibilityLabel = "Grouping Options"
? It might also be that you need to wait for the existence of the sheet rather than asserting immediately– Kane Cheshire
Nov 11 at 15:08
Can you try setting the accessibility label on the alert controller's view instead?
alertController.view.accessibilityLabel = "Grouping Options"
? It might also be that you need to wait for the existence of the sheet rather than asserting immediately– Kane Cheshire
Nov 11 at 15:08
Yes! That fixed it. If you want to leave that as an answer, maybe with some more info on why that fixes it, I'll accept the answer. Thanks @KaneCheshire
– Alan Scarpa
Nov 11 at 15:40
Yes! That fixed it. If you want to leave that as an answer, maybe with some more info on why that fixes it, I'll accept the answer. Thanks @KaneCheshire
– Alan Scarpa
Nov 11 at 15:40
Happy to although not really sure why it fixes it, I just remember having to do it before!
– Kane Cheshire
Nov 11 at 16:55
Happy to although not really sure why it fixes it, I just remember having to do it before!
– Kane Cheshire
Nov 11 at 16:55
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245402%2fuitest-unable-to-find-accessibilitylabel-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you try setting the accessibility label on the alert controller's view instead?
alertController.view.accessibilityLabel = "Grouping Options"
? It might also be that you need to wait for the existence of the sheet rather than asserting immediately– Kane Cheshire
Nov 11 at 15:08
Yes! That fixed it. If you want to leave that as an answer, maybe with some more info on why that fixes it, I'll accept the answer. Thanks @KaneCheshire
– Alan Scarpa
Nov 11 at 15:40
Happy to although not really sure why it fixes it, I just remember having to do it before!
– Kane Cheshire
Nov 11 at 16:55