Executing a task after all test are launch cypress

冷暖自知 提交于 2020-04-11 04:30:28

问题


I need to execute some code after all tests run. I add this test on after hook. But this task needs the report to be created, but on after hook, the report is not created yet.

I also tried to use

 on('run:end', () => {
        console.log("gdfgfdsafkañjsdfjñaldfkjsñkasfdñlassfjdskafmjassd");
  });

but it does nothing.


回答1:


You can't, there is an open issue for that.

At the moment you can only leverage a package.json post hook. So, if you have a dedicated command in your package.json file

"scripts": {
  "cy:run": "cypress run"
}

you can add a postcy:run script

"scripts": {
  "cy:run": "cypress run",
  "postcy:run": "<YOUR_COMMAND>"
}

I hope it helps you 😊




回答2:


Be aware that the post hook might not run when the tests fail. I'm currently using a global after hook in support/index.ts for running after all tests

I'm currently using a global after hook in support/index.ts

after(() => {
  // something here
});


来源:https://stackoverflow.com/questions/56006940/executing-a-task-after-all-test-are-launch-cypress

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!