SuffolkLITLab / ALKiln

Integrated automated end-to-end testing with docassemble, puppeteer, and cucumber.
https://assemblyline.suffolklitlab.org/docs/alkiln/intro
MIT License
14 stars 4 forks source link

Multiline text area value shows "\n" not actual new line #655

Open plocket opened 1 year ago

plocket commented 1 year ago

cucumberjs stringifies the value before passing it in to us. We can't JSON.parse() the value, because parsing \\n will cause an error ("hello\nworld" isn't a valid JSON value). We can simply replace \\n and \\r with \n and \r. It's not a complete unescape solution, but the more complete solution is problematic. For example, we could put it in an array first:

// `answer` is the string from cucumber
let unescaped_answer = JSON.parse(`["${ answer }"]`)[0];
handler.type( unescaped_answer );

It's just not particularly safe. If users do something like "hello\nworld\" they'll get an error that's completely useless while if we just deal with new lines ourselves, they shouldn't run into that problem. The problems they would run into would then be more visible and easier to fix than if we try to be clever about it.

imo, we should replace only escaped newline characters like \\n and \\r when we type into a textarea.

plocket commented 9 months ago

We might look into setting the value or pasting the text and then typing ' ' to make sure the user has interacted with the field. This would also speed up writing a lot of text in a textarea. Here's one example of setting the value, etc. There's a more recent one that may do a better job.