Search code examples
javascriptautomationautomated-testse2e-testingtestcafe

Unescape JSON data values to assert


in working with Data Driven files, I setup the json file to included escaped characters

 {
...
        "emailbodyHTML":"Hi [[Contact First Name]],\r\n\r\nToday is a nice day.\r\n\r\nThanks!",

...
    },

In my test

dataSet.forEach(userdata => {
  test(`Enter '${userdata.testcasename}'`, async t => {  
....

     await t.expect(messagingDetailsPage.emailBodyHTML.value).eql(userdata.emailbodyHTML,"Email Body in HTML Match Not Found")

...

}

I am presuming for the assertion to work - there is some kind of reverse unescaping I have to do? Any pointers would be helpful.


Solution

  • I realized that JSON test files cannot have uppercase chars hence this was failing. once I changed it to read like this:

    "emailbodyhtml": "<p>Hi [[Contact First Name]],</p><p>Today could be a coincidental peak day and there is a high probability a Demand Response event will be scheduled this afternoon.</p><p>Thanks!</p>",
    

    My Test

    await t.expect(messagingDetailsPage.emailBodyHTML.innerText).eql(userdata.emailbodyhtml,"Email Body in HTML Match Not Found")
    

    Resolved the issue.