Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift UITesting error: Invalid escape sequence in literal. \U201c

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?

like image 251
Charlie Seligman Avatar asked Sep 22 '15 08:09

Charlie Seligman


1 Answers

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).

like image 62
Martin R Avatar answered Oct 19 '22 03:10

Martin R