Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit recorded element in Xcode UI Testing

After recording a UI test, Xcode produces test code with the values it has recorded. In Xcode 9 some of these are highlighted in blue and don't appear to be editable:

Xcode UI test lines

I would like to be able to copy/paste/modify these values without manually retyping them. Is there a way to do this?

like image 958
Chris Garrett Avatar asked Jun 11 '26 08:06

Chris Garrett


1 Answers

I figured out a reasonable workaround for this, but if anyone knows an answer for editing these within Xcode that would still be preferred.

From Xcode, ctrl-click on the test file and choose "View in Finder"

Open the file with your favorite text editor that isn't Xcode.

UIRecording uses Swift inline comments to produce the uneditable elements. They look like this:

let userButton = app/*@START_MENU_TOKEN@*/.buttons["User"]/*[[".otherElements[\"PasscodeScreen\"].buttons[\"User\"]",".buttons[\"User\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/

You can manually remove those comments, and then then they become editable. Or, if you needed to just fix some text you could do that here as well.

You could also create a Regex in your text editor that could go through and remove all of them if you want. In my case though, I actually prefer the locked down ones because they give options for switching to different elements. So I only wanted to change and modify a few of them.

like image 171
Chris Garrett Avatar answered Jun 13 '26 22:06

Chris Garrett



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!