Javascript 如何在CasperJS中的特定断言失败时捕获屏幕截图?

Javascript 如何在CasperJS中的特定断言失败时捕获屏幕截图?,javascript,casperjs,Javascript,Casperjs,当特定的断言失败时,是否可以捕获屏幕截图? 我在文档和论坛中看到,当测试失败时,可以执行全局过程,如下所示: casper.test.on("fail", function (failure) { // Do something, "casper.capture" for example }); 但是我希望每个断言都有一个特定的过程。我的意思是: test.assertTitle(...) // if it fails, do this test.assertMatch(...) // i

当特定的
断言失败时,是否可以捕获屏幕截图?
我在文档和论坛中看到,当测试失败时,可以执行全局过程,如下所示:

casper.test.on("fail", function (failure) {
  // Do something, "casper.capture" for example
});
但是我希望每个
断言都有一个特定的过程。我的意思是:

test.assertTitle(...) // if it fails, do this
test.assertMatch(...) // if it fails, do that
...

可能吗?我该怎么做呢?

在谷歌/论坛/代码搜索之后,我发现它=)

try{
  test.assertxxx(...)
} catch (e) {
  casper.fail("It's a fail!");
}