I have created a series of UI Tests that run fine on a device but when using a Simulator, I cannot tap alert view buttons.
let alert = app.alerts["Continue"]
alert.buttons["Yes"].tap()
Instead, it crashes with
Find: Descendants matching type Button
t = 10.17s Find: Elements matching predicate '"Yes" IN identifiers'
t = 10.18s Check for interrupting elements affecting "Yes" Button
t = 10.19s Requesting snapshot of accessibility hierarchy for app with pid 14120
t = 10.21s Find: Descendants matching predicate identifier == "NotificationShortLookView" OR elementType == 7
*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil (NSInvalidArgumentException)
I believe (and hope) this is an Xcode 13 bug and may be fixed in an update soon.
Does any one know a way around this?
Turns out this is only an issue when running on an iOS 12 simulator. It is ok when running on an iOS 15.4 simulator.
Related
So I've worked on this App which should display a map, add annotations on coordinates found by Mapbox SearchUI, and start Navigating there when requesting it. It all worked fine until I opened xcode and tried to build today. I have the impression that MapBox updated Mapbox SearchUI (I am calling pod 'MapboxSearchUI', ">= 1.0.0-beta", "< 2.0" and it seems like XCode then uses 1.0.0-beta.2). Everything still works except one breaking thing: when trying to search stuff in the searchUI search bar, the app cant display the results, resulting in a timeout.
2021-10-13 13:51:15.300321+0200 APP[10454:5269100] [LayoutConstraints] Changing the translatesAutoresizingMaskIntoConstraints property of a UITableViewCell that is managed by a UITableView is not supported, and will result in incorrect self-sizing. Cell: <MapboxSearchUI.SearchSuggestionCell: 0x1138f7000; baseClass = UITableViewCell; frame = (0 0; 442 68); clipsToBounds = YES; autoresize = RM+BM; layer = <CALayer: 0x280d99980>>
2021-10-13 13:51:15.300463+0200 APP[10454:5269100] *** Assertion failure in -[MapboxSearchUI.SearchSuggestionCell _setHostsLayoutEngine:], NSLayoutConstraint_UIKitAdditions.m:3806
2021-10-13 13:51:15.301220+0200 APP[10454:5269100] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Must translate autoresizing mask into constraints to have _setHostsLayoutEngine:YES.'
Seems like XCode has trouble with MapBox's Layout for the results. This explains why searching from shortcuts such as Gas stations work fine since they don't need to display search results in the searchUI, doing it on the map instead.
Does anyone know how to work around this? Or is there a way to know what version exactly I was using a few weeks back? The weird thing is that I did not update the pods or mess with other parts of the project. It was on hold there and now it won't work anymore.
Thanks!
I've recently come across the same error message (and visual effect) in a codebase which does not use MapBox. The error started to occur only when the project was built using Xcode 13/iOS 15 instead of Xcode 12/iOS 14 (which was used before). The error only occurred on simulators/devices running iOS 15, not on iOS 14.
The codebase was, as the error message suggests, setting the translatesAutoresizingMaskIntoConstraints = false in multiple UITableViewCell's awakeFromNib() methods. Removing the line caused the error message to disappear and the contents to be displayed correctly on both, iOS 14 and iOS 15.
In your case, this will likely have to be addressed by the team at MapBox and a new SDK version would have to be provided including the change.
Apple has re-designed the share sheet that appears, which has now broken my UI tests.
I have attempted to record a new UI test through Xcode, but as soon as I tap on the dismiss button, the test terminates so I have not been able to capture the event.
Ultimately, I just want to know how I can access the gray 'X' shown with the arrow below:
I have just tested this with Xcode 13 and have found that the original answer no longer works. However, I am keeping it for posterity, or those using previous versions of Xcode.
Xcode 13
I have tested this with Xcode 13.0 and verified it works for iPhone and iPad:
let activityListView = app.otherElements.element(matching: .other,
identifier: "ActivityListView")
XCTAssertTrue(activityListView.waitForExistence(timeout: 2.0))
activityListView.buttons["Close"].tap()
Previous versions
After some trial and error, I was able to locate where my specific elements were with the following:
app.otherElements.element(boundBy: 1).buttons.element(boundBy: 0).tap()
Using app.otherElements.element(boundBy: 1) would identify the share sheet for me. I had attempted to locate it through accessibility identifiers, but I could not find one that worked, including previously valid ones used in iOS 12 and below.
Please note that based on the layout of your screen, the index value
may differ from what I am seeing.
Next, .buttons.element(boundBy: 0).tap() was used to locate the Close button. I again attempted to use identifiers, but could not find anything that represented the button.
When I attempted to discern additional information through the console while testing, I would always wind up crashing the test. This result was surprising, as I was able to query these elements with Xcode 10.
Ultimately, I would like to find working identifier values so that I can have something that works reliably across products, without the trial and error to find the share sheet's index value.
For iPad
The following will dismiss the popover for an iPad:
app.otherElements["PopoverDismissRegion"].tap()
The first time I run my Sticker Pack extension on a simulator, I get the following crash:
2017-10-25 14:56:10.513268-0700 MobileSMS[94610:5136614] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘attempt to scroll to invalid index path: <NSIndexPath: 0x60c00023b820> {length = 2, path = 0 - 9223372036854775807}’
I didn't see an answer for this on StackOverflow, so I'm posting this question and will answer it below. Let me know if this is incorrect!
The simulator is actually trying to scroll to the sticker pack app icon and press it. For some reason, the simulator doesn't automatically enable your sticker pack, so there isn't an icon to press.
To enable your sticker pack:
On simulator, open message thread.
Tap the ellipsis (three dot) button at bottom.
Tap edit at top-right, then enable your app.
Re-run your app and it will work! I wrote a blog post about this fix. The post is essentially the same content I've posted here.
I am facing a strange problem with UITesting in Swift under iOS 10.3.2 and Xcode 8.3.3 .
I am running a simple test inside my app which should tap and verify every single row inside a TableView (is the Settings view of my application so every single row is loaded from the disk and nothing is downloaded from the web at this step), but for a strange reason when I tap on a row which previously wasn't visible the .tap() method doesn't work.
Example Code:
let app = XCUIApplication()
let myTableView = app.tables.element(matching: .table, identifier: "tableView01")
myTableView.swipeUp(). //I swipe so that the cell becomes visible...
let myCell = myTableView.cells.element(matching: .cell, identifier: "tappableCell")
myCell.tap()
The strange thing is that I have a correct output from the console in Xcode.
t = 328.24s Tap "tappableCell" Cell
t = 328.24s Wait for app to idle
t = 328.80s Find the "tappableCell" Cell
t = 328.80s Snapshot accessibility hierarchy for com.thefloow.enterprise.ownbrand
t = 328.92s Find: Descendants matching type Table
t = 328.92s Find: Element at index 0
t = 328.92s Find: Descendants matching type Cell
t = 328.92s Find: Elements matching predicate '"tappableCell" IN identifiers'
t = 329.04s Wait for app to idle
t = 329.22s Synthesize event
t = 329.37s Wait for app to idle
Another strange thing is that if I put a breakpoint before the tap method and then I run it from the command line it works perfectly giving me the same output from the console.
What could be the reason of this strange behaviour?
Thank you for your help!
Andrea
I found that the problem is in the framework. After scrolling the UI doesn't respond properly so I had to double tap on the cell to resign the UIResponder and then the test works properly. I've also reported the issue to to know if it is a regular behaviour or not.
However thank you to everyone! Happy coding!
I'm working on the automated UI tests for my app and I'm having trouble when trying to set up the environment for running the tests. The plan is roughly this:
build the application
shutdown simulator if running
erase the simulator to make a clean install
install my app on the simulator
run UIAutomation tests
Everything is working except when the application is launched by instruments to execute the tests, the alert appears to ask if the user allows notifications. This is all as expected, but I can't find the way to get rid of the alert.
Things I have already tried:
creating onAlert as a first thing in my test script, in case it appears before the my alert callback is defined
delay the target by 5 seconds in case the tests actually run even before the UI of the app is visible in the simulator
I also went through all the permutations of the above that can be found on SO, I never get my onAlert callback invoked, no matter what I do. So another thing I tried was:
try dismissing the alert with applescript
The script I wrote:
tell application "System Events"
tell process "iOS Simulator"
set allUIElements to entire contents of window 1
repeat with anElement in allUIElements
try
log anElement
end try
end repeat
end tell
end tell
and it displays:
static text “MyApp” Would Like to Send You Notifications of window iOS Simulator - iPhone 6 - iPhone 6 / iOS 8.1 (12B411) of application process iOS Simulator
static text Notifications may include alerts, sounds, and icon badges. These can be configured in Settings. of window iOS Simulator - iPhone 6 - iPhone 6 / iOS 8.1 (12B411) of application process iOS Simulator
UI element 3 of window iOS Simulator - iPhone 6 - iPhone 6 / iOS 8.1 (12B411) of application process iOS Simulator
Looks like the buttons are placed inside the "UI element 3" but I can't retrieve any elements from inside it, let alone clicking on it. So I checked with Accessibility Manager:
It sits there as one of the children, the other ones are notification title and message. But when I go to that element, it is highlighted and I see this:
It is identified as generic element, it doesn't have any children...
The interesting thing is when I choose the OK button in the Accessibility Inspector, I can actually see it's a child of the window, yet it is never listed:
Can someone please shed some light on what is going on here? How can I press that button with Applescript?
If you are doing automation using Instrument, the you will need to register callback (onAlert) for performing any action on alerts.
But the problem in your case is that the alert appears before your script actually start executing and at that time no callback is registered for alert.
So if the alert can come with a delay of around 10 sec when you start application, then only it can be handled. But this can only be controlled through source code and not by your Automation code.
So only option which is left is you need to manual dismiss the alert once fresh application is installed
I am also facing same problem and found it to be a limitation of the tool
There are too many limitaion of this tool and thats why i shifted to UFT
I had a similar problem. I just wanted position of the last control on the alert. So I came up with following piece of code:
on get_simulator_last_object_rect(simulator_index)
tell application "System Events"
set ProcessList to (unix id of processes whose name is "iOS Simulator")
set myProcessId to item simulator_index of ProcessList
tell window 1 of (processes whose unix id is myProcessId)
-- Forcefully print the UI elements so that Accessibility hierarchy is built
UI elements
-- Then wait precisely to let the Accessibility view hierarchy is ready
delay 0.5
set lowest_label_lowest_position to 0
set _x to 0
set _y to 0
set _width to 0
set _height to 0
repeat with element in UI elements
set {_x, _y} to position of element
set {_width, _height} to size of element
set current_control_lowest_position to _y + _height
if current_control_lowest_position > lowest_label_lowest_position then set lowest_label_lowest_position to current_control_lowest_position - _height / 2
end repeat
return {{_x, _y}, {_width, lowest_label_lowest_position}}
end tell
end tell
end get_simulator_alert_ok_button_position
I have a desktop app to control my actions. I use this apple script in my Desktop app to get the frame of the last control. Now that I have the frame, I create a mouse event and perform click on the frame, after activating the simulator.
Although I have not yet tried, but I am pretty sure that you can create mouse events from apple script and perform click on the frame / center of the frame.
Hope this helps.
Thanks,
RKS