ios - UI 测试 Xcode 中的 128 个字符限制
<p><p>这个测试失败是因为</p>
<blockquote>
<p>exceeds maximum length of 128 characters. You can work around this
limitation by constructing a query with a custom NSPredicate that
specifies the property (label, title, value, placeholderValue, or
identifier) to match against.'</p>
</blockquote>
<pre><code>func testMessage() {
app.buttons["BEGIN"].tap()
let tablesQuery = app.tables
XCTAssert(tablesQuery.children(matching: .cell).element(boundBy: 0).staticTexts["<EXTREMELY LONG TEXT HERE (200chars)>"].exists)
}
</code></pre>
<p>如何转换它,以便在测试文本有效性时绕过 128 个字符的限制。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您可以使用 <code>label LIKE</code> 作为完整字符串:</p>
<pre><code>let yourSuperLongText = "your super long string"
let predicate = NSPredicate(format: "label LIKE %@", yourSuperLongText)
let element = tablesQuery.children(matching: .cell).element(boundBy: 0).staticTexts.element(matching: predicate)
XCTAssert(element.exists)
</code></pre>
<p>或者您可以将 <code>label CONTAINS</code> 用于部分字符串:</p>
<pre><code> let partOfYoursSuperLongText = "part of your super long string"
let predicate = NSPredicate(format: "label CONTAINS %@", partOfYoursSuperLongText)
let element = tablesQuery.children(matching: .cell).element(boundBy: 0).staticTexts.element(matching: predicate)
XCTAssert(element.exists)
</code></pre>
<p>更多:
<a href="https://stackoverflow.com/questions/38044374/how-to-test-that-statictexts-contains-a-string-using-xctest" rel="noreferrer noopener nofollow">How to test that staticTexts contains a string using XCTest</a> </p>
<p>这里:<a href="https://developer.apple.com/documentation/foundation/nspredicate" rel="noreferrer noopener nofollow">https://developer.apple.com/documentation/foundation/nspredicate</a> </p></p>
<p style="font-size: 20px;">关于ios - UI 测试 Xcode 中的 128 个字符限制,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/53501517/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/53501517/
</a>
</p>
页:
[1]