swift - 如何使用 XCTAssert 断言复制和粘贴行的内容
问题描述
我在做什么。
- 我正在创建一个段落块/行
- 用随机文本填充该行
- 使用内置
copy
和paste
块功能复制和粘贴该行 - 然后尝试断言新粘贴的行以检查它是否与文本的第一个块中的文本匹配
目前我如何断言,但失败了:
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
被调用的那一步失败了。
解决方案
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 }
推荐阅读
- excel - 用VB.net打开Excel Office365 Doc
- java - 如果两个商店具有相同的 ID 并且他们希望与 Corp 同步,SymmetricDs 如何处理 ID 冲突
- youtube-api - 如何获取我订阅的频道的 ID?
- django - 如何在 django ORM 的 WHERE 子句上使用 CASE 语句进行查询?
- c - 如何使用指针填写 C 中的结构数组?
- python-3.x - 节 SSLError: HTTPSConnectionPool(host='raw.githubusercontent.com', port=443)
- php - 二维数组在 laravel 中没有循环
- excel - 如何使用 COUNTIF 计算日期范围之间的特定文本?
- kdb - kdb:避免在字符串中转义双引号
- python - 层的输入与预期输入的层不兼容