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?










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














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?










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












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?










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,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
















  • 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',
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















































 


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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Museum of Modern and Contemporary Art of Trento and Rovereto

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully