How to access images in UIATablecell - ios

I'm trying to validate that an image is showing/hidden using UIAutomation on iOS7.
The problem that i'm running into is that .cells()[0].images() always return [object UIAElementNil] even though I can see my image.
I also tried calling images() on the main window, but no luck either.
Any help appreciated.
Thanks.

This is not possible in UI Automation. Table cells don't let you access anything inside, which is caused by the way UI Automation works an how the cell hierarchy looks like.
You could do some changes to your implementation and make your cell images accessible in UI Automation by using UIAccessibilityContainer methods. However, that's a bit complicated.
You can also inspect value(). UI Automation converts all cell content views into a string and sometimes it is possible to check content just by checking this one string.
If everything fails, just go for another testing framework. There are several open source & paid frameworks that are more robust and much more documented than UI Automation.

Related

Is it possible to get an `XCUIElement` by its `accessibilityId` when it is not an accessibility element?

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.

Interface Builder PREVIEW using IBDesignable and core graphics (drawrect)?

I have lots of views - sub classes (UILabel, UIVIew, UIButton etc) using core graphics (within drawrect).
These show fine within normal interface builder.
However they do not show in the preview assistant editor for the storyboard (where you can see how views should look on actual devices).
I've been doing some research and found posts suggesting prepareForInterfaceBuilder should be used. However this doesn't show in preview for me.
I asked this question some years ago, IB_DESIGNABLE, having views show in preview? however I can't reproduce this, I'm not convinced it did work back then either.
I'm still following the same approach, with a framework and that link shows my implementation.
I know that prepareForInterfaceBuilder should be used to do something different, to show something basic. Therefore I believe that core graphics won't work.
However, I can't even get a simple change in background color to work in the preview, although it does work in normal interface builder.
I would like to know if this is a bug (that core graphics can not be used in preview) or still a limitation in xcode?
At the very least I'd like to do something simple (like a change in background color). I have a lot of views and an impossible task to make auto layout changes.
Previously I was producing lots of screen shots, different devices, languages etc (via automation) just so I could see my auto layout changes, which is really slow way to work.
I can verify this is a long standing bug. Apple doesn't care. Custom view be damned. All those dollars spent for more broken Xcode functionality.
Android?
Daniel

Fill the View Controller with elements/objects from web/cloud swift

I have a TableViewController which is connected to a empty-"template" viewController. I would like to make each cell responsible for its own interface/design.
In other words: the viewController has all elements placed (like UIImage, UILabel, UIText, etc.) and each time when specific cell is selected the viewController starts to fill with specific images/resources. Moreover, it would be great if the resources will be taken from web or cloud (in order to not save everything in the application itself).
So, I imagine it somehow like this:
Flow sketch
The problem is that I deal with this for the first time, and tried to find different ways to solve this problem (in terms of implementation), therefore I would like to ask: does this idea can be implemented in this way or probably there is more reliable way, and which techniques or technology can be used for this realization?
Thank you!
You can do it in multiple approaches. It totally depends on the architecture you have been following.
You can use react/ key-value observing and set the keys when you get a response.
Alternatively, for a very small app or a POC, I would use alamofire as my network manager and as soon as I get a response, I would set the labels. I would use the image extension in alamofire to set the images as it takes more time to download.
I would want to know the exact problem you are facing to help you out. Generic discussion are not normally encouraged here.

Specific UI Testing in Xcode 7

I am new to UI Testing in Xcode 7, and I find it very difficult to determinate how can I test multiple details about my app. I have been able to test the basic things, such as different labels exist, and their values are changed when I tap the corresponding buttons.
However, I have no idea how can I test that the color of these labels changes to the one desired, or that a new screen is presented modally when I tap a button. After searching in Google and Stackoverflow I have found nothing but the basic tutorials that let me test what I have already accomplished. How should I proceed to expand my tests and make them actually useful?
There are some limitations. I don't believe testing color (or fonts for example) is possible... yet. However you can definitely test the navigation from screen to screen...
XCTAssertTrue(app.navigationBars["ViewControllerTitle"].exists)
Of course, it all depends on how your screen works. In the example, we're assuming there is a disabled navigation bar label. You just have to find something visual (text) on the screen that uniquely identifies it. It does take some getting used to.
As stated, the specifics for testing for color are not yet possible. However, you might want to consider Unit Tests for that. You can test GUI components for color in those. That's where the line between Unit and UI Testing can get a bit blurry. But, if you need to test for color, that is one way to do it.

Setting properties of UI elements without having to restart simulator

I have a lot of UI elements on my screen, and I have to tweak their appearance to perfection including the frame, text color, background, color, corner radius, etc. Each tiny tweak means that I have to re-compile the code and restart the simulator - and it can take 5-6 seconds per iteration, which is very time consuming (and annoying) when 100's of tweaks have to be made by trial and error. My question is if there are any techniques to instantly update the properties of each UI element WITHOUT having to recompile the code and relaunch the simulator.
One technique I had in mind is to embed a UIWebView which will automatically download a json from a localhost server that contains all the UI elements and their properties. I would have Grunt Server running on my local machine and it would detect any change made to that json file and cause the UIWebView to refresh and download the new json after every edit. There would be a handler in my code which will set the UI element properties to the new values contained in that json. This way I can just have the simulator and a text editor side by the side and I can see how the changes I make in the json impact the appearance of the UI elements instantly.
Perhaps there are other developers out there who have had the same issue and can share how they overcame this annoying problem. I don't like using nib files - so please don't tell me to use nib files :) Even with .xib files, you still have to compile them.
Make a second little viewController subclass with UISliders etc you can set to do various things, rgba for a colour for example, set up a quick and dirty protocol to push these values back to root viewController and redraw element in question, then pop the second view controller modally to tweak stuff (inside a UIPopover on iPad simulator would probably be easiest. This could become a nice reusable 'skinning' class that you use in development, just need a tool item or button to trigger it)
Probably NSLog the values as well so when you finalize something you can hardcode or typedef it in

Resources