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

Posts under XCTest tag

161 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

[xcode 15, ios 17]UseDestinationArtifacts key does not work when used in xctestrun file to execute the test with test-without-building
I am using xcode 15 beta and ios 17 beta 6 and experiencing a bug where the key UseDestinationArtifacts does not work when used in an xctestrun file to execute the test with the test-without-building flag. When I set the UseDestinationArtifacts key to true in my xctestrun file and run the tests with the test-without-building flag, Xcode throws the below error Testing failed: Application Bundle Not Found Runner encountered an error (Failed to install or launch the test runner. (Underlying Error: Application Bundle Not Found. Configure the path to a bundle to be installed on the device.)) **UseDestinationArtifacts works smoothly on ** xcode version<15 xcode 15 + ios 16 I have attached a reproduction of the bug. Steps to reproduce: Update below keys in xctestrun file remove DependentProductPaths, TestHostPath, UITargetAppPath Add UseDestinationArtifacts, TestBundleDestinationRelativePath, UITargetAppBundleIdentifier
4
4
1.1k
Aug ’23
Force app interface style in Xcode UI tests with iOS target to be light or dark
In my UI test I'm trying to force the app's user interface style to be light or dark. On macOS, when the system appearance is light, I can force the app to be dark with this code: var app = XCUIApplication() app.launchArguments += ["-AppleInterfaceStyle", "Dark"] app.launch() Sadly, this doesn't work with a iOS target, and UIScreen.main.traitCollection.userInterfaceStyle is read-only. Is this not possible?
0
0
392
Aug ’23
Simulate arrow key press in UITextView during UI test
I would like to simulate pressing an arrow key on the hardware keyboard attached to an iPad. In a UI test for a macOS target I can do this: XCUIElement.typeKey(.rightArrow, modifierFlags: [.option, .command]) but this won't compile for a iOS target supporting iPhone and iPad. Is there an alternative? What I would like to achieve in the end is moving the text cursor at the beginning of a particular sentence by pressing Option-Command-Arrow left a certain number of times, but if someone knows a better way, I'd be happy to hear it.
0
0
411
Aug ’23
XCUITest Sign in with apple
I'm trying to automate a testing flow in my app, that requires signing in with apple first. I've figure out how open settings and login with a test apple ID. I've wrapped that up in a function and call that first (with a check to see if its already logged in). When I return to my app, and tapping the sign in with apple button, I can't find anyway to interact with the sign in with apple modal, e.g. asking me if I want to share my email address or not, tapping "continue with password" and so on I've tried setting up an interruption handler, but it doesn't get triggered let test = addUIInterruptionMonitor(withDescription: "") { alert in print("inside alert:\( alert )") return true } I've tried checking for springboard alerts, but its not an alert let springboardApp = XCUIApplication(bundleIdentifier: "com.apple.springboard") springboardApp.alerts.exists I don't know any other tricks, or how to find the bundle ID of this popup. Any advice?
1
0
1.1k
Aug ’23
UI Testing Authorization Plugins
Has anyone managed to ui test an authorization plugin that is based on SFAuthorizationPluginView? I have searched on the internet and nothing shows up. I know that if we open separate windows in a mechanism that's not based on SFAuthorizationPluginView we can create a standalone app for those windows and ui test them, but it would be great if we could UI test whole flows, beginning with SFAuthorizationPluginView / built in login window and then continue on our own windows in further mechanisms. What I tried: XCUITest needs an XCUIApplication to oparete on. But what is the application here? I'd assume it's SecurityAgentHelper-x86_64 (based on accessibility inspector that is the root ancestor of my window: SecurityAgentHelper-x86_64 > Login (window) > [my text field]). But that is an XPC process, which brings me to my next point: I don't think xpc processes can be the target application in XCUIApplication's init. The init(bundleIdentifier: "com.apple.SecurityAgentHelper.x86_64") call crashes with app not found, while the init(url: URL(string: "/System/Library/Frameworks/Security.framework/Versions/Current/MachServices/SecurityAgent.bundle/Contents/XPCServices/SecurityAgentHelper-x86_64.xpc")!) call simply hangs forever, then times out. Based on the Accessibility Inspector hierarchy this app is the host application which should be opened. Without a main XCUIApplication it is impossible to start querying UI elements for UI tests, so I am stuck here.
0
0
746
Aug ’23
Parallel Distributed Testing On XCUITest
I am trying to develop new XCUITest project and my requirement is to do parallel distributed testing. Such that i have 4 iPhones and 6 classes. Each class should run once and if it is executed then it should not be executed on any other iPhone. Example: class to be executed: Class1, Class2, Class3, Class4, Class5, Class6 No of iPhones: iPhone1, iPhone2, iPhone3, iPhone4 Now execution should be like this iPhone1: Class1, Class5 iPhone2: Class2, Class6 iPhone3: Class3 iPhone4: Class4 I have tried test plan, fastlane & xcodebuild still not able to find the solution. Does anyone has any idea how can we achieve this or if someone has implemented this in their project. Any help would be great.
1
0
688
Aug ’23
Error reporting test coverage in Xcode 14.3.1
Xcode is throwing an error when attempting to report test coverage after running unit tests. Showing All Messages Failed to merge raw profiles in directory /{my project dir}/DerivedData/{my project name}/Build/ProfileData/A98EC493-3AB4-4B1C-B7FC-BC5D77B23EE3 to destination /{my project dir}/DerivedData/{my project name}/Build/ProfileData/A98EC493-3AB4-4B1C-B7FC-BC5D77B23EE3/Coverage.profdata: Aggregation tool '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/llvm-profdata' failed with exit code 1: warning: /{my project dir}/DerivedData/{my project name}/Build/ProfileData/A98EC493-3AB4-4B1C-B7FC-BC5D77B23EE3/997F01E3-3735-4897-AE00-31EBB0A9E8D3-57885.profraw: invalid instrumentation profile data (file header is corrupt) error: no profile can be merged Anyone else seeing this issue?
11
1
2.7k
Apr ’24
UI test: Unable to access view in table view
I have some view which contents I want to interact with in UI test. In the first case, when view is added to view controller everything is fine - I can access all its contents. However, when the same view is added to table view cell, some of its content become unaccessible. Here is view example class SomeView: UIView { required init?(coder: NSCoder) { fatalError() } override init(frame: CGRect) { super.init(frame: frame) let label = UILabel(frame: .init(x: 5, y: 5, width: 100, height: 20)) label.text = "Label" label.accessibilityIdentifier = "label" addSubview(label) let button = UIButton(frame: .init(x: 5, y: 35, width: 100, height: 20)) button.setTitle("Button", for: .normal) button.accessibilityIdentifier = "button" button.setTitleColor(.black, for: .normal) addSubview(button) let view = UIView(frame: .init(x: 5, y: 65, width: 100, height: 20)) view.backgroundColor = .red view.accessibilityIdentifier = "container" addSubview(view) let view2 = UIView(frame: .init(x: 0, y: 0, width: 100, height: 20)) view2.backgroundColor = .red view2.accessibilityIdentifier = "inner_view" view.addSubview(view2) let label2 = UILabel(frame: .init(x: 0, y: 0, width: 100, height: 20)) label2.text = "Label2" label2.accessibilityIdentifier = "inner_label" view2.addSubview(label2) accessibilityIdentifier = "some_view" } } And output from UI test Attributes: Application, 0x7fb4b9d0e680, pid: 71041, label: 'UITest' Element subtree: →Application, 0x7fb4b9d0e680, pid: 71041, label: 'UITest' Window (Main), 0x7fb4b9d0ae20, {{0.0, 0.0}, {390.0, 844.0}} Other, 0x7fb4b9b08bc0, {{0.0, 0.0}, {390.0, 844.0}} Other, 0x7fb4b9b0b040, {{0.0, 0.0}, {390.0, 844.0}} Other, 0x7fb4b9b0ac80, {{0.0, 0.0}, {390.0, 844.0}} Other, 0x7fb4b9b09960, {{0.0, 50.0}, {200.0, 100.0}}, identifier: 'some_view' StaticText, 0x7fb4b9b0ec80, {{5.0, 55.0}, {100.0, 20.0}}, identifier: 'label', label: 'Label' Button, 0x7fb4b9b10770, {{5.0, 85.0}, {100.0, 20.0}}, identifier: 'button', label: 'Button' StaticText, 0x7fb4b9b0bbf0, {{28.0, 84.0}, {54.0, 22.0}}, label: 'Button' Other, 0x7fb4b981b1d0, {{5.0, 115.0}, {100.0, 20.0}}, identifier: 'container' Other, 0x7fb4b981b2e0, {{5.0, 115.0}, {100.0, 20.0}}, identifier: 'inner_view' StaticText, 0x7fb4b981c0d0, {{5.0, 115.0}, {100.0, 20.0}}, identifier: 'inner_label', label: 'Label2' Table, 0x7fb4b981c1e0, {{16.0, 343.0}, {361.0, 244.0}} Cell, 0x7fb4b981c2f0, {{16.0, 343.0}, {361.0, 100.0}} StaticText, 0x7fb4b981c420, {{21.0, 348.0}, {100.0, 20.0}}, identifier: 'label', label: 'Label' StaticText, 0x7fb4b981c530, {{21.0, 408.0}, {100.0, 20.0}}, identifier: 'inner_label', label: 'Label2' Button, 0x7fb4b981c640, {{21.0, 378.0}, {100.0, 20.0}}, identifier: 'button', label: 'Button' StaticText, 0x7fb4b981c750, {{44.0, 377.0}, {54.0, 22.0}}, label: 'Button' Other, 0x7fb4b981c860, {{16.0, 343.0}, {361.0, 100.0}} Other, 0x7fb4b981c970, {{16.0, 343.0}, {361.0, 100.0}} Other, 0x7fb4b9b05400, {{36.0, 442.7}, {341.0, 0.3}} Path to element: →Application, 0x7fb4b9d0e680, pid: 71041, label: 'UITest' Query chain: →Find: Target Application 'com.temp.temp.UITest' Output: { Application, 0x7fb4b981ce80, pid: 71041, label: 'UITest' } As you can see, in table view I am missing some_view, container and inner_view views. Is there a way to access these elements in table view?
0
0
551
Jul ’23
XCode 14.3.1 - M1 runner - UI tests doesn't create clones of simulators
I'm having problems with UI tests on an M1 runner using Xcode 14.3.1. In my project, I need to build using the Rosetta simulator because I have a dependency that is not updated to support the arm simulator. This dependency relies on OpenCV." This is the command that I use when I want to run UI tests on CI: xcodebuild ARCHS=x86_64 clean test -scheme UITests -configuration Debug -destination 'id=50E9C593-9A40-4E4D-B58D-1DE437CFBE3A' -parallel-testing-enabled YES -parallel-testing-worker-count 3 -maximum-concurrent-test-simulator-destinations 4 -test-iterations 3 -retry-tests-on-failure And this code run only with 1 clone of simulator. Anyone know why?
2
0
1.8k
Oct ’23
XCUITest is not able to detect element nested view hierarchy post 62 depth.
Hi, We are writing our automation tests on app based which is hybrid of Native and React Native. We are using Appium 1.22.3 and on some screens it is not able detect element s and giving us stale Error. On deep diving, we debugged and created a project with dummy views, wrote XCUITest and found out that after number of children (in view hierarchy is greater than 62), it is not able to detect the elements. It truncates the snapshot of generated tree hierarchy. It seems like a limitation from XCUITest, irrespective of native or React Native. What is a resolution to fix this and How can we unblock our automation on this massive problem? Thanks
2
0
764
Aug ’23
Apple Silicon and UI tests
Several of our UI tests started failing when we switched over to M2 Macs... The issue with the affected tests seems to be that have a element.swipeLeft() in them, the swipeLeft doesn't seem to work the same... Is there a fix to the swipeLeft() issue yet? If not, is there an easy way to programmatically test if we are running on an Apple Silicon Mac? Any other ideas? Thank you!
2
0
691
Aug ’23
XCUIElement's Print Statement Not Including Nested Button
Example Image: Expected Behavior: When an XCUIElement is rendered from a screen with (Initial Conditions): An ImageView with.. isUserInteractionEnabled = YES… IsAccessibilityElement = YES… A nested button… isUserInteractionEnabled = YES… IsAccessibilityElement = YES… Assigned to the ImageViews accessibility elements array XCUIElement’s print statement includes the nested button Current Behavior: When an XCUIElement is rendered from a screen with: (above Initial Conditions) XCUIElement’s print statement only include the ImageView Attempted Fixes: Combinations of the Initial Conditions: Attempted all combinations of Initial Condition variable values. (ie: myImageView.accessibilityElements = [imageView, nestedButton] myImageView.accessibilityElements = [nestedButton] isUserInteractionEnabled = YES/NO [for both] IsAccessibilityElement = YES/NO [for both] etc…) Debug Print: Image View with No Descendants - Image, 0x7fa875d23e80, {{172.7, 292.7}, {45.0, 41.7}}, label: 'demo image' po element.images and po element.buttons - Find: Descendants matching type Image Output: { Image, 0x7fa876e14e70, {{-8.0, 99.0}, {136.7, 109.3}} Image, 0x7fa876e14f80, {{-8.0, 741.7}, {136.7, 102.3}} Image, 0x7fa876e13da0, {{269.7, 737.0}, {136.3, 123.0}} Image, 0x7fa876e1a060, {{172.7, 292.7}, {45.0, 41.7}}, label: 'demo image' } Output: { Button, 0x7fa875c12740, {{0.0, 47.0}, {68.0, 44.0}}, label: 'myApp UIKit' Button, 0x7fa875c24f00, {{338.0, 47.0}, {44.0, 44.0}}, identifier: 'Settings Button', label: 'Settings' Button, 0x7fa875c2c800, {{175.0, 533.0}, {40.0, 40.0}} Button, 0x7fa875c2cf30, {{183.0, 541.0}, {24.0, 24.0}} Button, 0x7fa875c2fa20, {{40.0, 659.3}, {153.0, 44.0}}, label: 'Left' Button, 0x7fa875c30cd0, {{197.0, 659.3}, {153.0, 44.0}}, label: 'Right' } Comparing the coordinates of the parent image view and the nested button, the button isn't here. The 24x24 button that appears comes from another view on the same screen, noting the ample y coordinate from the parent image view. Request: Request that Apple, in the spirit of XCUI framework being to be near to human experience include this common design case
1
1
596
Aug ’23
Run UI tests on multiple devices in succession?
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?
2
0
1.7k
Nov ’23
"XCTAutomationSupport couldn’t be loaded because it is damaged or missing necessary resources"
We're seeing this message when trying to run test automation on iOS 17. We're building the app on Sonoma, using Xcode 15, and running on iOS 17 (physical iPhone 13). At one point in the test we want to verify that something is correctly set in the iOS Setting app. We were previously doing this by launching com.apple.Preferences On iOS 17 we're getting a failure because "XCTAutomationSupport couldn’t be loaded because it is damaged or missing necessary resources" I suspect that the error message is not actually representative of the real error Anyone seen this before?
9
0
2.1k
Aug ’23
Not able to find user generated alerts in XCTest on Ventura
This is for MacOS My app posts errors during its operation. Two years ago the following used to be able to test whether the alert was correct (or missing) func isRightAlert(alertImgStr: String, target: String) -> Bool{ let app = XCUIApplication() let ackdialog = app.dialogs["alert"] let imageexists = ackdialog.images[alertImgStr/*"CaptureEclipse alert"*/].exists //let full = app.debugDescription XCTAssert(imageexists) let acklist = ackdialog.children(matching: .staticText) //NSLog( String(acklist.count)) var found = false NSLog("Alert>>>>>>>>>>>") for index in 0...acklist.count - 1{ <see if is is one of the expected ones> } <other tests> } Now that I am on Ventura with XCode 14.3 it is no longer able to detect the alert. ackdialog returns as not found. imageexists is false which triggers the Assert The alert is on the screen when the timeouts I added trigger app.debugDescription justs lists all of my menu entries These are my own alerts (NSAlert) and not system alerts.
5
0
715
Aug ’23