简体   繁体   中英

How to get App name in UITesting swift 4 iOS

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.

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

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:

在此处输入图片说明

在此处输入图片说明

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.

I am getting app name in UI test like this:

let app = XCUIApplication()
// ...
let appName = app.label

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM