TestCafe - 如何在失败时获取元素的 html 输出

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

当我 运行 测试时,如果不做一些繁重的工作,我目前无法在 Jenkins 中捕获屏幕截图。我想做的是获取正文的 HTML 输出,以查看发生特定错误时显示的内容。

我已经尝试过获取 textContent,这非常接近,但如果可能的话,我想获取字符串化的 HTML。

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

我收到了文本,但想要 HTML。

看看Selector Custom Properties。有一个如何获取元素的 innerHTML 的例子。