Open jhenya opened 9 years ago
I think this problem is besause of onBeforeScenarioTested wasn't executed, but i can't understand why it wasn't executed
Hi jhenya,
What exactly is the issue you're having?
Are you trying to get the scenario name for a screenshot?
Hi, yes i try to get it in afterStep($scope) in my feature context $scenarioName = $this->currentScenario->getTitle(); $fileName = strreplace('|', '', str_replace(' ', '', $scenarioName)) . '.png';
And it works correct and get current scenario name (generate name from example table)
But in behat-html-formatter\src\Renderer\Behat2Renderer.php in line 346 $scenario->getScreenshotName() i get null
looks like onBeforeScenarioTested (behat-html-formatter\src\Formatter\BehatHTMLFormatter.php line 487) where screenshot name should be set wasn't executed
HI, can you put up the render after step function you have in Behat2Renderer?
I'll have a quick look.
public function renderAfterStep($obj)
{
$feature = $obj->getCurrentFeature();
$scenario = $obj->getCurrentScenario();
$steps = $scenario->getSteps();
$step = end($steps); //needed because of strict standards
//path displayed only if available (it's not available in undefined steps)
$strPath = '';
if($step->getDefinition() !== null) {
$strPath = $step->getDefinition()->getPath();
}
$stepResultClass = '';
if($step->isPassed()) {
$stepResultClass = 'passed';
}
if($step->isFailed()) {
$stepResultClass = 'failed';
}
if($step->isSkipped()) {
$stepResultClass = 'skipped';
}
if($step->isPending()) {
$stepResultClass = 'pending';
}
$print = '
<li class="'.$stepResultClass.'">
<div class="step">
<span class="keyword">'.$step->getKeyWord().' </span>
<span class="text">'.$step->getText().' </span>
<span class="path">'.$strPath.'</span>
</div>';
$exception = $step->getException();
if(!empty($exception)) {
$relativeScreenshotPath = 'assets/screenshots/' . $feature->getScreenshotFolder() . '/' . $scenario->getScreenshotName();
$fullScreenshotPath = $obj->getBasePath() . '/build/html/behat/' . $relativeScreenshotPath;
$print .= '
<pre class="backtrace">'.$step->getException().'</pre>';
if(file_exists($fullScreenshotPath))
{
$print .= '<a href="' . $relativeScreenshotPath . '">Screenshot</a>';
}
}
$print .= '
</li>';
return $print;
}
Here i just change folder results/html feature->getScreenshotFolder() works correct
Hmm, I'm not sure what's going off here. What version of Behat are you using? I'm currently on dev-master and it's working for me. Maybe they've changed something in one of the versions?
now v3.0.15, i think problem is that onBeforeScenarioTested wasn't executed (behat-html-formatter\src\Formatter\BehatHTMLFormatter.php line 487) where screenshot name should be set
Yes that does seem to be the issue. I can't see why that wouldn't be executed though? Can you paste the onBeforeScenarioTested function you have so I can take a look. APologies about all the code requests, just trying to figure out what's going on here? I'll test on 3.0.15 too.
no problem i just tried on dev-master and get same behavior /* * @param BeforeScenarioTested $event / public function onBeforeScenarioTested(BeforeScenarioTested $event) { $scenario = new Scenario(); $scenario->setName($event->getScenario()->getTitle()); $scenario->setTags($event->getScenario()->getTags()); $scenario->setLine($event->getScenario()->getLine()); $scenario->setScreenshotName($event->getScenario()->getTitle()); $this->currentScenario = $scenario;
$print = $this->renderer->renderBeforeScenario($this);
$this->printer->writeln($print);
}
we need in setScreenshotName set name of scenario (name of each example row in the scenario outline) not Scenario outline name
Still working for me? As far as I'm aware, getTitle() will get the text that comes after the Scenario: declaration unless it's a scenario outline in which case it will get the text in the example.
How are you creating your scenarios? If I could get an example of one of your features I could give it a test?
Scenario Outline: Open page and validate something
Given I am on page
for each row in example table scenario will be executed Name of each scenario here are: | some | test | parameter | parameter1 | | some | test | parameter | parameter1 |
So, what you're saying is that the above is working and creating you a screenshot with the correct name, but you are getting null when Behat2Renderer attempts to get the scenario name?
If that is the case, I'm not sure why it wouldn't be setting the screenshot name. If you could paste me an example feature file you're using, I can run it on mine to see if it works?
you need .feature or context file? In your feature from Examples table you just set parameter to context methods using angle brackets
Just a feature file, but I've found yours above, tried it and it worked fine?
did you get scenario name like this? | some | test | parameter | parameter1 |
Just tried that too and it worked for me?
How are you seeing that getScenario() is calling a null value, are you printing it somewhere?
Is it null in FeatureContext() or Behat2Renderer?
i watch Behat2Renderer in debug
So it is in Behat2Renderer then? Not really sure what I can offer here. This is consistently working for me and I'm never getting a null value. If I can't recreate, I'm not sure if there's anything I can do to fix it?
did you get scenario name like this? | some | test | parameter | parameter1 |
It just uses the Behat framework getScenario()->getTitle() function, so whatever that returns, which is either the scenario description, or in the case of scenario outline, the example data.
Hmm, then try to find something wrong in my test and let you know later
OK, well if you can find me some way to recreate it, let me know and I'd be happy to take a look.
in report we have only Scenario outline name and Scenario Example Name not available, is it possible that Scenario Example Name is not available during creating report ?
but when i add in BehatHTMLFormatter.php (line 195 getSubscribedEvents) this code tester.example_tested.before' => 'onBeforeScenarioTested', then onBeforeScenarioTested was executed before Scenario Example and I can get Scenario Example Name in report but only last Scenario Example
May be we need to add Example class here behat-html-formatter\src\Classes and implement listen event tester.example_tested.before
jroy-998, could you please try to investigate it with scenario with 2 or more Scenario Examples
Hi,
I can still get scenario example name. I did notice an issue to do with long example names, but that is separate to this I think.
I am still getting the scenario example name, so am not sure what is going wrong here? I notice your report is formatted differently to mine (see screenshot).
Are you using a different/custom version?
Hi I try using same format (renderer: Behat2) and i get Scenario Example name but only after adding in BehatHTMLFormatter.php (line 195 getSubscribedEvents) this code tester.example_tested.before' => 'onBeforeScenarioTested',
this solution Ok for me but each next Scenario Outline is nested in previous
I may have to go back to the drawing board a little bit here.
If an example contains a lot of data, the image file will not be created (I suspect that this may have something to do with file name length restrictions).
I may have to think of some other way of doing it.
I still cannot recreate the issue that you are having. But this may be superseded by doing it a different way.
As for the nesting issue. This is a seperate issue that I raised here:
https://github.com/dutchiexl/BehatHtmlFormatterPlugin/issues/47
Hi guys, are there any conclusions about the initial issue? I'm writing here from the future (2016) and the case with the empty screenshot name in Behat2Renderer is still reproducing for me. Just like described above, and only for the cases with the scenario outline
Hi! I have question about getting scenario name in report
Step by step explenation my case
I set scenario title in my FeatureContext
public function setUpTestEnvironment($scope) { $this->currentScenarioTitle = $scope->getScenario()->getTitle; }
4.After test execution when i try get scenario name using getName in \vendor\emuse\behat-html-formatter\src\Classes\Scenario.php i get only Scenario Title, in my case it is "Open page anf validate something"
but i need title from Example table like this "| some| test| parameter| parameter1|"
Could you please explain how to get it?