简体   繁体   English

Xcode 7 UI 测试,录制按钮灰显

[英]Xcode 7 UI Tests, Recording button is greyed out

I am trying to add UI tests to my existing project using Xcode 7. However the UI test recording button is always greyed out.我正在尝试使用 Xcode 7 将 UI 测试添加到我现有的项目中。但是,UI 测试录制按钮始终显示为灰色。 What I am missing here?我在这里缺少什么?

I tried restarting Xcode, cleaning and rebuilding the project and adding a new UI test target.我尝试重新启动 Xcode,清理并重建项目并添加一个新的 UI 测试目标。 Does anyone else experience the same behaviour?有没有其他人经历过同样的行为?

To enable the red button, you have to have the cursor on the test method:要启用红色按钮,您必须将光标放在测试方法上:

在此处输入图片说明

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.为了记录,您必须在 Xcode 识别为包含测试的类中。 Add a file to your UI testing target with something like:将文件添加到您的 UI 测试目标,例如:

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.录制按钮应该是可用的。

FWIW: I had this problem and it turns out I was trying to run the simulator in the wrong OS. FWIW:我遇到了这个问题,结果我试图在错误的操作系统中运行模拟器。

I was trying to use iOS 8, and UITesting only works in iOS 9+.我试图使用 iOS 8,而 UITesting 仅适用于 iOS 9+。

Switch the simulator version, and the record button appears.切换模拟器版本,出现录制按钮。

I had the same issue and my setup was correct, iOS >= 9.0, target was added.我遇到了同样的问题,我的设置是正确的,iOS >= 9.0,添加了目标。

The problem was Xcode indexing which took for a while (about 1h), after indexing was done, recording button becomes active.问题是 Xcode 索引需要一段时间(大约 1 小时),索引完成后,录制按钮变为活动状态。

Had the same issue on Xcode 8.3.在 Xcode 8.3 上有同样的问题。

I have removed the tearDown method我已经删除了tearDown方法

   override func tearDown() {
        super.tearDown()

    }

As didn't need to use it.由于不需要使用它。 As soon as I added it back the record button was enabled.一旦我将它添加回来,记录按钮就被启用了。

For me, the problem was the "Version Editor" pane was open.对我来说,问题是“版本编辑器”窗格已打开。 As soon as I switched back to the Assistant Editor, it worked.一旦我切换回助理编辑器,它就起作用了。

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.测试方法必须以单词test开头,以便 Xcode 识别它并允许在光标位于方法内时进行记录。

One indication that Xcode recognized the method is a rhombus appearing left to the method name: Xcode 识别该方法的一个迹象是出现在方法名称左侧的菱形:

在此处输入图片说明

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.确保你有一个 UITesting 目标,一个常规的测试目标并没有为我做。

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.之后,按钮立即变为活动状态。

Check your version editor and correct it检查您的版本编辑器并进行更正

在此处输入图片说明

在此处输入图片说明

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. (可选,推荐)- 删除项目的所有 TEST 方案和 TEST 目标,通过创建新的 UITest 目标重新开始。
  2. Make sure that your UITest scheme and main project run scheme point to the same target.确保你的 UITest 方案和主项目运行方案指向同一个目标。
  3. Try deleting your other UITest schemes if they can be easily recreated/are not of absolute importance.如果可以轻松重新创建/不是绝对重要,请尝试删除其他 UITest 方案。
  4. Product > (Press and hold ALT key) > Clean Build Folder产品 >(按住 ALT 键)> 清理构建文件夹
  5. Product > Clean (just for safe measure)产品 > 清洁(只是为了安全措施)
  6. Close project, quit Xcode.关闭项目,退出 Xcode。
  7. Quit simulator.退出模拟器。
  8. Finally, reopen Xcode, load your project.最后,重新打开 Xcode,加载您的项目。 Navigate to your UITest file and the little red button of joy should be available for usage.导航到您的 UITest 文件,应该可以使用红色的快乐小按钮。

Also, make sure that your build/run target is set to iPhone X 9.X.此外,请确保您的构建/运行目标设置为 iPhone X 9.X。

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.如果您要继承XCTestCase ,请更改您的类以再次继承它,保存文件,将其改回您的子类名称。 No clean or build needed.无需清理或构建。

For my project I've got a sublcass of XCTestCase , let's call it APPMyTestCase .对于我的项目,我有一个 XCTestCase 的XCTestCase ,我们称之为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.如果我将我的子类改回XCTestCase一秒钟,一切都会恢复正常。

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.这为我修好了。

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.确保您使用UI testing方案,因为 UI 测试记录器无法在任何其他方案上工作。

Be sure to only have one subclass of XCTestCase per file.确保每个文件只有一个XCTestCase子类。 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).根据我的经验,即使你有 UI 测试工作,如果你在同一个文件中添加你的工作 XCTestCase 子类的新子类,记录按钮将被禁用(尽管所有其他测试 UI 将继续工作)。

When I created a UITest Target, a new scheme was not simultaneously created.当我创建 UITest Target 时,并没有同时创建一个新方案。 So, I had to create a new scheme with the test target that I had created.因此,我必须使用我创建的测试目标创建一个新方案。 This enabled the record button.这启用了记录按钮。

You should import the View Class you want to Test.您应该导入要测试的视图类。 Then put the cursor in the test method.然后将光标放在测试方法中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM