Pheepster
Pheepster

Reputation: 6367

Record button disabled in Xcode UI Test Target

I know similar questions have been posted, but from my investigating, there has not been a solution posted, at least not one that works. I have successfully run UI tests only from sample projects in both Swift and Obj-C.

I am trying (unsuccessfully) to integrate UI tests into an existing Xcode Obj-C project, which seems to be another issue altogether. Here are the steps I have taken:

  1. Created a new UI Test target within my project
  2. Ensured that 'Enable Testability' has been set to YES for the target I am testing
  3. Cleaned, cleaned build folder, rebuilt the app, restarted Xcode and everything else I could think of.

When I do this, the test target is available but the record button is greyed out (disabled) and there are no play buttons in the gutter to execute the tests. There is nothing visual about the test class that would indicate that it is a test class. When I place my cursor in the test method, the record button remains disabled.

Is there anything I've left out? Anything else to check that might be preventing UI tests?

Upvotes: 22

Views: 9141

Answers (12)

Leszek Szary
Leszek Szary

Reputation: 10346

If you have this issue in Xcode 16 then possibly the problem is that you are trying to record inside an automatically generated test function which looks like below:

@MainActor
func testExample() throws {
    // UI tests must launch the application that they test.
    let app = XCUIApplication()
    app.launch()

    // Use XCTAssert and related functions to verify your tests produce the correct results.
    
}

But there seems to be a bug in Xcode 16 and if there is @MainActor before the test function then the record button is disabled, so in this case try to remove/comment the @MainActor line.

Upvotes: 1

Vladislav
Vladislav

Reputation: 1

if you don't see the rhombuses against the function definition that allows you to run the specific test in your editor, that means something is wrong with Xcode and you should try to reopen it. Helped me. Until you don't see the rhombuses the record button is disabled.

Upvotes: 0

kgaidis
kgaidis

Reputation: 15639

I followed all the tips listed here, and the only thing that fixed it was restarting Xcode.

Upvotes: 20

Pankaj Kulkarni
Pankaj Kulkarni

Reputation: 561

If your project has a test plan (.xctestplan) then make sure that the new test is enabled. Till then the record button will be disabled. This often happens when you add a new UI Test Case Class. Or when you add new test to existing class which has some of the tests disabled.

Upvotes: 0

zs2020
zs2020

Reputation: 54543

  1. Click on 6th button from top of the left pane - Show the test navigator
  2. Right click on the UI tests, then click on "Enable ... "

Then you can record.

Upvotes: 3

Calin Drule
Calin Drule

Reputation: 2949

Also, make sure you select the UI test scheme, which was the problem in my case:

enter image description here

Upvotes: 0

Papon Smc
Papon Smc

Reputation: 688

  1. create function in yourfileUITests.swift

enter image description here

  1. running program by TEST

enter image description here

  1. your function can record UI Testing, button already enable

enter image description here

Upvotes: -1

Arbitur
Arbitur

Reputation: 39091

I realized you had to have your cursor inside the test function you want to record for. I simply clicked inside the test function and the record button got enabled.

Upvotes: 1

Domnic Francis
Domnic Francis

Reputation: 321

  1. Record button only gets enabled within a function body.

  2. The function name must start with test. Like testExample().

  3. After changing the name of the function wait for a few seconds for the run icon to appear in the gutter.

Now the record button should appear.

Upvotes: 32

Shelly Jaglan
Shelly Jaglan

Reputation: 31

Make sure you have at least one test function in your ui test class. For example- func testExample(){}. Then you'll be able to record in that function as you can only run functions as tests if they have test as prefix.

Upvotes: 1

Federico Jordan
Federico Jordan

Reputation: 186

Make sure you are in the correct XCTestCase subclass file.

After researching for a time, I found that I was all the time in a extension file (I'm been ordering the flows in extension files). So when I opened the main XCTestCase subclass file (like "YourAppUItests") the record test button has been enabled.

Upvotes: 7

samwize
samwize

Reputation: 27383

Make sure you can build for the test target successfully.

Go to Product > Test, and make sure the UI Testing test case is run (it is fine if the test case is empty). You should also see the test cases under Test Navigator, or in the app target scheme.

Upvotes: 2

Related Questions