9

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?

Senseful
  • 86,719
  • 67
  • 308
  • 465
Charlie S
  • 4,366
  • 6
  • 59
  • 97
  • This seems to be an Xcode bug when generating code during UI testing, compare http://stackoverflow.com/questions/32432068/incomplete-universal-character-name-in-ui-testing for a similar issue. – Martin R Sep 22 '15 at 09:02
  • Note: The problem here is *not* that OP does not know how to escape unicode characters in strings. This is code *created by Xcode* during UI test recording. – Martin R Sep 22 '15 at 09:04
  • That is correct. This is an Xcode bug when generating code. Any ideas what the code created 'should' be as per the question? – Charlie S Sep 22 '15 at 09:33

2 Answers2

14

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

Community
  • 1
  • 1
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • Its very weird as your quotes match perfectly what is on screen, but even though the UIAlertView is displayed I am getting a false boolean returned by the query: return app.alerts["Allow “Light Alarm” to access your location while you use the app?"].exists – Charlie S Sep 22 '15 at 14:05
  • @CharlieSeligman: You would have to use `app.alerts["Allow “Light Alarm“ ..."]`. – My remark *"Actually it should be ..."* was only meant as a gentle reminder that there are two different (right and left) quotation marks. Your code uses the left double quotation mark only. – Martin R Sep 23 '15 at 16:21
  • Does this mean adding tags to the views or is it enough to convert the Unicode value inserted by Swift? – IIllIIll Jan 06 '16 at 20:34
  • Any one got a work around for this? Although when I look at the xcode debugger console, the string is displayed as expected but fails when I call .exists method? – seleniumlover Feb 04 '16 at 23:03
  • @seleniumlover see my answer below, try to install new version of Xcode – Anton Gaenko Mar 29 '16 at 19:27
0

Installing Xcode 7.3 fixed this issue for me

Anton Gaenko
  • 8,929
  • 6
  • 44
  • 39