在 Scalatest 失败时执行专门的功能

编程入门 行业动态 更新时间:2024-10-10 01:17:32
本文介绍了在 Scalatest 失败时执行专门的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 selenium 在 Scala Web 应用程序上执行集成测试.每当测试失败时,我想屏幕截图或将页面的 html 打印到控制台中.我目前的设置是使用 Selenium 2.0 和 Spec 的 Scalatest.

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.

无论如何都可以从 AfterEach 覆盖方法中拦截失败或确定测试的状态吗?

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

推荐答案

为此,您需要覆盖 withFixture 而不是使用 BeforeAndAfterEach.BeforeAndAfterEach 的 beforeEach 方法发生在测试之前,而 afterEach 发生在测试之后.而 withFixture 可以在测试开始和/或结束时做一些事情.所以当 withFixture 被调用时,测试已经开始了.测试函数返回withFixture后,测试还没有完成.因此,您可以在 withFixture 中捕获异常以确定测试是否失败,如果失败,则创建屏幕截图.

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.

更多推荐

在 Scalatest 失败时执行专门的功能

本文发布于:2023-11-25 06:30:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628682.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:功能   Scalatest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!