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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31874855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:38:43  来源:igfitidea点击:

Xcode 7 UI Tests, Recording button is greyed out

iosiphonexcodexcode7xcode-ui-testing

提问by rustylepord

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?

我正在尝试使用 Xcode 7 将 UI 测试添加到我现有的项目中。但是,UI 测试录制按钮始终显示为灰色。我在这里缺少什么?

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

我尝试重新启动 Xcode,清理并重建项目并添加一个新的 UI 测试目标。有没有其他人经历过同样的行为?

采纳答案by Le Mot Juiced

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 iOS8.x, and UITesting only works in iOS9+.

我试图使用 iOS8.x,而 UITesting 仅适用于 iOS9+。

Switch the simulator version, and the record button appears.

切换模拟器版本,出现录制按钮。

回答by pableiros

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

要启用红色按钮,您必须将光标放在测试方法上:

enter image description here

在此处输入图片说明

回答by Maldron

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:

我也被这个问题困住了一段时间。为了记录,您必须在 Xcode 识别为包含测试的类中。将文件添加到您的 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.

保存文件,清理你的项目,然后切换到另一个文件,然后再回到这个文件。录制按钮应该是可用的。

回答by toxicsun

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 小时),索引完成后,录制按钮变为活动状态。

回答by Tal Zion

Had the same issue on Xcode 8.3.

在 Xcode 8.3 上有同样的问题。

I have removed the tearDownmethod

我已经删除了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.

由于不需要使用它。一旦我将它添加回来,记录按钮就被启用了。

回答by Chase Holland

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

对我来说,问题是“版本编辑器”窗格已打开。我一切换回助理编辑,它就起作用了。

回答by leopic

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

回答by Manuel

A test method has to begin with the word testfor 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 识别该方法的一个迹象是出现在方法名称左侧的菱形:

enter image description here

在此处输入图片说明

回答by Rajneesh071

Check your version editor and correct it

检查您的版本编辑器并更正

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by Tamás Sengel

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

听起来很傻,我不得不从左侧的侧边栏中选择另一个文件,然后返回我的带有测试用例的文件。之后,按钮立即变为活动状态。