XCTest: App is terminated after changing device language
My UI test scenario is simple. Change device language in settings app and open my test app to check if the language in app is changed accordingly. And I would check about 5 languages so that involve switching between test app and settings app.
The problem is that when I applied the language change in device settings, the test is stopped. It shows "Message from debugger: Terminated due to signal 9" in console, I think that means my app was terminated by some cause.
So is that a correct behavior? If it is, how could I check test app's language after changing the device language?
Here is an example about the test case:
func testExample() throws {
// 1. lauch settingsApp
let settingsApp = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
settingsApp.launch()
// 2. change device language in settingsAPP and apply the change
// MARK: App was terminated: Message from debugger: Terminated due to signal 9
// 3. launch my app to check if language was changed accordingly
let app = XCUIApplication()
app.launch()
}
do you know?
how many words do you know
See also questions close to this topic
-
Command failed: xcrun instruments -s
I want to run my react native app on a real ios device with this line :
npx react-native run-ios --udid SOME-UDID
but i got this error :
xcrun: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find instruments 2> /dev/null' failed with exit code 17664: (null) (errno=No such file or directory) xcrun: error: unable to find utility "instruments", not a developer tool or in PATH error Command failed: xcrun instruments -s xcrun: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find instruments 2> /dev/null' failed with exit code 17664: (null) (errno=No such file or directory) xcrun: error: unable to find utility "instruments", not a developer tool or in PATH
everything is ok on simulator
I'm using XCODE 13
-
IOS Launcher in android studio
I'm trying to change the whole Android OS installed app icons into IOS icons, please help me with the proper code or library for android kotlin
-
Debugging undefined is not an object (evaluating 'Object.keys(routeConfigs)')
I'm using Expo and React Native to create a simple iOS app. I am currently getting this error and have no idea how to fix it. I've tried various other solutions on Stack Overflow to no avail.
My code is:
import 'react-native-gesture-handler'; import React from 'react'; import { createStackNavigator } from 'react-navigation-stack'; import { NavigationContainer } from '@react-navigation/native'; import HomeScreen from './src/screens/HomeScreen'; const Stack = createStackNavigator(); export default function App() { return ( <NavigationContainer> <Stack.Navigator> <Stack.Screen name="Home" component={HomeScreen} /> </Stack.Navigator> </NavigationContainer> ); }
Here is my
HomeScreen.js
import React from 'react'; import { Text, View } from 'react-native'; export default function HomeScreen () { return ( <View> <Text>Welcome Home!</Text> </View> ) }
My packages:
"packages": { "": { "name": "safey", "version": "1.0.0", "dependencies": { "@react-native-community/masked-view": "^0.1.11", "@react-navigation/native": "^6.0.10", "@react-navigation/stack": "^6.0.10", "expo": "~45.0.0", "expo-splash-screen": "~0.15.1", "expo-status-bar": "~1.3.0", "react": "17.0.2", "react-dom": "17.0.2", "react-native": "0.68.1", "react-native-gesture-handler": "^2.4.2", "react-native-reanimated": "^2.8.0", "react-native-safe-area-context": "^4.2.5", "react-native-screens": "^3.13.1", "react-native-web": "0.17.7", "react-navigation": "^4.4.4", "react-navigation-stack": "^2.10.4" },
-
SwiftUI, apply drawGesture only when over Image
I'm try to apply the gesture only when the user is over the Image display not when tapped outside the image.
Any suggestion how I can do? this following code draw also when user tap outside the image.
struct ContentView: View { @StateObject var am = AppManager() @State var switchToTakePicture = false @State var paths: [PathContainer] = [] @State var currentDraggingId = UUID() @State var spikoPic = #imageLiteral(resourceName: "spiko-16.jpeg") @State var centerOFimage = CGSize(width: 0, height: 0) var body: some View { GeometryReader { proxy in ZStack { Image(uiImage: spikoPic) .resizable() .scaledToFit() .position(x: proxy.size.width/2, y: proxy.size.height/2) .background(GeometryReader { Color.clear.preference(key: ViewRectKey.self, value: [$0.frame(in: .global)]) }) .gesture(drawGesture) // not correct ForEach(paths) { container in // draw and set the foreground color of the paths to red container.path .stroke(Color.red, lineWidth: 4) } } .onPreferenceChange(ViewRectKey.self) { rects in print(rects.first ?? .zero) } } } var drawGesture: some Gesture { DragGesture(minimumDistance: 0) .onChanged { value in // The point that the gesture started from let start = value.startLocation // The point that the gesture ended to let end = value.location // the properties of the rectangle to be drawn let rectangle: CGRect = .init(origin: end, size: .init(width: start.x - end.x, height: start.y - end.y)) // create a path for the rectangle let path: Path = .init { path in path.addRect(rectangle) } print("rettangolo = \(rectangle) orig \(rectangle.origin) - height \(rectangle.height) width = \(rectangle.width)") // remove the previous rectangle that was drawen in current // process of drawing paths.removeAll { $0.id == currentDraggingId } // append the new rectangle paths.append(.init(id: currentDraggingId, path: path)) } .onEnded { _ in // renew the dragging id so the app know that the next // drag gesture is drawing a completely new rectangle, // and is not continuing the drawing of the last rectangle currentDraggingId = .init() } } }
i want no box outside
-
How to navigate between NavigationLink while leave a part of main window stay the same in SwiftUI
I would like to navigate between different
NavigationLink
s inNavigationView
while some part of the main window stay the same. For example, I want to make a music app and I want to let the play controller always on top, while I can display different navigation contents (songs page, artists page...) using the rest of the window.Like what's showed in the picture below, I want to keep the red part always there while the blue part changes.
My code would be like below, but it won't work correctly. The
AlwaysStayView()
disappears when I click anyNavigationLink
on sidebar. So, how can I correct it or is there any solution (prefer in SwiftUI, but framework like UIKit would also be OK). I would appreciate it.NavigationView { List { NavigationLink { DiscoverView() } label: { Label("Discover", systemImage: "magnifyingglass") } NavigationLink { SongsView() } label: { Label("Songs", systemImage: "music.note") } NavigationLink { ArtistsView() } label: { Label("Artists", systemImage: "music.mic") } } } .listStyle(SidebarListStyle()) VStack { AlwaysStayView() SongsView() } }
-
NumberFormatter and unsigned with UInt64.max
I'm trying to create a string representing
UInt64.max
usingNumberFormatter
. Here's the code:let formatter = NumberFormatter() formatter.usesGroupingSeparator = true formatter.numberStyle = .decimal formatter.positiveFormat = "# ##0.#########" formatter.maximumSignificantDigits = 20 formatter.usesSignificantDigits = false formatter.maximumFractionDigits = 20 formatter.minimumFractionDigits = 0 formatter.alwaysShowsDecimalSeparator = false // formatter.roundingMode = .halfUp let text1 = formatter.string(for: NSNumber(value: Int64.max)) let text2 = formatter.string(for: NSNumber(value: UInt64.max)) print(text1) print(text2)
which prints:
Optional("9,223,372,036,854,780,000")
Optional("-1")but should print
Optional("9223372036854775807")
Optional("18,446,744,073,709,551,615")It looks like
NSNumber
is roundingInt64
and isn't taking theUIn64
. The obj-c version ofNSNumberFormatter
works fine.Am I missing something or is there a problem with
NumberFormatter
? -
Referencing static string in Xcode UI test with apostrophe
In my project is a localized string in a *.strings file like this...
"some_key" = "Yada yada won't blah.\nBlah blah?";
In my UI Test, when I record the element and when I print object on the staticTexts dictionary, it's referenced with a string like this...
app.staticTexts["Yada yada won't blah.\nBlah blah?"]
However, in my test I localize the key and the string comes out with an extra escape character for the apostrophe in the contraction which I believe is breaking the label reference...
print("some_key".localized) Yada yada won\'t blah.\nBlah blah?
I've tried replacing "\'" with "'" and even the below code...
let begin = id.substring(start: 0, offsetBy: 15) let end = id.substring(start: 16, offsetBy: 41) id = "\(begin ?? "")'\(end ?? "")"
...but the escape is always there.
How do I keep the break line, but remove the escape on the apostrophe?
I don't control the client code being tested, so I can't change how the text is setup and I can't reference with an accessibility identifier.
-
XCTAssertEqual failed: ("nan") is not equal to ("nan") in Swift
When I run the following test case, I get
XCTAssertEqual failed: ("nan") is not equal to ("nan")
error.XCTAssertEqual(0.0 / 0.0, Double.nan)
How can I fix this error?
-
How can I download apps to iOS Simulator?
with the recent updates appstore is not available in simulator. I want to download apps such as twitter, facebook etc... to implement some UITests. How can I achieve that?
-
Is there a way to disable iOS simulator's network during a UI automation test
I get many tests, which require no network state. Because all the tests will executed in CI so cannot use a real device.
Solutions I found from internet:
- There is tool could be installed in Mac and control network status -> Cannot use for an automation test.
- Use real device -> No, because all tests would be executed in CI and also include parallel, so simulator is better way.
After these failed attempts, I inject "noNetwork" as environment to the app like this minimum example. And return a "noNetwork" Error to API calls if this env exist in code.
// In test envs["networkStatus"] = "noNetworkConnection" launchEnvironment = envs // In app code if ProcessInfo.processInfo.environment["networkStatus"] == "noNetworkConnection" { completion(.failure(.noNetworkConnection)) }
It block the Simulator's network but another problem is coming, because
launchEnvironment
takes effect when app is launched, and there is API calls during app launch, so these API calls also get blocked as no network.My purpose is to reach to a certain step then disable the network. I'm wondering whether there is a way to inject the env or what ever to the app during a UI test? Appreciate for any help, guys.
-
How to solve 'Test runner exited before starting test execution' error for iPhone Devices
Context -
We have E2E Testing running on the CI on the iPhone devices.
The script performs the following steps -
- Build the Test runner app from code.
- Extracts the app file from the IPA.
- Re-codesign the app with the required Provision Profiles.
- Creates a
.xctestrun
file - Uses the
xcodebuild
command like the following to run the test -
xcodebuild -sdk iphoneos -destination id=<device_id> -xctestrun <path_to_xctestrun_file> -resultBundlePath <path_to_test_bundle_file> test-without-building -only-testing:E2ETestsBundle.xctest/<test_filter>
- The above command installs the runner and target app into the device and starts executing the test.
The apps get installed and uninstalled at each run during a single execution.
Problem -
During the execution, the
xcodebuild
CLI tool, suddenly loses connection to the device and is not able to install the apps into the device and then results in the following error -Testing failed: E2ETestsBundle.xctest: E2ETestsBundle-Runner encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted. (Underlying Error: Test runner exited before starting test execution. If you believe this error represents a bug, please attach the log file at /var/folders/1r/0xlnbmzd0yj3m_cc7p95yb4r0000gn/T/tmpl7d9p1s6/testResults.bundle/Staging/1_Test/Diagnostics/E2ETestsBundle-Configuration-Test Scheme Action-Iteration-1/E2ETestsBundle/Session-E2ETestsBundle-2022-04-13_205520-muaMCx.log)) ** TEST EXECUTE FAILED **
Points to note -
- The
xcodebuild
CLI tool will keep on failing with the error once it occurred until recovered. - Even while the xcodebuild is in a failed state, the devices are still accessible via Xcode IDE and other CLI tools like libimobiledevice and are able to install both the test runner and target applications.
- This is occurring intermittently across all devices models and across subversions of iOS 14 and 15.
Recovery -
- The only way to recover is to reboot the device.
- Even after a reboot, the devices start facing this exception again after a few days of execution.
As we can’t keep on rebooting the device every time before execution, we need a solution to fix this problem. Any help would be appreciated!!
-
I want to understand how i can XCTest that a list of Countries are Sorted
Im writing a UITest to check if a List of Countries populated in my tableview are displayed in ascending order. I am populating the countries from Countries api
The purpose of my UITest is to check the countries are displayed in alphabetical order, so I pick ten countries at random in ascending order of table index and confirm that the countries are in ascending order too.
let table = app.tables["CountryTable"] XCTAssertTrue(table.waitForExistence(timeout: kTimeOut)) let cells = table.cells.allElementsBoundByIndex var indexes = Set<UInt32>() while indexes.count < 10 { indexes.insert(arc4random_uniform(UInt32(cells.count))) } let orderedIndexes = Array(indexes).sorted() let countries = orderedIndexes.map { (index) -> String in return cells[Int(index)].staticTexts["Country"].label } let orderedCountries = countries.sorted() XCTAssertEqual(countries, orderedCountries)
In my ViewController i can see that the countries are sorted in ascending order, but my Test is failing.
i will be glad to be educated on how to test this approach appropriately and make the Test pass.