Perform specialised functionality on failure of a Scalatest

守給你的承諾、 提交于 2020-01-04 09:15:34

问题


I am using selenium to perform integration tests on a Scala web app. I would like to either screenshot or print the html of a page into the console whenever a test fails. My current set up is Scalatest using Selenium 2.0, with Spec.

Is there anyway to intercept a failure or determine the state of a test from a AfterEach override method?


回答1:


To do that you'll want to override withFixture instead of using BeforeAndAfterEach. BeforeAndAfterEach's beforeEach method happens before the test, and afterEach happens after the test. Whereas withFixture can do something at the start and/or end of the test. So when withFixture is invoked, the test has already started. After the test function returns to withFixture, the test has not yet completed. So you can catch an exception in withFixture to determine if the test has failed, and if so, create a screen shot.



来源:https://stackoverflow.com/questions/9464030/perform-specialised-functionality-on-failure-of-a-scalatest

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