Ios accessibilityIdentifier的良好命名约定?-XCode 7 UI测试-录制

Ios accessibilityIdentifier的良好命名约定?-XCode 7 UI测试-录制,ios,xcode,xcode-ui-testing,Ios,Xcode,Xcode Ui Testing,是否有可访问性标识符的命名约定(与Xcode UI测试记录相关) 我正在研究可访问性和UI测试。我在Xcode 7中使用了新的录制功能。在录制UI操作时,我注意到: 当我有一个标记为“a”的按钮并记录了两次轻触时,我得到以下代码: XCUIElement *aButton = [[XCUIApplication alloc] init].buttons[@"a"]; [aButton tap]; [aButton tap]; XCUIElement *1Button = [[XCUIAppli

是否有可访问性标识符的命名约定(与Xcode UI测试记录相关)

我正在研究可访问性和UI测试。我在Xcode 7中使用了新的录制功能。在录制UI操作时,我注意到:

当我有一个标记为“a”的按钮并记录了两次轻触时,我得到以下代码:

XCUIElement *aButton = [[XCUIApplication alloc] init].buttons[@"a"];
[aButton tap];
[aButton tap];
XCUIElement *1Button = [[XCUIApplication alloc] init].buttons[@"@1"];
[1Button tap];
[1Button tap];
XCUIElement *button = [[XCUIApplication alloc] init].buttons[@"1"];
[button tap];
[button tap];
当我将其accessibilityIdentifier设置为“a”并重复录制时,我得到了相同的代码

本地化标签会干扰可访问性标识符吗?(如果在某些语言中,按钮X突然以“a”作为标签,而按钮Y以“a”作为可访问性标识符,这是否会产生歧义/冲突?)

我的第一个想法是为可访问性标识符提供一个唯一的前缀,比如“@”。所以我试了一下“@a”,“@1”等等

但是,使用“@1”记录会导致以下代码:

XCUIElement *aButton = [[XCUIApplication alloc] init].buttons[@"a"];
[aButton tap];
[aButton tap];
XCUIElement *1Button = [[XCUIApplication alloc] init].buttons[@"@1"];
[1Button tap];
[1Button tap];
XCUIElement *button = [[XCUIApplication alloc] init].buttons[@"1"];
[button tap];
[button tap];
这会产生编译器错误,因为
1按钮
不是有效的标识符。显然,可访问性标识符在按钮的变量名前面加了一些字符

使用“1”时,记录将导致以下代码:

XCUIElement *aButton = [[XCUIApplication alloc] init].buttons[@"a"];
[aButton tap];
[aButton tap];
XCUIElement *1Button = [[XCUIApplication alloc] init].buttons[@"@1"];
[1Button tap];
[1Button tap];
XCUIElement *button = [[XCUIApplication alloc] init].buttons[@"1"];
[button tap];
[button tap];
这引出了另一个问题:

我可以影响Xcode在录制期间如何派生变量名吗


我知道,我可以手动录制和清理变量名。但是,如果可以在某个地方轻松配置,那就太傻了。

您可以通过测试这个案例来回答第一个问题,不是吗?可能会比写这部分问题花费更少的时间。至于你的第二个问题,我喜欢从开发人员的角度考虑这些工具,在这种情况下,我不明白为什么他们会实现这样的东西。@A-Live好吧,开发人员发现了ID是数字的情况。它们去除特殊字符,因此变量不会命名为
@button
。作为一名开发人员,我更进一步地处理了像
@1
这样的ID。它看起来就像在特殊字符剥离之后而不是之前应用数字检查一样简单。(像Xcode这样的大型工具从来都不容易,所以这可能不像看上去那么容易。)考虑到苹果建议用户多走一英里,我也希望在这里。所以我想知道是否有一些大师比我更了解它:-)上次我用Apple devs技术支持询问苹果时,他们不得不推荐使用并提交一个“增强”问题,你可能想这样做。