标签: xcode-ui-testing

如何在 XCTest 的 setUp 函数中报告错误?

在我的 UI 测试中,我想在运行我的 UI 测试之前调用远程端点来重置数据库状态。这很好用,但我想确保在请求失败时我能捕捉到任何错误。我想做的是:

  1. 停止运行后续测试(将其标记为失败)
  2. 提供一些发生的事情的日志。

下面是一些示例代码,说明了我的观点:

override func setUp() {
    super.setUp()

    var finished = false

    dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)) {
        let request = Alamofire.request(.GET, "http://xxx.xxx.xxx.xxx/resetdb")
        request.response() {
            request, response, data, error in
            if let _ = error {
                let message = "Could not call remote helper -- \(response?.statusCode)"
                XCTFail(message)  // doesn't work
                debugPrint(message) // can't see this anywhere
            }
            finished = true
        }
    }

    while !finished {
        NSRunLoop.currentRunLoop().runMode(NSDefaultRunLoopMode, beforeDate: NSDate.distantFuture())
    }
    app = XCUIApplication()
    app.launch()
}
Run Code Online (Sandbox Code Playgroud)

xctest swift xcode-ui-testing

2
推荐指数
1
解决办法
1467
查看次数

在哪里可以找到从命令行启动的 XCode UITests 报告

我正在寻找一种在从命令行启动的测试完成后打开报告的方法。

使用命令行开始测试:

xcodebuild -scheme "Application Test Schema" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6s Plus,OS=9.3' test
Run Code Online (Sandbox Code Playgroud)

在测试结束时,我列出了失败的测试用例:

Test Suite 'AppUITests.xctest' failed at 2016-07-11 12:00:10.376.
     Executed 17 tests, with 1 failure (0 unexpected) in 389.167 (389.217) seconds
Test Suite 'Selected tests' failed at 2016-07-11 12:00:10.377.
     Executed 17 tests, with 1 failure (0 unexpected) in 389.167 (389.219) seconds
Failing tests:
    -[MainScreenTests test14_ClickOnButtonOpensKeyboard()]
Run Code Online (Sandbox Code Playgroud)

我想弄清楚测试“test14_ClickOnButtonOpensKeyboard”、读取堆栈跟踪等时发生了什么...我在哪里可以找到本次运行的报告?

我检查了 XCode Report Navigator 历史记录,它不包含上次从命令行启动的运行。

XCode 版本 7.3.1

xcode continuous-integration ios xcode-ui-testing xcode7.3

2
推荐指数
1
解决办法
3994
查看次数

触摸特定坐标(UI 测试)

如何使用 UITests 触摸特定坐标?

当我在特定位置录制点击时,我有类似的东西:

XCUIApplication *app = [[XCUIApplication alloc] init];
[[[[[[[[[[app.otherElements containingType:XCUIElementTypeNavigationBar 
identifier:@"Navigation Bar title"] 
childrenMatchingType:XCUIElementTypeOther].element 
childrenMatchingType:XCUIElementTypeOther].element 
childrenMatchingType:XCUIElementTypeOther].element 
childrenMatchingType:XCUIElementTypeOther] elementBoundByIndex:0] 
childrenMatchingType:XCUIElementTypeOther].element 
childrenMatchingType:XCUIElementTypeOther] 
elementBoundByIndex:0].staticTexts[@"Action"] tap];
Run Code Online (Sandbox Code Playgroud)

ios xcode-ui-testing

2
推荐指数
1
解决办法
3035
查看次数

在 xcode ui 测试执行正在进行时关闭设备的 wifi

我在 xcode ui 测试中遇到问题。

也就是说,当我的执行正在进行时,而不是在某些条件下

i have to off my wifi
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用命令来做到这一点

networksetup -setairportpower en0 on
Run Code Online (Sandbox Code Playgroud)

我在 osx 中写了一个函数:

func runTerminalCommand(args: String...) -> Int32 {
let task = NSTask()
task.launchPath = "/usr/bin/env"
task.arguments = args
task.launch()
task.waitUntilExit()
return task.terminationStatus
Run Code Online (Sandbox Code Playgroud)

}

如果我在 osx 中使用它,我可以关闭 wifi。

但是我不能在我的 ios 应用程序中使用它,或者不能在我的 xcode ui 测试中使用它。

我如何在 xcode ui 测试正在进行时关闭我的 wifi?

macos xcode ios xctest xcode-ui-testing

2
推荐指数
1
解决办法
2021
查看次数

UI 测试:当嵌套在表格视图单元格中时滑块无法调整

在UI测试上的Xcode 9.0(9A235),与之交互UISlideradjust(toNormalizedSliderPosition:)时不工作在所有UISlider嵌套在UITableViewCell

我已经在许多不同的场景中进行了测试: - Normal UISliders 没有嵌入到UITableView使用该adjust方法的工作中。-UISlider与 a 共存UITableView但不在 Table View Cell 内继续使用adjust -UISlider在 aUITableView中可以唯一标识。-UISlider在 a 中识别UITableView可以响应简单的事件,例如tap() -UISlider在 aUITableView中识别根本不适用于adjust方法,即使我将行数修改为 1。错误消息是:

获取元素 pid 的属性失败:24415,elementOrHash.elementID:106102876671744.43:错误域=XCTDaemonErrorDomain 代码=13“获取属性 5011 的值返回 AX 错误 -25205。” UserInfo={NSLocalizedDescription=获取属性 5011 的值返回 AX 错误 -25205。}

我在网上找到的相关讨论:https : //forums.developer.apple.com/thread/77445

如果有人有兴趣查看它,我也已将我的代码上传到网上

我已经就此向 …

tableview uislider ios swift xcode-ui-testing

2
推荐指数
1
解决办法
704
查看次数

如何根据测试用例失败或跳过或通过 xctest 框架触发另一个方法或任务

我正在使用 xctest 框架快速编写 UI 测试用例。

我想根据测试用例通过或失败或跳过触发另一个任务(例如截屏或)。我当前的代码如下

  import Foundation
  import XCTest

  class HomePageChromeUITests: XCTestCase {

var pathStr:String = ""
override func setUp() {

    super.setUp()
    continueAfterFailure = false
    self.launchWithUserLoggedIn()
}

override func tearDown() {
    super.tearDown()
}

func testHomePageChrome_10385() {
    let app = XCUIApplication()


    let backButton = app.buttons[AccessibilityIdentifiers.PageEditorBackButton]
    let editButton = app.buttons[AccessibilityIdentifiers.PageEditorEditButton]

    XCTAssertTrue(backButton.exists && backButton.frame.origin.x < editButton.frame.origin.x, "Back button does not exist.---10385")
    XCTAssertTrue(!editButton.exists, "Edit button does not exist.---10385")

 }
}
Run Code Online (Sandbox Code Playgroud)

我想在测试用例失败时触发一个方法,并在那里传递我的失败消息,即“10385”。

我怎样才能做到这一点。任何帮助,将不胜感激。

xctest swift xcode-ui-testing ios11 xcode9

2
推荐指数
1
解决办法
1080
查看次数

在 UITestCase 期间使用可访问性标识符识别 UISearchBar

我有一个UISearchBar在我的一个UIViewController。但UISearchBar默认情况下没有可访问性标识符,因此我尝试使用“用户定义运行时属性”来定义手动可访问性标识符。

在此处输入图片说明

但是在UITestCase编写过程中,我无法UISearchBar使用“用户定义运行时属性”访问或识别。但我无法使用标识符访问它。我总是不得不使用我不想使用的占位符文本,因为它在支持“多语言”时会导致问题。

我已经参考了有关此问题的堆栈溢出答案,但没有一个符合我的要求。

请帮助提供解决方案。谢谢你。

ios xcode-ui-testing

2
推荐指数
1
解决办法
1563
查看次数

处理位置服务警报的 UITest 案例

我正在为我的项目编写 UI 测试用例。

我的项目流程如下:

  • 登录屏幕。用户输入凭据并按登录。
  • 主屏幕。对于用户的许可,系统有位置要求。我允许。
  • 登出。

因此,当我全新安装应用程序时,此流程会记录在测试用例中,并且如果我在新的全新构建上执行,则该流程会起作用。

但问题是当我在旧版本上进行测试时,没有位置许可警报,并且测试失败。每次运行测试时,如何处理这种情况或请求用户许可?

为了重置用户的凭据,我将 launchArguments 传递给XCUIApplication()AppDelegate 并在其中处理。

我已经实现了代码让我知道它是否正确

addUIInterruptionMonitor(withDescription: "Allow “APP” to access your location?") { (alert) -> Bool in
            alert.buttons["Only While Using the App"].tap()

            return true
        }
Run Code Online (Sandbox Code Playgroud)

无论警报是否出现,上面的代码都适用于两者。

xcode ui-testing ios xctest xcode-ui-testing

2
推荐指数
1
解决办法
1159
查看次数

构建 Xcode UITest 失败,并显示“错误打开输入文件”

我在现有的 Xcode 项目中添加了一个 UITest 目标。

记录 UITest 工作正常。但是在构建期间运行相同记录的 UITest 失败并出现错误:

Compile Swift source files
Precompile bridging header
<unknown>:0: error: error opening input file '/Users/<...>/Bridging-Header.h' (No such file or directory)
Run Code Online (Sandbox Code Playgroud)

路径正确,文件存在于路径中。

  • 试图将文件添加到目标,但我无法将它添加到任何目标,因为复选框是灰色的。
  • 试图清理构建文件夹并删除派生数据文件夹,同样的问题。

有任何想法吗?

xcode ios xcode-ui-testing

2
推荐指数
1
解决办法
2862
查看次数

XCTest:有没有办法在 UI 测试中通过 ID 查找任何类型的视图?

在 XCTest 中,有一种方法可以按类型获取所有 UI 元素,然后按 AccessibilityIdentifier 进行过滤,例如:

app.buttons[someID]
Run Code Online (Sandbox Code Playgroud)

但是如果我不知道视图的类型怎么办?如果我正在寻找 UIView,我可以写:

app.otherElements[someID]
Run Code Online (Sandbox Code Playgroud)

但这不包括 UIButton 视图。

我可以通过连续调用所有方法(staticTexts、textViews、buttons、otherElements 等)来实现这一点,但有些东西告诉我它的性能不是很好,因为类型列表很大。

有没有通用的方法?

ios xctest xcode-ui-testing

2
推荐指数
1
解决办法
1227
查看次数