I'm trying to close the UIFontPickerViewController in a UI test by tapping the close button in the navigation bar. In a default iOS app, I embed the default storyboard view controller in a navigation view controller, then in code I open the font picker like this:
class ViewController: UIViewController, UIFontPickerViewControllerDelegate {
override func viewDidAppear(_ animated: Bool) {
let picker = UIFontPickerViewController(configuration: .init())
picker.delegate = self
self.present(picker, animated: true)
}
func fontPickerViewControllerDidPickFont(_ viewController: UIFontPickerViewController) {
}
}
And the UI test looks like this:
final class problemUITests: XCTestCase {
@MainActor
func testExample() throws {
let app = XCUIApplication()
app.launch()
sleep(2)
let button = app.navigationBars.element(boundBy: 1).buttons.element(boundBy: 0)
print(button.debugDescription)
XCTAssert(button.waitForExistence(timeout: 2))
button.tap()
}
}
When running the UI test, the XCTAssert always fails and the button.tap() also fails with an error message
Failed to tap "chiudi" Button: No matches found for Element at index 1 from input {(
NavigationBar
)}
"chiudi" means "close" in Italian, my macOS system language. It sounds to me like I correctly get the close button, but the messages Xcode prints make no sense to me.
It's particularly confusing given that the output of the print statement shows that the button is there, but somehow fails to be tapped:
Attributes: Button, 0x104f44660, {{701.0, 320.0}, {43.0, 44.0}}, label: 'chiudi'
Element subtree:
→Button, 0x104f44660, {{701.0, 320.0}, {43.0, 44.0}}, label: 'chiudi'
Image, 0x104f44780, {{709.0, 327.5}, {30.0, 30.0}}, identifier: 'UICloseButtonBackground'
Path to element:
→Application, 0x104f35940, pid: 29803, label: 'problem'
↳Window (Main), 0x104f376a0, {{0.0, 0.0}, {1032.0, 1376.0}}
↳Other, 0x104f42e10, {{0.0, 0.0}, {1032.0, 1376.0}}
↳Other, 0x104f43100, {{0.0, 0.0}, {1032.0, 1376.0}}
↳Other, 0x104f43220, {{0.0, 0.0}, {1032.0, 1376.0}}
↳Other, 0x104f43340, {{0.0, 0.0}, {1032.0, 1376.0}}
↳Other, 0x104f43460, {{0.0, 0.0}, {1032.0, 1376.0}}
↳Other, 0x104f43580, {{0.0, 0.0}, {1032.0, 1376.0}}
↳Other, 0x104f436a0, {{0.0, 0.0}, {1032.0, 1376.0}}
↳Other, 0x104f437c0, {{0.0, 0.0}, {1032.0, 1376.0}}
↳Other, 0x104f438e0, {{0.0, 0.0}, {1032.0, 1376.0}}
↳Other, 0x104f43a00, {{0.0, 0.0}, {1032.0, 1376.0}}
↳Other, 0x104f43b20, {{0.0, 0.0}, {1032.0, 1376.0}}
↳Other, 0x104f43c40, {{276.0, 314.0}, {480.0, 748.0}}
↳Other, 0x104f43e80, {{276.0, 314.0}, {480.0, 748.0}}
↳Other, 0x104f43fa0, {{276.0, 314.0}, {480.0, 748.0}}
↳Other, 0x104f440c0, {{276.0, 314.0}, {480.0, 748.0}}
↳Other, 0x104f441e0, {{276.0, 314.0}, {480.0, 748.0}}
↳Other, 0x104f44300, {{276.0, 314.0}, {480.0, 748.0}}
↳NavigationBar, 0x104f44420, {{276.0, 314.0}, {480.0, 108.0}}, identifier: 'Scegli font'
↳Button, 0x104f44660, {{701.0, 320.0}, {43.0, 44.0}}, label: 'chiudi'
Query chain:
→Find: Target Application 'org.desairem.problem'
Output: {
Application, 0x104f781b0, pid: 29803, label: 'problem'
}
↪︎Find: Descendants matching type NavigationBar
Output: {
NavigationBar, 0x10607c0d0, {{0.0, 24.0}, {1032.0, 50.0}}, identifier: 'UIFontPickerView'
NavigationBar, 0x10607dab0, {{276.0, 314.0}, {480.0, 108.0}}, identifier: 'Scegli font'
}
↪︎Find: Element at index 1
Output: {
NavigationBar, 0x1064693a0, {{276.0, 314.0}, {480.0, 108.0}}, identifier: 'Scegli font'
}
↪︎Find: Descendants matching type Button
Output: {
Button, 0x104f714a0, {{701.0, 320.0}, {43.0, 44.0}}, label: 'chiudi'
Button, 0x104f71800, {{711.0, 378.0}, {17.0, 22.0}}, identifier: 'Dictate', label: 'Avvia dettatura'
}
↪︎Find: Element at index 0
Output: {
Button, 0x104f5d5e0, {{701.0, 320.0}, {43.0, 44.0}}, label: 'chiudi'
}
XCTest
RSS for tagCreate and run unit tests, performance tests, and UI tests for your Xcode project using XCTest.
Posts under XCTest tag
111 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
How can I test biometric on UI Tests in Swift / iOS 18? This code not working.
+ (void)successfulAuthentication {
notify_post("com.apple.BiometricKit_Sim.fingerTouch.match");
notify_post("com.apple.BiometricKit_Sim.pearl.match");
}
+ (void)unsuccessfulAuthentication {
notify_post("com.apple.BiometricKit_Sim.fingerTouch.nomatch");
notify_post("com.apple.BiometricKit_Sim.pearl.nomatch");
}
Requirement :
We wanted to run UI Automation using xcuitest in devices with MDM profiles.
Steps :
We have created a test target for our app and signed with MDM profile (in-house)
Generated app and testbundle-Runner along with xctestrun files using “xcodebuild build-for-testing -scheme “App-TestRelease" -configuration “Release” -derivedDataPath "${CURDIR}/derivedData" -workspace "${PROJECT_NAME}.xcworkspace" -sdk iphoneos”
Tried running “xcodebuild test-without-building -destination platform=iOS,id=000842883-**** -xctestrun App-TestRelease_iphoneos17.5-arm64.xctestrun -derivedDataPath /derived/“
Facing below issues
xcodebuild[35481:3588352] IDELaunchReport: e2934a094f300d40:e2934a094f300d40: Finished with error: Unable to launch com.org.mdm.XCTest.xctrunner
Domain: com.apple.platform.iphoneos
Code: -12
User Info: {
IDERunOperationFailingWorker = IDELaunchiPhoneLauncher;
}
--
Request to launch com.org.mdm.XCTest.xctrunner failed.
Domain: com.apple.dt.deviceprocesscontrolservice
Code: 2
Failure Reason: The request to open "com.org.mdm.XCTest.xctrunner" failed. : Failed to launch process with bundle identifier 'com.org.mdm.XCTest.xctrunner'.
--
The request to open "com.org.mdm.XCTest.xctrunner" failed.
Domain: FBSOpenApplicationServiceErrorDomain
Code: 1
Failure Reason: The request was denied by service delegate (SBMainWorkspace) for reason: Security ("Unable to launch com.org.mdm.XCTest.xctrunner because it has an invalid code signature, inadequate entitlements or its profile has not been explicitly trusted by the user").
User Info: {
BSErrorCodeDescription = RequestDenied;
FBSOpenApplicationRequestID = 0x9f9;
}
--
The operation couldn’t be completed. Unable to launch com.org.mdm.XCTest.xctrunner because it has an invalid code signature, inadequate entitlements or its profile has not been explicitly trusted by the user.
Domain: FBSOpenApplicationErrorDomain
Code: 3
Failure Reason: Unable to launch com.org.mdm.XCTest.xctrunner because it has an invalid code signature, inadequate entitlements or its profile has not been explicitly trusted by the user.
User Info: {
BSErrorCodeDescription = Security;
}
A UI test case that checks for the existence of a SwiftUI Text element initialized with an empty string previously reliably passed in iOS 17.
In iOS 18 the assertion reliably fails.
I searched the iOS 18 developer release notes for anything possibly related to this but didn't find much. I'd like to point to a conclusive change in iOS handling before changing the test permantently. Can anyone confirm that this is indeed a change in iOS 18?
Hello Developers,
I regularly use Xcode Cloud to run unit tests, but since the release of Xcode 16, the testing process has become significantly slower.
I am seeking advice on how to improve the situation.
[ Details ]
With Xcode 15.4, unit tests took about 1 hour to complete.
However, since upgrading to Xcode 16, the tests have not finished even after 2 hours.
The blog post linked below also mentions significant overhead in running unit tests on Xcode Cloud, even with Xcode 15.4:
https://dwango.github.io/articles/2024-07_nicoiphone_xcode_cloud/#%E3%83%86%E3%82%B9%E3%83%88%E5%AE%9F%E8%A1%8C%E6%99%82%E9%96%93%E3%81%8C%E5%A2%97%E5%8A%A0%E3%81%97%E3%81%A6%E3%81%97%E3%81%BE%E3%81%86%E5%95%8F%E9%A1%8C
According to the blog, while reviewing the xcodebuild-test-without-building.log, it was observed that the time from start to finish was about 4 minutes.
However, the overall “Run xcodebuild test-without-building” process took 23 minutes, with around 20 minutes of apparent idle time.
It seems that the idle time has increased even further with Xcode 16, resulting in more than twice the testing time.
[ Question/Request ]
Is there any way to reduce the overhead when running unit tests on Xcode Cloud, especially with the increased overhead in Xcode 16?
Any advice or solutions for improving the performance would be greatly appreciated.
Best regards,
Topic:
Developer Tools & Services
SubTopic:
Xcode Cloud
Tags:
Xcode
XCTest
Xcode Cloud
Swift Testing
We have widget snapshot tests using XCTest as shown below:
func testHomeWidgetView() {
let widgetView = HomeWidgetView(
state: .done,
text: "All done!"
).frame(width: 170, height: 170)
assertSnapshot(matching: widgetView, as: .image)
}
}
Is it possible to apply a tint to the widgets in snapshot tests like a user can from their home screen in iOS 18? We'd like to capture snapshots of our widget while tinted via the home screen.
I'm wondering if the tagging functionality which was added for Swift testing will be added to XCTest for UITests anytime soon.
When using Xcode's "Build for Testing", I have noticed the resulting MyApp.xctestrun file has an array of CodeCoverageBuildableInfos. This array has all of our built targets. They all have an Architectures array property. For all of our targets this is set to x86_64 when we build for Any iOS Simulator. This is irrespective of what we have "ARCHS" and "ONLY_ACTIVE_ARCH" set to (in our case we only want arm64).
We do have a number of local swift packages defined, each with their own test targets. We are using a test plan for these tests.
This is causing issues when processing the resulting xcresult file since it is complaining that it can't find objects for the correct architecture when calculating code coverage.
No object file for requested architecture
No coverage data found. (Underlying Error: No object file for requested architecture)
Hello everyone,
I’m having trouble configuring SKTestSession for StoreKit testing in my UI tests. Specifically, I’m encountering the ASDErrorDomain Code 505 error when trying to set the storefront and locale in my test configuration. Despite following the setup steps, I keep getting errors indicating that the storefront and locale cannot be set, and the transactions are not being processed correctly.
Here are the error messages I’m seeing:
[SKTestSession] Error saving configuration file: Error Domain=ASDErrorDomain Code=505 "(null)"
[SKTestSession] Error setting storefront to JPN for com.company.product: Error Domain=ASDErrorDomain Code=505 "(null)"
[SKTestSession] Error fetching the current storefront: Error Domain=ASDErrorDomain Code=505 "(null)"
[SKTestSession] Error setting value to ja for identifier 4 for com.company.product: Error Domain=ASDErrorDomain Code=505 "(null)"
[SKTestSession] Error fetching value for identifier 4 for com.company.product: Error Domain=ASDErrorDomain Code=505 "(null)"
These errors suggest that SKTestSession is unable to save or apply the configuration properly, but I’m not sure why. I’ve tried various storefronts and locales, but the issue persists. I’m running this on Xcode 16.0 (16A242d) on macOS 14.7 and 15.
Below is the code for the setUpSession function I’m using to configure the session:
func setUpSession(configuration: String = "Configuration", storefront: String? = nil, localeIdentifier: String? = nil) throws -> SKTestSession
{
var session: SKTestSession!
try XCTContext.runActivity(named: "Set up subscriptions for \"\(configuration)\" storefront: \"\(storefront ?? "")\" and locale: \"\(localeIdentifier ?? "")\"")
{
activity in
session = try SKTestSession(configurationFileNamed: configuration)
if let storefront
{
session.storefront = storefront
}
if let localeIdentifier
{
session.locale = Locale(identifier: localeIdentifier)
}
session.disableDialogs = true
let info = XCTAttachment(string: "storefront: \(session.storefront)\nlocale: \(session.locale.identifier)\ntransactions: \(session.allTransactions().count)")
info.name = "Session configuration"
activity.add(info)
XCTAssertEqual(session.storefront, storefront, "Failed to set storefront")
XCTAssertEqual(session.locale.identifier, localeIdentifier, "Failed to set locale")
}
return session
}
What I’ve Tried:
Ensuring that storefront and locale values are valid.
Resetting StoreKit configuration in Xcode’s scheme settings.
Deleting derived data and restarting Xcode.
Testing with different values for storefront and locale.
Has anyone encountered similar issues with ASDErrorDomain Code 505, or can anyone point out what might be causing this? Any help would be greatly appreciated!
Thank you!
No coverage is generated for private xxxx.framework, but tests are running under this framework.
This was perfectly working before and started giving this error after updating to Xcode 16.
Failed to generate coverage for target xxxx.framework at paths (
"/Users/xxxxxx/Desktop/xcode/Debug-iphonesimulator/Common/xxxxxx.framework/xxxx"
):
No object file for requested architecture
The operation couldn’t be completed. (XCTHCoverageReportGenerationErrorDomain error 2.).
(Underlying Error: No object file for requested architecture)
I am trying to add an XCUITest target to an existing application. When I try to run the tests, I get the error "Invalid configuration: MyProjectUITests sets both USES_XCTRUNNER and either TEST_HOST or RUNTIME_TEST_HOST".
I have seen information stating that it might be because I have multiple apps built from different build configurations in the same scheme, but I could not resolve the issue with any of the suggestions I saw.
I've attached a screenshot of the error message and a link to a project stripped down to just the existing configuration to help with diagnosing this issue. I would really love to be able to get some UI tests running.
My Project
I am trying to browse an SSH Service from UI Test Target using NWBrowser
let descriptor = NWBrowser.Descriptor.bonjour(type: "_superapp._tcp", domain: "local.")
let browser = NWBrowser(for: descriptor, using: .tcp)
browser.stateUpdateHandler = { newState in
print("browser.stateUpdateHandler \(newState)")
}
I get failed(-65555: NoAuth) error
nw_browser_fail_on_dns_error_locked [B1] DNSServiceBrowse failed: NoAuth(-65555)
I have added _superapp._tcp in Bonjour Services for UI Test Target Info.plist.
I have also added Local Network Permission in UI Test Target Info.plist.
Everything works fine, when I call this Bonjour service from App Target.
Doesn't work when I call this from UI Test Target.
Am trying to automate below drop down but iOS Accessibility inspector is unable to detect the element. Even we tried with Appium Inspector issue is same.
Drop down: https://www.npmjs.com/package/react-native-element-dropdown
We tried to debug the dropdown component. In that we can see the value is rendered properly from react.
We have raised the issue with Appium, but they have given few suggestions in the Appium setting but it didn't solve. Now it's something that has to be done from XCTest Framework end.
Appium issue git link: https://github.com/appium/appium/issues/14825
Hi,
I work on a iOS application which includes several local swift packages containing modularised code. Each of those local swift packages has a test target defined in their respective Package.swift, and when opening a local package folder standalone in Xcode, then the tests run without issues.
However I would like in the main app's test plan to add the local package test targets and have them all run together when the main app's default test plan is run. Xcode allows me to select local package test targets within the main app's test plan (also within Test portion of the main app's scheme), however attempting to build for testing throws a "Module '…' was not compiled for testing".
Any ideas on how to achieve this goal (run local package tests in conjunction with main app's tests) and avoid that error?
Thanks
Peter
Hello. In the Xcode 15 we were using this command in the terminal to run our tests on the Rosetta Simulator:
xcodebuild -workspace CoreLibraries.xcworkspace -scheme CoreLibraries -destination 'platform=iOS Simulator,name=iPhone 15,arch=x86_64' test`
In the Xcode 16 the same command doesn't work anymore. It produces the error:
xcodebuild: error: Unable to find a device matching the provided destination specifier:
{ platform:iOS Simulator, arch:x86_64, OS:latest, name:iPhone 16 }
Unsupported device specifier option.
The device “iPhone 16” does not support the following options: arch
Please supply only supported device specifier options.
Running test directly from the Xcode UI using iPhone 16 (Rosetta) still works fine.
Does anyone know how to modify the xcodebuild command to make it work again?
I have a + image in the UI from the following code
struct QueryPlusButton: View {
var body: some View {
Button {
}
label: {
Image(systemName: "plus")
}
}
}
However, I'm not able to query the + image in XCTest using any of the following queries
let view = app.images["plus"]
//let view = app.staticTexts["plus"]
//let view = app.buttons["plus"]
XCTAssertTrue(view.exists, "Plus button does not exist")
The test fails. Is there a methodical way to determine what a query is for any UI element? Thank you.
I am developing an app that uses CoreBluetooth to communicate with a proprietary piece of hardware. I would like to be able to write tests for it, but there does not seem to be any way to mock or simulate the presence of, for example a CBPeripheral object.
This library (https://github.com/NordicSemiconductor/IOS-CoreBluetooth-Mock) almost does what I need, but it's not quite flexible enough. I think they have the right idea, but it doesn't seem to be actively maintained anymore.
This seems like a pretty big hole in the iOS SDK. Is there really not an officially supported way of testing BLE functionality?
I am using two iPhone11 devices, having iOS v17.6.1 for automation testing using Seleniumv4.X-Appium v2.x.
Today I updated the mac to Sequoia15 version which updated the XCode to v16.
Just after this update, I could not able to run the previously running automation script. The console message is "org.openqa.selenium.SessionNotCreatedException:
Could not start a new session. Response code 500. Message: Unable to launch WebDriverAgent. Original error: xcodebuild failed with code 70. This usually indicates an issue with the local Xcode setup or WebDriverAgent project configuration or the driver-to-platform version mismatch."
I tried to use XCTest to test my own project that uses EndpointSecurity, but when I created the esClient I got an error:ES_NEW_CLIENT_RESULT_ERR_NOT_PRIVILEGED, indicating that it was not root.
This makes it impossible for me to do coverage tests for the ESClient application. Is there any way I can implement this ESClient test? If so, how should I use it? The project is a macOS program, if I use gcov, but I find I can't get coverage. Using __gcov_flush will indicate that there is no symbol
#if !TARGET_IPHONE_SIMULATOR
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
setenv("GCOV_PREFIX", [documentsDirectory cStringUsingEncoding:NSUTF8StringEncoding], 1);
setenv("GCOV_PREFIX_STRIP", "13", 1);
#endif
extern void __gcov_flush(void);
__gcov_flush();
#endif
Topic:
App & System Services
SubTopic:
Processes & Concurrency
Tags:
Xcode
XCTest
Testing
Endpoint Security
I am creating a iOS library project using Xcode 15 in objective C lang which has dependency XCTest framework and Objective C run time and having UI test cases which can be use used in various projects.
I am able to build and run unit test cases using Xcode fine but when try to run test using command line getting below issue
Command
env NSUnbufferedIO=YES xcodebuild clean test -workspace EnptyLibrary.xcworkspace -scheme EnptyLibrary -configuration Debug -destination 'platform=iOS Simulator,OS=latest,name=iPhone 15 Pro' -destination 'platform=iOS Simulator,OS=latest,name=iPad Pro (12.9-inch) (6th generation)' -testPlan EnptyLibrary -derivedDataPath build -disable-concurrent-destination-testing -retry-tests-on-failure=NO
Error log
** TEST SUCCEEDED **
2024-09-12 16:36:34.822 xcodebuild[8345:45388802] Writing error result bundle to /var/folders/12/rcxtcvjs08169cc_fzhyc8x40000gq/T/ResultBundle_2024-12-09_16-36-0034.xcresult
2024-09-12 16:36:34.832 xcodebuild[8345:45388802] [MT] DVTAssertions: ASSERTION FAILURE in IDEFrameworks/IDEFoundation/ProjectModel/ActionRecords/IDESchemeActionsInvocationRecord.m:458
Details: Assertion failed: !self.hasSaved
Object: <IDESchemeActionsInvocationRecord: 0x112c21ce0>
Method: -saveWithCompletionBlock:
Thread: <_NSMainThread: 0x600000e441c0>{number = 1, name = main}
Hints:
Backtrace:
0 -[DVTAssertionHandler handleFailureInMethod:object:fileName:lineNumber:assertionSignature:messageFormat:arguments:] (in DVTFoundation)
1 _DVTAssertionHandler (in DVTFoundation)
2 _DVTAssertionFailureHandler (in DVTFoundation)
3 _DVTAssertionWarningHandler (in DVTFoundation)
4 -[IDESchemeActionsInvocationRecord saveWithCompletionBlock:] (in IDEFoundation)
5 -[IDESchemeActionsInvocationRecord saveSynchronouslyWithError:] (in IDEFoundation)
6 -[Xcode3CommandLineBuildTool saveResultBundleForError:triageWithSchemeTask:error:] (in Xcode3Core)
7 -[Xcode3CommandLineBuildTool _printError:schemeTask:andFailWithCode:] (in Xcode3Core)
8 -[Xcode3CommandLineBuildTool _printErrorWithSchemeTaskUserInfo:] (in Xcode3Core)
9 -[Xcode3CommandLineBuildTool _buildWithTimingSection:] (in Xcode3Core)
10 -[Xcode3CommandLineBuildTool run] (in Xcode3Core)
11 XcodeBuildMain (in libxcodebuildLoader.dylib)
12 -[XcodebuildPreIDEHandler loadXcode3ProjectSupportAndRunXcode3CommandLineBuildToolWithArguments:] (in xcodebuild)
13 -[XcodebuildPreIDEHandler runWithArguments:] (in xcodebuild)
14 main (in xcodebuild)
15 start (in dyld)
zsh: abort env NSUnbufferedIO=YES xcodebuild clean test -workspace -scheme EnptyLibrary