Is it possible to avoid accessibility labels when using UIAutomation?
If you want it to be seen by UIAutomation but not by applications like VoiceOver, you should use accessibilityIdentifier property of UIAccessibilityIdentification Protocol.
It allows you to set the value later seen trough UIAElement.name
Normally when not set, name is copied from the label.
But when the second is seen by VoiceOver the first one is not.
This is available in iOS 5.0 and later.
You can as well look at the UIAccessibility Protocol it has some more nice tricks.
Unless your app is very simple*, it is not. UIAutomation relies on accessibility labels.
Even if you could do this, you would not save any effort, you would still need to provide some way for UIAutomation to identify your UI elements.
* the simple case would be where there is only one distinct UIView subclass on screen at once. In this case, UIAutomation will generate anonymous references to the unanamed element which allow your scripts to hobble along. It is very brittle though.
In general, you have two ways to access an element : by its label or by its rank.
Example :
target.frontMostApp().mainWindow().tableViews()[0]
or target.frontMostApp().mainWindow().tableViews()["Contents"]
You can choose which one you want to use in UIAutomation by clicking on the element in the script editor.
Related
I have custom UITableViewCell with some child images and labels. I have made the entire cell as a single accessible element. I have set accessibility ids to all the elements - cell and its subviews, hoping to be able to use it in the XCUITests.
Now, I am not able to get the image, say, using XCUIApplication().images["cell_image_acc_id"].
What should I do to get these elements? I am a newbie at XC ui testing. Please let me know if there is something basic that I am missing.
Thanks in advance.
If you set up a view as an accessibility element its subviews are not available for VoiceOver users, and as a result not testable. While it is good for accessibility users, it may affect testability.
You can pass an environmental variable or a launch argument for your app while testing. Do not set isAccessibilityElement in your app code if such variable (or an argument) is set.
https://developer.apple.com/documentation/objectivec/nsobject/1615141-isaccessibilityelement
https://developer.apple.com/documentation/xctest/xcuiapplication/1500477-launcharguments
https://developer.apple.com/documentation/xctest/xcuiapplication/1500427-launchenvironment
How to detect if iOS app is running in UI Testing mode
This way you can still deliver a great experience for VoiceOver users and test your code properly.
iOS has built-in support for accessibility, for UIButtons it reads the title of the button followed by a hint "double tap to activate" (by default). Sometimes we are required to make a non-UIButton control behaving similar to UIButton in terms of accessibility, so we would set its accessibility trait to button and hardcode "double tap to activate" for accessibilityHint.
I don't like altering system behaviours, and I've seen accessibility users who prefer single tap instead of double tap (there's an option they can set), although I haven't checked if the opt for single tap instead of double tap, does the system hint become "single tap to activiate".
What is the common practice regarding accessibility support for a non-UIButton control that is tappable? Thanks!
I've seen accessibility users who prefer single tap instead of double tap (there's an option they can set)
I'm really curious to know how it's possible using VoiceOver because a single tap with one finger deals with the accessibility focus. In the UIButton documentation, Apple states: 🤓
VoiceOver speaks the value of the title [...] when a user taps the button once.
Would you mind detailing the way to activate this option you mentioned because I'm really astonished, please? 🤔
What is the common practice regarding accessibility support for a non-UIButton control that is tappable?
Using a hint is a very good practice to provide useful information to the user but this information mustn't be crucial for using because the accessibility hint may be deactivated in the device settings.😰
Admittedly speaking, this kind of element must be read out in such a way that its goal and its using are clear enough for any user: that's what traits are made for. 👍
Many traits are well known and give rise to different actions like adjustable values, customed actions and the rotor items using.
Besides, it's also possible to use the accessibilityActivate() method so as to define the purpose of a double-tap with one finger of an accessible element. 🤯
The way you want to vocally expose the possible actions on a tappable control depends on the content of your application.
Finally, keep in mind that hardcoding a hint must be understood as a plus information but definitely not as an essential one because it can be deactivated by the user: a conception oriented a11y is very important when building an app. 😉
I have completed making an IOS app. Now its been final and was ready to upload, but suddenly I was given a task to apply a new thing in the app and that is as Under
When user increases text size From the Settings > Accessibility > Larger Text or from Settings > Display And Brightness > TextSize now my app text appearance must change accordingly.
What I want: As I told you above that app is completed, and as I have used too many UILabels, UIButtons and UITextViews, so I am finding a way to how to change their text size accordingly to newly changed text size by the user. Is it possible to add any extension that increase the text size of app in more generic way. so that I do not have to go to every view in storyboard to make the view of dynamic type.
The process of changing and converting every view or coding in every class will be cumbersome. Is there any short way to handle it while everything is already completed.
Please help thanks.
The process of changing and converting every view or coding in every class will be cumbersome. Is there any short way to handle it while everything is already completed.
I'm sorry to tell you that implementing the Dynamic Type feature in an already existing app is never easy and quick to be done.
It's like making the design, it takes time and requires conception for adapting the ergonomic a11y to provide the best user experience.
Even if many things can be done in the Interface Builder, I prefer to handle everything in code because you can mutualize many properties and methods while it's element by element in the IB.
Among other things, you'll have to:
Use the text styles and activate the adjustsFontForContentSizeCategory properties of your elements to have an automatic update of your system font size.
Listen to the traitCollectionDidChange method that belongs to the UITraitEnvironment informal protocol to be aware of the font size settings changes.
Use dynamic values for adapting all your constraints so as to reorder appropriately every single element and make the containers fit their contents according to the different font size settings.
Adapt and customize every Large Content Viewers to enlarge UI elements when the Dynamic Type can't be applied (only since iOS 13).
There's no magic trick to make an app with the Dynamic Type support: you have to know how it works and then build every element as you do in your daily programming.
Hereunder few links that may help to reach your goal:
A detailed summary of the WWDC video 'Building Apps with Dynamic Type' where every steps are explained with a complete example in the end.
Some code snippets (ObjC + Swift) and illustrations to provide explanations for code implementation.
Few outlines to have in mind when testing a Dynamic Type implementation.
All these information could help you make your app with the Dynamic Type support.
I have a somewhat customized UIPickerView in my app. Basically I use pickerView:viewForRow:forComponent:reusingView returning a simple UILabel. As I started working on making the app more accessible, I noticed that VoiceOver reads label and adds, say, "3 of 300" (i.e. row number "of" total rows). This is not a desired behavior.
While trying to troubleshoot this, I found that if I use pickerView:titleForRow:forComponent instead of pickerView:viewForRow:forComponent:reusingView, without any other changes, then I get the desired behavior of VoiceOver simply reading the "title" of the selected row. I tested this on iOS 9.
Question is: how do I get UIPickerView back to the "normal" VoiceOver behavior, while still using pickerView:viewForRow:forComponent:reusingView? Thanks for any help!
I asked Apple support for help on this. The official reply was: "Our engineers have reviewed your request and have concluded that there is no supported way to achieve the desired functionality given the currently shipping system configurations". (For posterity - this was when the newest iOS version was 9.4). They suggested to file a request for new functionality, which I may do.
To solve this problem I went with the following workaround.
Created a base class almost identical to the class I had, but implementing only pickerView:titleForRow:forComponent and not pickerView:viewForRow:forComponent:reusingView. This class presents vanilla non-customized picker.
Created a subclass of that base class, now implementing pickerView:viewForRow:forComponent:reusingView. This class presents a fully customized picker.
In my code elsewhere used UIAccessibilityIsVoiceOverRunning() to create an object of base class when VoiceOver is on, and an object of the subclass otherwise
Thus when a user is running VoiceOver, they get a visually ugly picker, but one that is perfectly well-behaved in terms of accessibility (i.e. no row number announcements). Which is a perfectly reasonable "compromise" I think, since the user is basically guaranteed not to care about the visual appearances.
One fix will be to check if voice over is running
UIAccessibilityIsVoiceOverRunning()
If so use titleForRow otherwise use viewForRow. That way you don't degrade normal experience.
Simple question. Does anyone know why Interface Builder doesn't allow for applying custom styles on UI elements? Why is it only possible to do this programmatically?
I can see how this might be difficult for custom UIView subclasses but the default controls definitely only have a tiny subset of the style options available through IB, such as background color or changing font colors. Why is this the case? Is there any way to approach a concept like application themes through IB?
My personal feeling is that Apple does this right. They provide the elements and styles that fit the HIG. If they start adding other elements/styles then where do the start, and where do they draw the line?
Also, it isn't like Apple actively prevents using custom elements/styles, they just don't include it in the tool set.
The last thing we need is a tool set full of bloat.
You'd really have to ask Apple as to the why. I'd guess that it's some combination of promoting consistent use of standard interface elements and limited development resources.
You can, of course, build interfaces using your own custom subclasses of the standard interface elements in IB. It's a little more work, since you have to change the type of each object you add from UIButton to MyGreenButton or whatever, but it's not difficult.
It's also not hard to imagine coming up with a controller-type class that could connect to all your controls and whatnot to customize their appearance in some consistent, theme-like manner. Add an instance of that to each nib, connect all the controls, and let it do it's thing. You wouldn't see the effect until you actually run the app, of course, but it sounds like you're talking about customizing colors and fonts rather than size.
Unfortunately you are at the mercy of the Almighty Apple Deity..... Bow at their feet and give thanks that you have what they give you..... lol...
Seriously tho. Apple puts in what apple wants and you can request additions, but the IB is fairly minimal in the way of features.
I think this may be by design. Somehow an Elegant Simplicity ?
The ability to customize the controls is given to the programmer however I think they want the controls standardized. I just dont know why they didnt give a little more variety in the controls that are available. Like a few more button styles for the ios devices...
If you find out otherwise I would definitely be all ears.
I think that apple should let you to customize more the controls, for games it takes too much time to make the custom control ( you can make it faster in android as you can configure it in xml)
Btw PaintCode is another option to make your own style for components, it will generate the code but its more like interface builder
http://www.paintcodeapp.com/