字符串掩码元素名称 UITests

String mask element name UITests

我的屏幕上显示如下文字:

@"New element #13"

如何对其进行通用测试并通过掩码到达该元素?

[[[XCUIApplication alloc] init].buttons[@"New element #**"] tap];

听起来您正在尝试通过正则表达式匹配文本。

XCUIApplication *app = [[XCUIApplication alloc] init];
NSString *format = "label BEGINSWITH 'New element #'";
NSPredicate *predicate = [[NSPredicate alloc] initWithFormat:format];
XCUIElement *element = [app.buttons elementMatchingPredicate:predicate];
[element tap];

请注意,如果有多个按钮与谓词匹配 Xcode 可能会引发异常。

您可以在 my post on UI Testing 中找到 Swift 示例(和工作应用)。