Reputation: 5801
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?
Upvotes: 31
Views: 12699
Reputation: 12011
My case is not a typical one. I had to delete @MainActor
before the test declaration. I used Fastlane Snapshot setupSnapshot()
which requires MainActor.
@MainActor
func testRecord() throws {
let app = X UIApplication()
setupSnapshot(app)
app.launch()
// This won't record! (shows "At least one test should be selected")
}
//@MainActor
func testRecord() throws {
let app = X UIApplication()
//setupSnapshot(app)
app.launch()
// This will record!
}
func testEmpty() {
// This will also record like no problem!
}
Sometimes building the test schema (after adding a new method, for example) helps to resolve the gray record button.
Upvotes: 0
Reputation: 821
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.
Upvotes: 0
Reputation: 3849
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.
Upvotes: 14
Reputation: 107
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.
Upvotes: 0
Reputation: 61
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.
Upvotes: 1
Reputation: 58139
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.
Upvotes: 2
Reputation: 15072
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:
Upvotes: 4
Reputation: 16062
To enable the red button, you have to have the cursor on the test method:
Upvotes: 40
Reputation: 6526
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.
Upvotes: 6
Reputation: 1762
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).
Upvotes: 0
Reputation: 397
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.
Upvotes: 12
Reputation: 3497
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.
Upvotes: 1
Reputation: 2268
For me, the problem was the "Version Editor" pane was open. As soon as I switched back to the Assistant Editor, it worked.
Upvotes: 4
Reputation: 86
I did a few things to enable my record button:
Also, make sure that your build/run target is set to iPhone X 9.X.
Upvotes: 1
Reputation: 3012
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.
Upvotes: 3
Reputation: 571
You should import the View Class you want to Test. Then put the cursor in the test method.
Upvotes: -2
Reputation: 160
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.
Upvotes: 16