Xcode 7 UI Tests, Recording button is greyed out
Asked Answered
C

17

30

I am trying to add UI tests to my existing project using Xcode 7. However the UI test recording button is always greyed out. What I am missing here?

I tried restarting Xcode, cleaning and rebuilding the project and adding a new UI test target. Does anyone else experience the same behaviour?

Corroboration answered 7/8, 2015 at 9:54 Comment(0)
S
14

FWIW: I had this problem and it turns out I was trying to run the simulator in the wrong OS.

I was trying to use iOS 8, and UITesting only works in iOS 9+.

Switch the simulator version, and the record button appears.

Squill answered 23/1, 2016 at 20:43 Comment(2)
The fixes to Apple's problems...simply amazing!Chlori
the test function needs to be started with "test" and there must be at least comment line inside it.Turbot
A
40

To enable the red button, you have to have the cursor on the test method:

enter image description here

Agnola answered 20/11, 2017 at 19:15 Comment(0)
L
16

I got stuck on this for a while too. In order to record, you have to be in a class that Xcode recognizes as containing tests. Add a file to your UI testing target with something like:

import Foundation
import XCTest

class MyTests: XCTestCase {
    func testSomething() {

    }
}

Save the file, clean your project, and switch to another file then back to this one. Record button should be available then.

Lilt answered 7/8, 2015 at 20:58 Comment(6)
Thanks @Lilt , I did this several times but didn't work out. Had to readd the UI test target again. Feels like UI tests are really buggy.Corroboration
Sometimes Xcode bugs out and doesn't recognize a test case as an actual test case (you aren't able to play it either, because the option is missing in the bar to the left of the method declaration. I mostly get over them by alternately restarting Xcode, and disconnecting and/or restarting the simulator or attached test device. Haven't had to restart my machine, at least!Northwestwards
By restarting Xcode has resolved the issue for me. ThanksRestrain
I have to click onto the square right the testSomething() function. This worked for meEncounter
Just an addition, my cursor had to be inside a function that started with the keyword test in my UITest file in order to get the record button to show.Jigaboo
Agreement with the above comments... physically selecting on or inside the testExample() function with the cursor enabled the button... maybe this is just my ignorance on how these tests work.Rochette
S
14

FWIW: I had this problem and it turns out I was trying to run the simulator in the wrong OS.

I was trying to use iOS 8, and UITesting only works in iOS 9+.

Switch the simulator version, and the record button appears.

Squill answered 23/1, 2016 at 20:43 Comment(2)
The fixes to Apple's problems...simply amazing!Chlori
the test function needs to be started with "test" and there must be at least comment line inside it.Turbot
P
12

I had the same issue and my setup was correct, iOS >= 9.0, target was added.

The problem was Xcode indexing which took for a while (about 1h), after indexing was done, recording button becomes active.

Pintsize answered 19/4, 2016 at 12:49 Comment(3)
This appears to be the correct answer to this question for newly created UI test targets. My indexing took over 20 minutes after which the button was available.Castorina
I made this process quicker by quitting Xcode and relaunching Xcode again. As soon as it had finished processing and I updated the cursor position the record button became available.Gluconeogenesis
Waiting for indexing to finish fixed my problem.Aston
E
6

Had the same issue on Xcode 8.3.

I have removed the tearDown method

   override func tearDown() {
        super.tearDown()

    }

As didn't need to use it. As soon as I added it back the record button was enabled.

Externalization answered 4/4, 2017 at 8:36 Comment(0)
S
4

For me, the problem was the "Version Editor" pane was open. As soon as I switched back to the Assistant Editor, it worked.

Spondee answered 26/4, 2016 at 20:5 Comment(0)
O
4

A test method has to begin with the word test for Xcode to recognize it and allow recording when the cursor is inside the method.

One indication that Xcode recognized the method is a rhombus appearing left to the method name:

enter image description here

Ocular answered 10/3, 2018 at 0:15 Comment(1)
you are right, i tested all this solutions and the only that solve me is your answer, thanksMargay
E
3

This is kind of silly, but missed out in some articles I read.

Make sure you have a UITesting Target, a regular Test target didn't do it for me.

Extension answered 3/1, 2016 at 18:41 Comment(0)
E
2

As silly as it sounds, I had to select another file from the sidebar on the left and go back to my file with the test cases. After that, the button immediately became active.

Evocative answered 13/3, 2018 at 23:51 Comment(1)
Yea.. I guess Xcode needed to refresh some internal state which happens after selecting a different file.Egon
D
2

Check your version editor and correct it

enter image description here

enter image description here

Draughtboard answered 18/9, 2018 at 7:7 Comment(0)
W
1

I did a few things to enable my record button:

  1. (Optional, Recommended) - Delete all TEST schemes and TEST targets for your project, start fresh by creating a new UITest Target.
  2. Make sure that your UITest scheme and main project run scheme point to the same target.
  3. Try deleting your other UITest schemes if they can be easily recreated/are not of absolute importance.
  4. Product > (Press and hold ALT key) > Clean Build Folder
  5. Product > Clean (just for safe measure)
  6. Close project, quit Xcode.
  7. Quit simulator.
  8. Finally, reopen Xcode, load your project. Navigate to your UITest file and the little red button of joy should be available for usage.

Also, make sure that your build/run target is set to iPhone X 9.X.

Wisent answered 13/3, 2016 at 9:57 Comment(0)
K
1

I've found another solution that I haven't seen listed here.

If you're subclassing XCTestCase, change your class to inherit from that again, save the file, change it back to your subclass name. No clean or build needed.

For my project I've got a sublcass of XCTestCase, let's call it APPMyTestCase. I often find that the record button is greyed out and sometimes the little green/red buttons next to each test method don't appear either to be able to run them individually. If I change my subclass back to XCTestCase for a second everything works again.

Change this:

class APPLoadingPageUITests: APPMyTestCase {
    // tests here
}

To this:

class APPLoadingPageUITests: XCTestCase {
    // tests here
}

And then back to this:

class APPLoadingPageUITests: APPMyTestCase {
    // tests here
}

This fixed it for me.

Kumasi answered 29/4, 2016 at 16:19 Comment(0)
B
1

It immediately came back when I switched to the right scheme. Ensure that you're on the UI testing scheme as the UI test recorder can't work on any other one.

Brachial answered 13/4, 2018 at 11:24 Comment(2)
THANK YOU VERY MUCHMirellamirelle
Thank you! I actually had to create a new scheme because a new scheme wasn't automatically created when I created a new test target.Perfectionism
E
0

Be sure to only have one subclass of XCTestCase per file. You want the filename and class names to match.

In my experience, even when you have UI tests working, if you add a new subclass of your working XCTestCase subclass in the same file, the record button will be disabled (although all other testing UI will continue to work).

Evans answered 1/6, 2016 at 6:50 Comment(0)
P
0

When I created a UITest Target, a new scheme was not simultaneously created. So, I had to create a new scheme with the test target that I had created. This enabled the record button.

Perfectionism answered 15/11, 2019 at 16:29 Comment(0)
S
0

In my case adding this import solved the issue (iOS 16, Xcode 14.2):

import Foundation

The button is enabled when I write a new function and place the cursor inside it.

Sambar answered 26/2, 2023 at 8:4 Comment(0)
D
-2

You should import the View Class you want to Test. Then put the cursor in the test method.

Desinence answered 30/10, 2015 at 6:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.