bex / behat-screenshot
Behat 扩展,用于帮助调试失败的场景
2.1.0
2020-04-07 17:03 UTC
Requires
- php: >=5.5
- behat/behat: ^3.0.0
- behat/mink-extension: ^2.0.0
- bex/behat-extension-driver-locator: ^1.0|^2.0
- symfony/filesystem: ^2.7|^3.0|^4.0|^5.0
- symfony/finder: ^2.7|^3.0|^4.0|^5.0
Requires (Dev)
- behat/mink-selenium2-driver: ^1.3.0
- bex/behat-screenshot-image-driver-dummy: ^1.0
- bex/behat-test-runner: ^1.3.1
- jakoch/phantomjs-installer: ^2.1.1-p07
- phpspec/phpspec: ^2.5
Suggests
- bex/behat-screenshot-image-driver-img42: Allows to upload the screenshot to img42.com
- bex/behat-screenshot-image-driver-unsee: Allows to upload the screenshot to unsee.cc
- bex/behat-screenshot-image-driver-uploadpie: Allows to upload the screenshot to uploadpie.com
README
Behat-ScreenshotExtension 通过截取失败步骤的屏幕截图来帮助您调试 Behat 场景。
默认情况下,扩展会截取屏幕截图并将其保存到预配置的目录中(默认情况下,它将保存到默认的临时系统目录)。
此外,扩展允许您指定一个图像驱动程序,该驱动程序可以将图像上传到主机,在这种情况下,您将在终端中看到图像 URL,紧随失败的步骤之后。有关可用的图像驱动程序的详细信息,请参阅下文。
您还可以轻松创建自己的图像驱动程序,有关更多信息,请参阅本部分。
安装
通过将其添加到您的 composer.json
中进行安装
composer require --dev bex/behat-screenshot
配置
在 behat.yml
中启用扩展,如下所示
default: extensions: Bex\Behat\ScreenshotExtension: ~
您可以通过以下方式配置屏幕截图目录
default: extensions: Bex\Behat\ScreenshotExtension: image_drivers: local: screenshot_directory: /your/desired/path/for/screenshots clear_screenshot_directory: true # Enable removing all images before each test run. It is false by default.
如果您使用的是其他图像驱动程序,您可以通过以下方式启用它
default: extensions: Bex\Behat\ScreenshotExtension: active_image_drivers: customdriver image_drivers: # this node and the driver subnodes are optional, if you remove it then the driver's default values will be used customdriver: #... custom driver config goes here ...
您甚至可以同时启用多个图像驱动程序
default: extensions: Bex\Behat\ScreenshotExtension: active_image_drivers: [local, customdriver] image_drivers: local: #... local driver config goes here ... customdriver: #... custom driver config goes here ...
您可以为包括之前步骤的联合截图
default: extensions: Bex\Behat\ScreenshotExtension: screenshot_taking_mode: failed_scenarios # Available modes: # - failed_steps: Image contains only the screenshot of the failed step. [Default] # - failed_scenarios: Image contains screenshots of all steps in a failed scenario. # - all_scenarios: Each scenario has a combined image created, regardless of failing or passing.
您可以通过从 behat.yml 中删除扩展来禁用它,或者您可以使用 enabled
参数禁用特定配置文件,例如
ci: extensions: Bex\Behat\ScreenshotExtension: enabled: false
用法
当您运行 behat 并且一个步骤失败时,扩展将自动截取屏幕截图,您将看到屏幕截图的文件路径或图像 URL(基于配置的图像驱动程序)。所以您将看到类似以下的内容
Scenario: # features/feature.feature:2 Given I have a step # FeatureContext::passingStep() When I have a failing step # FeatureContext::failingStep() Error (Exception) Screenshot has been taken. Open image at /tmp/behat-screenshot/i_have_a_failing_step.png Then I should have a skipped step # FeatureContext::skippedStep()
可用的图像驱动程序
- bex/behat-screenshot-image-driver-uploadpie
- bex/behat-screenshot-image-driver-img42
- bex/behat-screenshot-image-driver-unsee
如何创建您自己的图像驱动程序
- 实现
Bex\Behat\ScreenshotExtension\Driver\ImageDriverInterface
- 将您的类放在
Bex\Behat\ScreenshotExtension\Driver
命名空间下
就是这样!
请参阅以下示例: https://github.com/tkotosz/behat-screenshot-image-driver-dummy