Swift UITesting错误:文字中的转义序列无效。 \U201c [英] Swift UITesting error: Invalid escape sequence in literal. \U201c
问题描述
我的应用程序加载了以下警报视图:
允许Light Alarm访问您的位置,而使用应用程序?
当我使用UI测试记录并单击此警报时,我会得到以下代码:
app.alerts [允许\U201cLight Alarm\\ \\ u201c在使用应用程序时访问您的位置?]
注意:引号已被替换为\U201c
但是,当我尝试编译我得到以下错误:
无效的转义序列在文字
任何人都知道如何得到这个?
在UI记录中生成代码时,这似乎是Xcode中的一个错误。
Swift在字符串文字中使用 \u {NNNN}
转义序列,所以
app.alerts [允许\ {201c} Light Alarm\u {201c} ...]
是正确的,或者简单地
app.alerts [允许Light Alarm ...]
(实际上应该是允许 ...
其中
第二个引号是U + 201D = RIGHT DOUBLE QUOTATION MARK:)
类似的问题在Objective-C中的UI记录代码以
报告不完整的通用字符UI测试中的名称。
我不知道解决方法,目前您唯一可以做的
似乎是修复录制后的代码(并向苹果发送了一个错误报告
)。
I am building an automation suite using Xcode 7 with swift.
My app loads with the following Alert View:
Allow "Light Alarm" to access your location while you use the app?
When I record with UI Testing and click this alert I get the following code: app.alerts["Allow \U201cLight Alarm\U201c to access your location while you use the app?"]
Note: The quotes has been replaced with \U201c
However, when I try and compile I get the following error: "Invalid escape sequence in literal"
Anyone know how to get round this?
This seems to be a bug in Xcode when generating code during UI recording.
Swift uses \u{NNNN}
escape sequences in string literals, so
app.alerts["Allow \u{201c}Light Alarm\u{201c} ..."]
would be correct, or simply
app.alerts["Allow "Light Alarm" ..."]
(Actually it should be "Allow "Light Alarm" ..."
where the
second quotation mark is U+201D = RIGHT DOUBLE QUOTATION MARK :)
A similar issue for UI recorded code in Objective-C was reported in Incomplete universal character name in UI Testing.
I do not know a workaround, it seems that the only thing you can do at present is to fix the code after recording (and sent a bug report to Apple).
这篇关于Swift UITesting错误:文字中的转义序列无效。 \U201c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!