17

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Pheepster
  • 6,045
  • 6
  • 41
  • 75
  • 1
    when you select the uitest file (in the project navigator on the left), do you see that it indeed has the target membership of your UITest target (in the Utilities pane on the right that lets you check/uncheck the Target Membership) ? – Nitin Alabur Jan 25 '16 at 17:18
  • 1
    Wow that worked, how annoying is that! Checking and unchecking the membership of the target works : / Please fix that @Apple – Laser Hawk Sep 19 '16 at 17:09

10 Answers10

29
  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.

jhoepken
  • 1,842
  • 3
  • 17
  • 24
Domnic Francis
  • 291
  • 3
  • 3
7

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.

Federico Jordan
  • 186
  • 2
  • 4
5

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

kgaidis
  • 14,259
  • 4
  • 79
  • 93
3
  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.

zs2020
  • 53,766
  • 29
  • 154
  • 219
2

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.

samwize
  • 25,675
  • 15
  • 141
  • 186
1

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.

0

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.

Arbitur
  • 38,684
  • 22
  • 91
  • 128
0

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

enter image description here

Calin Drule
  • 2,899
  • 1
  • 15
  • 12
0

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.

Pankaj Kulkarni
  • 553
  • 4
  • 12
-1
  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

Papon Smc
  • 576
  • 4
  • 11