首页 > 解决方案 > 如何使用 XCTAssert 断言复制和粘贴行的内容

问题描述

我在做什么。

  1. 我正在创建一个段落块/行
  2. 用随机文本填充该行
  3. 使用内置copypaste块功能复制和粘贴该行
  4. 然后尝试断言新粘贴的行以检查它是否与文本的第一个块中的文本匹配

目前我如何断言,但失败了:

func confirmPastedParagraphBlock() -> BlockEditorScreen {
    XCTAssert(pastedBlockView.isEqual(copiedBlockView))

    return self
}

我还使用以下对象:

let copiedBlockView = XCUIApplication().otherElements["Paragraph Block. Row 1."]
let pastedBlockView = XCUIApplication().otherElements["Paragraph Block. Row 2."]

我知道我想如何断言,但只是不确定我哪里出错了——它在confirmPastedParagraphBlock被调用的那一步失败了。

标签: swiftassertxctestassertionxcuitest

解决方案


XCUIApplication().otherElements["Paragraph Block. Row 1."]返回一个 XCUIElement。

您要断言的是这些元素的内容。

如果您调查一下,XCUIElementAttributes您可以使用一些属性。

 /** The raw value attribute of the element. Depending on the element, the actual type can vary. */
    var value: Any? { get }

    /** The title attribute of the element. */
    var title: String { get }

    /** The label attribute of the element. */
    var label: String { get }

推荐阅读