How do you prevent the tests from stopping on the first failed test case?

谁说我不能喝 提交于 2019-12-11 03:38:01

问题


I'm attempting to check if certain pieces of content are present, on different pages. For example:

const contentCount = Selector('.some-element').childElementCount

.expect(contentCount).gte(1, 'The related content is missing.')

... Which works fine, except that the testing stops after the first assertion fails. This isn't ideal as I'm trying to generate a report that shows ALL of the failed assertions at once.

How do I get the test to keep running after a failed assertion?


回答1:


Answering your question from the subject first (how to prevent the test from stopping on the first failed test case).

TestCafe will run all tests even if one of them failed. You might want to split your single test case with multiple assertions into multiple test cases with a single assertion per test to obtain a proper report.

Now, answering your question from the body (how to keep running after a failed assertion).

At the moment, there is no way to skip a failed assertion during the test execution. TestCafe considers that something went wrong if an assertion failed, so the entire test fails. However, if you don't want an assertion to fail a test, you may add a condition for it; e.g.:

if (contentCount > 0)
  await t.expect(contentCount).gte(1, 'The related content is missing.')

But, this does not look like straight and predictable test logic. So, I would choose splitting a test into multiple tests with one assertion per test.



来源:https://stackoverflow.com/questions/52614503/how-do-you-prevent-the-tests-from-stopping-on-the-first-failed-test-case

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