Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 316
Arun Avatar asked Mar 27 '18 12:03

Arun


People also ask

How to localize app name and authorization requests with infoplist?

Localize App Name and Authorization requests with Info.plist To localize your Info.plist content, add a new strings file to your project (as in step 1), and name it InfoPlist.strings. For the App name, the CFBundleDisplayName key is used by iOS to translate the app nane from Localizable.strings file.

How to find bundle ID for an iOS app?

So, to find an iOS Apps bundle ID you need to take couple steps as covered below – Steps to find the bundle ID for an iOS app ? Step 1: Search for the App Name on Google Search using your Desktop browser like Chrome, Firefox etc and open apps itunes/app store link.

How do I run a UI Test in Xcode?

When you’re ready to test, go to a test class and place the cursor inside the test method to record the interaction. From the debug bar, click the Record UI Test button. Xcode will launch the app and run it. You can interact with the element on-screen and perform a sequence of interactions for any UI test.

How do I create a new UI test target?

Creating a new UI test target for your project consists of two files with a default template. One is for regular UI tests and the other for launch tests. The former consists of two methods for the lifecycle of the test case: setUpWithError () – before each test method in a test case, you can reset the state and throw errors.


2 Answers

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
like image 174
Andreas Jünemann Avatar answered Sep 19 '22 22:09

Andreas Jünemann


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

like image 32
Anton Novoselov Avatar answered Sep 21 '22 22:09

Anton Novoselov