elvetemedve / behat-screenshot Goto Github PK
View Code? Open in Web Editor NEWThis is an extension for Behat which provides debugging functionality by taking a screenshot of failed tests.
License: MIT License
This is an extension for Behat which provides debugging functionality by taking a screenshot of failed tests.
License: MIT License
Taking the following behat.yml
the screenshots will be saved into Drupal's root dir (drupal_root: ../../web
) as directory named %paths.base%/screenshots/failed_steps
.
So it seems that screenshot_directory
currently can only be an absolute path or a relative path to the target projects's web root. But it MUST also be possible to use %paths.base%
to make it relative to the current behat.yml
.
default:
suites:
default:
contexts:
- FeatureContext
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
extensions:
Behat\MinkExtension:
base_url: http://drupal.localhost
goutte: ~
selenium2:
wd_host: http:/drupal.localhost:4444/wd/hub
capabilities:
marionette: true
browser: chrome
browser_name: chrome
Drupal\DrupalExtension:
blackbox: ~
api_driver: drupal
drupal:
drupal_root: %paths.base%/../../web
Bex\Behat\ScreenshotExtension:
screenshot_taking_mode: failed_steps
image_drivers:
local:
screenshot_directory: %paths.base%/screenshots/failed_steps
Hi guys, I was wondering whether the extension behaviour explained below is expected or not.
I have a successful Scenario Outline
step that gets executed, but it looks like an attempt to take a screenshot is made:
| zh-Hant-CN |
Screenshots are not supported by Behat\Mink\Driver\GoutteDriver
The extension configuration is as follows:
extensions:
Bex\Behat\ScreenshotExtension:
image_drivers:
local:
screenshot_directory: ./
screenshot_taking_mode: failed_scenarios
Shouldn't the message appear only when a failed scenario occurs?
Hi!
This is a great Behat extension, but currently it does not support Symfony 5 - are there plans to add support for it?
The current composer.json contains:
"symfony/filesystem": "^2.7|^3.0|^4.0",
"symfony/finder": "^2.7|^3.0|^4.0"
"behat/mink-extension": "^2.0.0",
which are not Symfony 5 compatible - would you be interesed in a PR that bumps these dependencies/upgrades code if needed?
I know that the Behat MinkExtension does not support Symfony 5, but there is a fork for that: https://github.com/FriendsOfBehat/MinkExtension which can be used.
Currently no screenshots are taken for a Scenario Outline.
I'll provide a pull request for this.
This code https://github.com/elvetemedve/behat-screenshot/pull/59/files#diff-367a0438232ae30182922c4e9618bd66be531f661c4e57d09b710749010b7fb9R6 is causing issues and the Pretty formatter
or Progress formatter
are not working.
I started to work on a fix #62
Trying to find my path to screenshots in Behat tests one thing is still unclear to me:
To make use of this pretty nice tool (❤️) we need a JavaScript session with for example Selenium or PhantomJS, yes?
As we need a browser in the first place, is this right?
For example I have the following behat.yml
were screenshots are only taken for @javascript
tagged scenarios. And I guess that's how it's supposed to work, yes?
default:
suites:
default:
contexts:
- FeatureContext
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
extensions:
Behat\MinkExtension:
base_url: http://foobar.localhost
goutte: ~
selenium2: ~
Drupal\DrupalExtension:
blackbox: ~
Bex\Behat\ScreenshotExtension:
screenshot_taking_mode: all_scenarios
image_drivers:
local:
screenshot_directory: /tmp/screenshots
Great extension, just what I wanted, but is there any way to capture the full contents of the browser window, not just the visible viewport?
This is a tricky problem because the browser driver is only going to render and deliver the viewport, so the only way to really do this is to cause the browser to scroll through the page and capture viewport-sized chunks of them (plus the remainder) and stitch them together into the final image. Do you have any intention of doing this, or perhaps accepting a PR that does this?
It involves javascript injection black magic. But it can work...
Hi!
Adding a if (!$driver instanceof Selenium2Driver) { return }
could prevent this extension to try to create screenshot while using the Symfony2 driver, for example.
Thx !
I just noticed that – if you annotate a method with @beforeStep
in your FeatureContext extends MinkContext
and you're using behat-screenshot – behat-screenshot complains about a null parameter, when starting bin/behat:
[Behat\Testwork\Call\Exception\CallErrorException]
Warning: end() expects parameter 1 to be array, null given in {projectRoot}\vendor\bex\behat-screenshot\src\Bex\Behat\ScreenshotExtension\Service\ScreenshotTaker.php line 91
behat [-s|--suite SUITE] [-f|--format FORMAT] [-o|--out OUT] [--format-settings
FORMAT-SETTINGS] [--init] [--lang LANG] [--name NAME] [--tags TAGS] [--role ROLE
] [--story-syntax] [-d|--definitions DEFINITIONS] [--append-snippets] [--no-snip
pets] [--strict] [--order ORDER] [--rerun] [--stop-on-failure] [--dry-run] [--]
[<paths>]
I originally wanted to initiate a debug-session for behat with that method. But even an empty method causes this error:
in features/bootstrap/FeatureConetxt.php
:
/**
* @beforeStep
*
* @param BeforeStepScope $scope
*/
public function synchronizeClientSession(BeforeStepScope $scope)
{
}
As soon as I remove the annotation @beforeStep
everything works again – no complaints.
https://github.com/dutchiexl/BehatHtmlFormatterPlugin expects screenshots to be put in a certain directory with a certain filename, then it will integrate them into its HTML report. It would be nice if the behat-screenshot extension would support this naming pattern. It might be feasible by just switching to another implementation for FilenameGenerator.
After requiring via composer
then adding the extension using screenshot_taking_mode: failed_scenarios
with the local
image driver, I got the following error on the first run:
Invalid configuration for path "testwork.screenshot.screenshot_taking_mode": Imagemagick PHP extension is required,
but not installed.
It doesn't seem this dependency was highlighted by Composer during install time... can the Imagemagick requirement be added to the composer.json
requirements? https://github.com/elvetemedve/behat-screenshot/blob/master/composer.json#L23-L30
I have this settings:
extensions:
Behat\MinkExtension:
browser_name: 'chrome'
goutte: ~
selenium2:
wd_host: 'http://localhost:4444/wd/hub'
browser: 'chrome'
capabilities:
browser: 'chrome'
chrome:
switches:
- "--headless"
- "--disable-gpu"
javascript_session: 'selenium2'
base-url: 'http://localhost:8080/my-site'
files_path: '/home/user/environment/my-site'
Drupal\DrupalExtension:
api_driver: 'drupal'
blackbox: ~
drupal:
drupal_root: '/home/user/environment/my-site'
selectors:
message_selector: '.messages'
error_message_selector: '.messages.error'
success_message_selector: '.messages.status'
subcontexts:
paths:
- '/home/user/environment/my-site/sites/default'
drush:
alias: 'default'
binary: '/home/user/environment/my-site/vendor/package/toolkit/bin/drush'
region_map:
header: "#layout-header"
featured: ".region-featured-wrapper"
content_top: ".content-top"
content: "#content-wrapper"
left sidebar: "#sidebar-left"
right sidebar: "#sidebar-right"
footer: "#layout-footer"
Bex\Behat\ScreenshotExtension:
screenshot_taking_mode: failed_scenarios
image_drivers:
local:
screenshot_directory: '/home/user/environment/my-site/tests/screenshots'
clear_screenshot_directory: true
formatters:
pretty: ~
And I noticed it only creates screenshots from the failed scenarios if the scenario is annotated as a javascript scenario. It's not possible to create screenshot if it's not annotated like that? And some why on the screenshot I can see only the text without css... But form the browser it works...
Hi guys,
I was trying to composer require --dev bex/behat-screenshot:1.2.2
today but then I started getting this:
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package elvetemedve/behat-screenshot could not be found in any version, there may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Installation failed, reverting ./composer.json to its original content.
Does it need changing on packagist or something?
Thanks!
How do I capture a screenshot on demand? I have it working on error.
Are there plans to add Symfony 6 support?
Hello,
I'm working on a behat project where i'd like to separate test suites on my jenkins instance into different jobs. To avoid jobB erasing screenshots from jobB I thought that it will be nice to add the possibility of extending screenshot repository defined in .yml file. That way my jobs will generate their screenshots in their own folder rather than using the one in .yml.
I'd like to have you opinion on it, and if you're thinking it's a good idea, I'd be glad to work on that and submit a PR.
Best regards
I really like this extension. The problem is that as the tests run the extension keeps adding screenshots to the array of screenshots (in ScreenshotTaker->takeScreenshot() which in itself is a memory leak.
With this extension disabled we don't run into memory leaks:
PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 8912975 bytes) in [...]
My config:
default:
extensions:
Bex\Behat\ScreenshotExtension:
image_drivers:
local:
screenshot_directory: '/var/www/project/tests/failures'
Test ouput:
alExtension\Context\MinkContext::assertTextVisible()
And I should see the text "The requested product Test Product is currently not available for this country" # Drupal\DrupalExtension\Context\MinkContext::assertTextVisible()
The text "The requested product Test Product is currently not available for this country" was not found anywhere in the text of the current page. (Behat\Mink\Exception\ResponseTextException)
--- Failed scenarios:
features/product.feature:12
1 scenario (1 failed)
7 steps (6 passed, 1 failed)
No message, no screenshot.
What am I doing wrong? behat version 3.0.15
the extension is not working this is what my composer file looks like
{ "name": "project", "description": "", "type": "project", "license": "MIT", "authors": [ { "name": "PROJECT", "role": "Dev team" } ], "require": { "behat/mink": "*", "behat/mink-goutte-driver": "~1.2", "jcalderonzumba/gastonjs": "~1.0.2", "jcalderonzumba/mink-phantomjs-driver": "~0.3.1", "phpunit/phpunit": "4.8.*", "symfony/css-selector": "~2.8", "bex/behat-screenshot": "1.2.*" }, "minimum-stability": "dev", "prefer-stable": true }
behat.yml file
default: suites: default: contexts: - FeatureContext extensions: Behat\MinkExtension: goutte: ~ selenium2: ~ base_url: http://mysite.com Bex\Behat\ScreenshotExtension: image_drivers: local: screenshot_directory: '/var/www/behat/results/screenshot' test: suites: default: filters: tags: "@test"
Can you let me know what am i missing .
Replace behat/mink-extension
with friends-of-behat/mink-extension
for PHP 8.x support.
Background
We use Behat Cucumber Json Formatter to send the test results to Cucumber Jenkins
Currently, it is not possible to attach screenshots to the reports.
This functionality is also mentioned here cawolf/behat-cucumber-formatter#10
Proposal
Trigger an event when files are uploaded, to allow Cucumber Formatter to subscribe to the event and attach the image Url to the json output.
I have this settings:
behat.yml:
default:
suites:
default:
contexts:
- FeatureContext
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
extensions:
Behat\MinkExtension:
javascript_session: selenium2
base_url: http://somesite.dd:8083
#goutte: ~
selenium2:
browser: firefox
wd_host: http://localhost:4444/wd/hub
Drupal\DrupalExtension:
blackbox: ~
Bex\Behat\ScreenshotExtension:
image_drivers:
local:
screenshot_directory: screenshots
clear_screenshot_directory: true # Enable removing all images before each test run. It is false by default.
composer.json:
{
"name": "drupal-composer/drupal-project",
"description": "Project template for Drupal 8 projects with composer",
"type": "project",
"license": "GPL-2.0+",
"authors": [
{
"name": "",
"role": ""
}
],
"repositories": {
"drupal": {
"type": "composer",
"url": "https://packages.drupal.org/8"
},
"leaflet": {
"type": "package",
"package": {
"name": "leaflet/leaflet",
"version": "v0.7.7",
"type": "drupal-library",
"dist": {
"url": "https://github.com/Leaflet/Leaflet/archive/v0.7.7.zip",
"type": "zip"
}
}
}
},
"require": {
"composer/installers": "^1.2",
"drupal-composer/drupal-scaffold": "^2.2",
"cweagans/composer-patches": "~1.0",
"drupal/core": "~8.0",
"drush/drush": "~8.0",
"drupal/console": "~1.0",
"drupal/paragraphs": "^1.0",
"drupal/admin_toolbar": "^1.18",
"drupal/addtoany": "^1.7",
"drupal/pathauto": "^1.0@beta",
"drupal/imagemagick": "^1.0@alpha",
"drupal/tvi": "^1.0@beta",
"drupal/google_analytics": "^2.1",
"drupal/webform": "5.0-beta7",
"drupal/parade": "2.x-dev",
"drupal/drupal-extension": "^3.3"
},
"require-dev": {
"behat/mink": "~1.7",
"behat/mink-goutte-driver": "~1.2",
"jcalderonzumba/gastonjs": "~1.0.2",
"jcalderonzumba/mink-phantomjs-driver": "~0.3.1",
"mikey179/vfsStream": "~1.2",
"phpunit/phpunit": "~4.8",
"symfony/css-selector": "~2.8",
"drupal/devel": "1.x-dev",
"bex/behat-screenshot": "^1.2",
"behat/mink-selenium2-driver": "^1.3",
"phpspec/phpspec": "^3.4",
"bex/behat-test-runner": "^1.2",
"jakoch/phantomjs-installer": "^2.1"
},
"conflict": {
"drupal/drupal": "*"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"classmap": [
"scripts/composer/ScriptHandler.php"
]
},
"scripts": {
"drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
"pre-install-cmd": [
"DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
],
"pre-update-cmd": [
"DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
],
"post-install-cmd": [
"DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
],
"post-update-cmd": [
"DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
]
},
"extra": {
"installer-paths": {
"web/core": ["type:drupal-core"],
"web/libraries/{$name}": ["type:drupal-library"],
"web/modules/contrib/{$name}": ["type:drupal-module"],
"web/profiles/contrib/{$name}": ["type:drupal-profile"],
"web/themes/contrib/{$name}": ["type:drupal-theme"],
"drush/contrib/{$name}": ["type:drupal-drush"]
}
}
}
And my problem is, when I add 'goutte: ~' on selenium2 level, my test works well, but it doesn't generate any image. If I remove that line, I get a 0b image, but all my tests fails (those too, which needs to be passed and passed with 'goutte: ~'). How do I need to use this?
Given
"bex/behat-screenshot": "^1.2"
php_fileinfo
installed (php.ini)When
bin\behat
Then an error will be thrown:
PHP Fatal error: Uncaught Error: Class 'finfo' not found in {project-root}\vendor\bex\behat-screenshot\src\Bex\Behat\ScreenshotExtens
ion\Driver\Local.php:48
Stack trace:
#0 {project-root}\vendor\bex\behat-extension-driver-lo
cator\src\Bex\Behat\ExtensionDriverLocator\DriverLocator.php(98): Bex\Behat\Scre
enshotExtension\Driver\Local->__construct()
#1 {project-root}\vendor\bex\behat-extension-driver-lo
cator\src\Bex\Behat\ExtensionDriverLocator\DriverLocator.php(54): Bex\Behat\Exte
nsionDriverLocator\DriverLocator->createDrivers(Array)
#2 {project-root}\vendor\bex\behat-screenshot\src\Bex\
Behat\ScreenshotExtension\ServiceContainer\Config.php(119): Bex\Behat\ExtensionD
riverLocator\DriverLocator->findDrivers(Object(Symfony\Component\DependencyInjec
tion\ContainerBuilder), Array, Array)
#3 {project-root}\vendor\bex\behat-screenshot\src\Bex\
Behat\ScreenshotExtension\ServiceContainer\ScreenshotExtension.php(8 in {project-root}\vendor\bex\behat-screenshot\src\Bex\Behat\Scree
nshotExtension\Driver\Local.php on line 48
I suggest that you either work around the finfo requirement or you declare the requirement in composer.json
:
"require": {
"php": ">=5.4",
"behat/behat": "^3.0.0",
"behat/mink-extension": "^2.0.0",
"bex/behat-extension-driver-locator": "^1.0.2",
"symfony/filesystem": "^2.7|^3.0",
"symfony/finder": "^2.7|^3.0",
"ext-Fileinfo": "*"
},
I'll post a pull request with the patch in a moment.
Currently screenshots are only taken in JavaScript sessions. Let's add a fallback similar to what integratedexperts/behat-screenshot
does, where as fallback an HTML file gets generated using the Goutte driver.
Remaining tasks:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.