htmltestingautomated-testse2e-testingtestcafe

TestCafe - How to get the html output of an element on fail


When I run tests I cannot capture screenshots at the moment in Jenkins without some heavy work. What I would like to do is get the HTML output of the body to see what is displayed when a particular error occurs.

What I've already tried is getting the textContent, which is pretty close but I would like to get the stringified HTML if possible.

await t
    .click(something)
    .wait(1000)
    .click(somethingElse)
    .wait(1000)
    .expect(mySelector.exists)
    .ok(await Selector('body').textContent, { timeout: 25000 }); // if .ok fails it should print out the contents of body

I get the text but would want HTML.


Solution

  • Take a look at the Selector Custom Properties. There is an example of how to get innerHTML of the element.