How to get App name in UITesting swift 4 iOS
Asked Answered
A

4

6

I tried to get my app name in UITesting. I tried the code below:

let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as! String

But it gives me the nil value result.

Audiogenic answered 27/3, 2018 at 12:26 Comment(1)
Did you set DisplayName from project setting of your APP??Coahuila
G
1

Are you sure, that you've set Display name in your Info.plist file? Just set this name in Project settings or in Info.plist:

enter image description here

enter image description here

Grandparent answered 27/3, 2018 at 12:36 Comment(2)
Yes. Already have added this in info.plist of UITest of Xcode. But its not working.Audiogenic
You should add this to Info.plist of your main app target, not in Testing target.. You sure you add this to your main target?Grandparent
E
8

When I was trying to find out if the 'debugDescription' provides any information about the actual app (and not the test app) I stumbled across a label that looked exactly like the app's display name.

I don't know if it helps you, but the following simple line of code helped me:

XCUIApplication().label
Exercise answered 22/8, 2018 at 9:55 Comment(2)
Unfortunately it will only work if your app is running, no?Easting
@FlavioBittencourt Yes. But if you store that name in a let constant, and then terminate the app, and then use the name you will be fineNormandnormandy
G
1

Are you sure, that you've set Display name in your Info.plist file? Just set this name in Project settings or in Info.plist:

enter image description here

enter image description here

Grandparent answered 27/3, 2018 at 12:36 Comment(2)
Yes. Already have added this in info.plist of UITest of Xcode. But its not working.Audiogenic
You should add this to Info.plist of your main app target, not in Testing target.. You sure you add this to your main target?Grandparent
S
1

I am getting app name in UI test like this:

let app = XCUIApplication()
// ...
let appName = app.label
Selfassertion answered 23/1, 2023 at 7:13 Comment(0)
D
0

Try to go to File > Workspace Settings if you are in a workspace environment or File > Project Settings for a regular project environment.

Then click over the little grey arrow under Derived data section and select your project folder to delete it.

And Product > Clean. It helps in many situations.

Dividivi answered 27/3, 2018 at 13:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.