Create and run unit tests, performance tests, and UI tests for your Xcode project using XCTest.

XCTest Documentation

Posts under XCTest tag

155 Posts
Sort by:
Post not yet marked as solved
9 Replies
5k Views
We got the newly issue that our Test devices keeps us asking for the pin code to "Enable UI Automation". Then it works for some hours or days, but after some time it starts again. "Enable UI Automation" is already enabled in "Settings" - "Developer" menu. The devices are located remotely and we can't access them directly, so this is a big issue for us right now. Is there any way to avoid this?
Posted Last updated
.
Post not yet marked as solved
0 Replies
406 Views
In my iOS project, there is an infrequent crash related to virtual memory problem. Therefore, I plan to use UITest in combination with Product/Perform Action/Profile "TestCaseName" to conduct Game Performance-type testing. This allows the automatic testing to continuously operate until the profile stops recording upon a crash. This enables me to observe the various states of the program at the time of the crash. However, I have found that the UITest using Profile is highly unstable. The UITestCase often terminates unexpectedly during execution, leading to failed tests (Instruments is still working). Sometimes, the app is terminated immediately after startup. It seems that the use of sleep() in the code can easily cause interruption issues, which do not occur during normal UI testing. I am wondering if anyone has experience using Profile for UITest and whether they have encountered the issues I described." Working Environment: XCode14.3.1, iPhone Device iOS17.2
Posted Last updated
.
Post not yet marked as solved
1 Replies
503 Views
I am directed from https://discuss.appium.io/t/create-multiple-instances-of-the-same-app/41266/14?u=lxnm, the context is that Appium max2 driver is implementing the activating of MacOS app using XCTest API methods. There are 2 ways to implement the activating of the app, using app path (calling initWithURL) and bundle id (calling initWithBundleIdentifier). This pull request shows how the XCTest methods are called when using the Mac2 driver, specifically in the file WebDriverAgentMac/WebDriverAgentLib/Routing/FBSession.m. The problem is that I am able to launch my MacOS app(it is a company app) using bundle id, but when I launch the app with app path, I receive XcodeBuild errors: [WebDriverAgentMac] [xcodebuild] XCTExpectFailure: matcher accepted Assertion Failure: Failed to launch com.company.companyApp: You do not have permission to run the application “companyApp”. You don’t have permission. To view or change permissions, select the item in the Finder and choose File > Get Info. (Underlying Error: The operation couldn’t be completed. Operation not permitted) I followed this to enable R+W permissions to all users, but the same error is displayed.
Posted
by johnnylim.
Last updated
.
Post not yet marked as solved
1 Replies
452 Views
I am currently working on a SwiftUI project and I am trying to write a UI test for a DatePicker. However, I am having trouble interacting with the DatePicker in the test. Here is the code for the DatePicker in my SwiftUI view: DatePicker("Date", selection: $date, displayedComponents: [.date]) .datePickerStyle(.graphical) .labelsHidden() .frame(width: 150) And here is the code for my UI test: func testSelectingDateChangesMainView() throws { let app = XCUIApplication() app.launch() let dateDatePicker: XCUIElement = app.windows["mainUI-AppWindow-1"].datePickers["Date"] dateDatePicker.click() let col = dateDatePicker.descendants(matching: .any) print("\(dateDatePicker.debugDescription), \(col.debugDescription)") } When I run the test, it seems like the DatePicker does not have any descendants, so I am unable to select a date. Does anyone have any suggestions on how I can interact with a .graphical style DatePicker in a UI test? Any help would be greatly appreciated. Thank you, OnlyForF1
Posted
by OnlyForF1.
Last updated
.
Post not yet marked as solved
2 Replies
394 Views
Hi! I'm experimenting with Xcode performance testing. I'm specifically focusing on XCTMemoryMetric. I have a demo project with two performance tests that do some work wrapped with XCTestCase.measure. I can navigate to my Report navigator in Xcode and see the memory footprints of these two tests… but I only see how to view them individually: From this screen it looks like I have the ability to Export this benchmark to CSV. My question is what my options are for viewing all my XCTestCase.measure tests together. I see the Duration for both tests… but I don't see any way to view the memory benchmarks for all my tests in just one place: Ideally… I would also like to run these tests and produce one CSV file (or XML or JSON) report. I'm not opposed to using command line for this (if the option exists there) but Xcode also works for me. I'm also flexible whether or not these tests live in a Swift Package or directly in an Xcode project if that makes any difference. Any more advice about how to set up these performance tests? Thanks!
Posted Last updated
.
Post not yet marked as solved
2 Replies
1.1k Views
Hi everybody, given the following case using SwiftUI: Button("testButton", action: noop) .accessibilityRepresentation{representation: { Slider(value: $sliderData.sliderValue) }) .accessibilityIdentifier("testSlider") I'm trying to control the slider using XCUITest via slider.adjust(toNormalizedSliderPosition: 0.2) and receive the following error message: Failed: Unable to get expected attributes for slider, found { "XC_kAXXCAttributeMaxScrubberPosition" = { X = 0; Y = 0; }; "XC_kAXXCAttributeMinScrubberPosition" = { X = 0; Y = 0; }; Similarly, print (slider.normalizedSliderPosition) leads to the error message "Failed to determine current position of slider "0 %". Is there a way to set and read the value of accessibilityRepresentation-Sliders with XCUITest? Thanks!
Posted
by sasro.
Last updated
.
Post not yet marked as solved
1 Replies
1.9k Views
I've created a test plan that includes the below configurations. {"configurations": [{ ... "options": { "defaultTestExecutionTimeAllowance" : 60, "maximumTestExecutionTimeAllowance" : 60, "testTimeoutsEnabled" : true }], "defaultOptions": { "defaultTestExecutionTimeAllowance" : 60, "maximumTestExecutionTimeAllowance" : 60, "testTimeoutsEnabled" : true, .... } ... } If I write a test that intentionally will take longer than 60 seconds, executing the test locally fails as expected with the error message Test exceeded execution time allowance of 1 minute let app = XCUIApplication() app.launch() let missingButton = app.buttons.firstMatch XCTAssertTrue(missingButton.waitForExistence(timeout: 120), "When a timeout is > 60 seconds, the default max setting of 60 seconds is still enforced") However, when this test is run using this test plan in XCode Cloud, it reports that it took 124 seconds to run and there is no message about exceeding execution time allowance. How can the test step be configured in XCode Cloud to ensure that the execution time allowances are respected?
Posted
by kb_123.
Last updated
.
Post not yet marked as solved
0 Replies
473 Views
We recently updated to Xcode 15.1 and start using iOS 17.2 simulator and ran into a blocker issue with out UITests. Setting accessibility identifier on a UIButton with image no longer works. It seems iOS automatically set the label to the file name used for the button and ignore (overwrite) the id and value we set in code. iOS 17.0 with Xcode 15.1 still works. I spent 2 days on this and still cannot find a solution. Anyone had similar issue? I did file a feedback https://feedbackassistant.apple.com/feedback/13515676 Thanks!
Posted Last updated
.
Post not yet marked as solved
1 Replies
492 Views
Hi, I have created the applications (debug and runner) using xcodebuild. I have tried it both using Xcode 14.3.1 and 15.1. I used the xcodebuild build-for-testing... with -configuration set to Debug (I've also built the apps by omitting the -configuration altogether). The configurations are set correctly in Xcode, and I can run the automation from Xcode and running xcodebuild. I am using a different tool other than xcodebuild to run the tests (I'm using go-ios https://github.com/danielpaulus/go-ios). The issue I'm having is that right at the beginning of the test, I'm getting this error "Failed to retrieve test configuration from IDE". I know it's something to do with the two apps (debug and runner appp), because I've made comparison to a brand new application I had created using Xcode. I assume this is something to do with the build configurations we have in the app (Debug or Release), but they're all correctly set in Xcode, and I can also run the tests (albeit using the xctestrun file) without any problems. Do you know what could be causing this? In particular, what could cause the above error to be generated? Any help (however related or unrelated you think it could be) is greatly appreciated. Thanks in advance. Sep
Posted
by Sepsky.
Last updated
.
Post not yet marked as solved
0 Replies
386 Views
I'm working on this project for the first time in a while, so I'm not sure if this issue started with Xcode 15 or what, but now when I run my UI tests I get the warning "“MyAppUITests-Runner” is from an unidentified developer and differs from previously opened versions. Are you sure you want to open it?" Code signing identity for the UITest target is set to "sign to run locally". Changing it to "Apple Development" doesn't help, and neither did a clean build. How do I need to configure it to eliminate the warning?
Posted
by Uncommon.
Last updated
.
Post not yet marked as solved
1 Replies
336 Views
when I download the sample backyard app from wwdc 23. The files for the Unit and Ui test are missing. Where do I find the? since I would like to see how they Apple implemented unit tests with SwiftData
Posted Last updated
.
Post not yet marked as solved
1 Replies
314 Views
Not able to capture the individual elements on the iOS 17 device (using iPhone 14) using Appium inspector. It always capture/ highlight the entire home screen as one element. As per the Appium support team, this is an issue with XCTest framework. The getPageSource() method is loading indefinitely. Please refer below links- https://github.com/appium/appium-inspector/issues/1225 https://github.com/appium/appium/issues/19429 I am using below configurations- MacBook AIR (Apple M2 2022) - Sonoma 14.1.2 Appium Version - 2.0.1 Appium Inspector - 2023.11.1 Available drivers: xcuitest@5.11.8 (automationName 'XCUITest') uiautomator2@2.34.2 (automationName 'UiAutomator2') Node - v21.3.0 npm - 10.2.4 Xcode - Version 15.0.1 (15A507) Could you please clarify if this is an existing/known issue or am I missing something? Note - Let me know if any other information needed from my end for better clarity. I will appreciate your inputs on this. Thanks in advance!
Posted
by Leap-User.
Last updated
.
Post not yet marked as solved
1 Replies
278 Views
Hi, I'm new here, and I'm need to Developer Disk Image to Test my app, how can I get it?
Posted
by Iepick.
Last updated
.
Post not yet marked as solved
3 Replies
1.5k Views
When using Xcode 15 beta 8 / iOS 17 beta 8 simulator runtime, we can see in Activity Monitor that memory used by "SimRenderServer" proccess grows significantly with each UI test run. It reproduces even on an empty test, that just wait for a second without launching the application. Memory usage doesn't go down when test run finishes, so each consecutive run adds more to it. For example, create an new project with a UI test // The contents of the test don't actually matter func testExample() async throws { try await Task.sleep(for: .seconds(1)) } Run this test repeatedly 100+ times and observe the "SimRenderServer" process in the Activity Monitor. From what we observed it only reproduces when "Preferred Capture Format" in the test plan configuration is set to "Video". Setting it back to "Screenshot" does no result in growing memory usage. This was reproducible on macOS Sonoma beta / macOS Ventura 13.5.1. Feedback was submitted FB13098749.
Posted
by tgrigory.
Last updated
.
Post not yet marked as solved
5 Replies
3.8k Views
Issue: When I click run unit tests the tests get 'stuck' and in the top bar is says "Testing..." and never completes - I even left it for an hour. I have created new projects with no code written and the same thing happens. I have deleted and re-downloaded code as well. Current Xcode: 14.3 I don't believe it's a project issue since I have tried multiple but rather something with Xcode. and my CPU % for Xcode shoots to 365+ when this is happening. I have a M1 Max with 64GB. Any help would be appreciated.
Posted Last updated
.
Post not yet marked as solved
2 Replies
1.4k Views
The new test report, with the automatic video recording and scrubber, is great. I'm setting up different configurations for different languages to improve localization testing, but I was wondering if it was possible to make the simulator device type part of the configuration. For example, I'd like to have a single test plan with an "iPhone 14" test plan, an "iPad Air" test plan, etc. Then I would just press Cmd-U, and Xcode would run through each device in sequence, leaving me with videos of each test run that I could review in the test report. Is that possible?
Posted Last updated
.
Post not yet marked as solved
1 Replies
327 Views
I have a swift package with a function that formats a HKQuantity using the current locale. I want to write a unit test with all locales the package is localized for. I do not want to insert a separate locale parameter, I want to test the function with the current locale as I use the function only with the current locale. Can I set the current locale for this use case in the code somehow? Example: do { let quantity = HKQuantity(unit: unit, doubleValue: 0.955) let result = quantity.formattedAsOxygenSaturation(precision: .better) let expectedResult = "95.5 %" XCTAssertEqual(result, expectedResult) } Thanks!
Posted
by Nankea.
Last updated
.
Post not yet marked as solved
0 Replies
394 Views
I facing the similar issue where Appium inspector is very slow to load my device, which makes me unable to locate the element. MacBook Pro (Apple M1 Prod) - Ventura 13.6 Appium Version - 2.2.1 Appium Inspector - 2023.11.1 appium driver list ✔ Listing available drivers uiautomator2@2.34.0 [installed (npm)] Node - v21.1.0 npm - 10.2.0 Xcode - Version 15.0.1 (15A507) Simulator - iPhone 15 (17.0) { "appium:deviceName": "iPhone 15", "appium:app": "sim.app PATH", "appium:automationName": "XCUITest", "appium:platformName": "iOS", "appium:platformVersion": "17.0", "appium:bundleId": "com.xxxxxxx", "appium:usePrebuiltWDA": false } https://github.com/appium/appium/issues/19382
Posted Last updated
.
Post not yet marked as solved
0 Replies
765 Views
webdriver: Request failed with status 500 due to An unknown server-side error occurred while processing the command. Original error: Unable to launch WebDriverAgent because of xcodebuild failure: xcodebuild failed with code 70 [0-0] xcodebuild error message: [0-0] . Make sure you follow the tutorial at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md. Try to remove the WebDriverAgentRunner application from the device if it is installed and reboot the device. I'm using macOs 13.6 xcode 14.3 Iphone Os 16.7.2 running with webdriverIO still getting this error can anyone help me in this please.
Posted
by Gajanan.
Last updated
.