Xcode UI Tests Can't Find Views That Are Added Programmatically

Xcode UI Tests can't find views that are added programmatically

You need to make sure that the container view of your label view (UIEditText?) doesn't have isAccessibilityElement set to YES. If it does it will hide the accessibility of its subviews (your label).

Check Make the Contents of Custom Container Views Accessible in the Accessibility Programming Guide

Can not access the programatically added UIView in XCTest

The line in question is very brittle. It's possible that your app's views are not always available in the same order every time the app launches, depending on race conditions, so what was recorded in your recording session does not necessarily work for all launches of the app. You'll probably find that the code is actually running, but isn't tapping the element you expected.

To make your code less brittle, add an accessibility identifier to the UIView in your app code, and use the otherElements query to find the UIView.

// app code
let view: UIView!
view.accessibilityIdentifier = "myAccessibilityIdentifier"

// UI test code
app.otherElements["myAccessibilityIdentifier"].tap()

UI Testing Failure - Neither element nor any descendant has keyboard focus on secureTextField

This issue caused me a world of pain, but I've managed to figure out a proper solution. In the Simulator, make sure I/O -> Keyboard -> Connect hardware keyboard is off.

Programmatically creating Views in IOS (how does it work)?

To be even more specific to your question, the syntax would be

UIWindow* window = [UIApplication sharedApplication].keyWindow;

UIView *polygonView = [[UIView alloc] initWithFrame: CGRectMake ( 0, 0, 200, 150)];
//add code to customize, e.g. polygonView.backgroundColor = [UIColor blackColor];

[window addSubview:polygonView];
[polygonView release];

This is a pattern you will use for not only this but subviews afterwards. Also, another note is with many of the templates, the viewController is already set up with it's own view. When you want to make a custom view, you create it like above but instead of the method above you set the viewControllers view to the newly created view like so:

viewController.view = polygonView;

Good luck!



Related Topics



Leave a reply



Submit