UITest unable to find accessibilityLabel string












0














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?










share|improve this question






















  • 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
















0














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?










share|improve this question






















  • 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














0












0








0







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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 2:45









Alan Scarpa

1,74431441




1,74431441












  • 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










  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()