Best Behat code snippet using ChainEventListener
PrettyFormatterFactory.php
Source:PrettyFormatterFactory.php
...75 * @param ContainerBuilder $container76 */77 protected function loadRootNodeListener(ContainerBuilder $container)78 {79 $definition = new Definition('Behat\Testwork\Output\Node\EventListener\ChainEventListener', array(80 array(81 new Definition('Behat\Behat\Output\Node\EventListener\AST\SuiteListener', array(82 new Reference('output.node.printer.pretty.suite_setup')83 )),84 new Definition('Behat\Behat\Output\Node\EventListener\AST\FeatureListener', array(85 new Reference('output.node.printer.pretty.feature'),86 new Reference('output.node.printer.pretty.feature_setup')87 )),88 $this->proxySiblingEvents(89 BackgroundTested::BEFORE,90 BackgroundTested::AFTER,91 array(92 new Definition('Behat\Behat\Output\Node\EventListener\AST\ScenarioNodeListener', array(93 BackgroundTested::AFTER_SETUP,94 BackgroundTested::AFTER,95 new Reference('output.node.printer.pretty.scenario')96 )),97 new Definition('Behat\Behat\Output\Node\EventListener\AST\StepListener', array(98 new Reference('output.node.printer.pretty.step'),99 new Reference('output.node.printer.pretty.step_setup')100 )),101 )102 ),103 $this->proxySiblingEvents(104 ScenarioTested::BEFORE,105 ScenarioTested::AFTER,106 array(107 new Definition('Behat\Behat\Output\Node\EventListener\AST\ScenarioNodeListener', array(108 ScenarioTested::AFTER_SETUP,109 ScenarioTested::AFTER,110 new Reference('output.node.printer.pretty.scenario'),111 new Reference('output.node.printer.pretty.scenario_setup')112 )),113 new Definition('Behat\Behat\Output\Node\EventListener\AST\StepListener', array(114 new Reference('output.node.printer.pretty.step'),115 new Reference('output.node.printer.pretty.step_setup')116 )),117 )118 ),119 $this->proxySiblingEvents(120 OutlineTested::BEFORE,121 OutlineTested::AFTER,122 array(123 $this->proxyEventsIfParameterIsSet(124 'expand',125 false,126 new Definition('Behat\Behat\Output\Node\EventListener\AST\OutlineTableListener', array(127 new Reference('output.node.printer.pretty.outline_table'),128 new Reference('output.node.printer.pretty.example_row'),129 new Reference('output.node.printer.pretty.example_setup'),130 new Reference('output.node.printer.pretty.example_step_setup')131 ))132 ),133 $this->proxyEventsIfParameterIsSet(134 'expand',135 true,136 new Definition('Behat\Behat\Output\Node\EventListener\AST\OutlineListener', array(137 new Reference('output.node.printer.pretty.outline'),138 new Reference('output.node.printer.pretty.example'),139 new Reference('output.node.printer.pretty.example_step'),140 new Reference('output.node.printer.pretty.example_setup'),141 new Reference('output.node.printer.pretty.example_step_setup')142 ))143 )144 )145 ),146 )147 ));148 $container->setDefinition(self::ROOT_LISTENER_ID, $definition);149 }150 /**151 * Loads formatter itself.152 *153 * @param ContainerBuilder $container154 */155 protected function loadFormatter(ContainerBuilder $container)156 {157 $definition = new Definition('Behat\Behat\Output\Statistics\TotalStatistics');158 $container->setDefinition('output.pretty.statistics', $definition);159 $definition = new Definition('Behat\Testwork\Output\NodeEventListeningFormatter', array(160 'pretty',161 'Prints the feature as is.',162 array(163 'timer' => true,164 'expand' => false,165 'paths' => true,166 'multiline' => true,167 ),168 $this->createOutputPrinterDefinition(),169 new Definition('Behat\Testwork\Output\Node\EventListener\ChainEventListener', array(170 array(171 $this->rearrangeBackgroundEvents(172 new Reference(self::ROOT_LISTENER_ID)173 ),174 new Definition('Behat\Behat\Output\Node\EventListener\Statistics\StatisticsListener', array(175 new Reference('output.pretty.statistics'),176 new Reference('output.node.printer.pretty.statistics')177 )),178 new Definition('Behat\Behat\Output\Node\EventListener\Statistics\ScenarioStatsListener', array(179 new Reference('output.pretty.statistics')180 )),181 new Definition('Behat\Behat\Output\Node\EventListener\Statistics\StepStatsListener', array(182 new Reference('output.pretty.statistics'),183 new Reference(ExceptionExtension::PRESENTER_ID)184 )),185 )186 )187 )188 ));189 $definition->addTag(OutputExtension::FORMATTER_TAG, array('priority' => 100));190 $container->setDefinition(OutputExtension::FORMATTER_TAG . '.pretty', $definition);191 }192 /**193 * Loads feature, scenario and step printers.194 *195 * @param ContainerBuilder $container196 */197 protected function loadCorePrinters(ContainerBuilder $container)198 {199 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettyFeaturePrinter');200 $container->setDefinition('output.node.printer.pretty.feature', $definition);201 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettyPathPrinter', array(202 new Reference('output.node.printer.pretty.width_calculator'),203 '%paths.base%'204 ));205 $container->setDefinition('output.node.printer.pretty.path', $definition);206 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettyScenarioPrinter', array(207 new Reference('output.node.printer.pretty.path'),208 ));209 $container->setDefinition('output.node.printer.pretty.scenario', $definition);210 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettyStepPrinter', array(211 new Reference('output.node.printer.pretty.step_text_painter'),212 new Reference(self::RESULT_TO_STRING_CONVERTER_ID),213 new Reference('output.node.printer.pretty.path'),214 new Reference(ExceptionExtension::PRESENTER_ID)215 ));216 $container->setDefinition('output.node.printer.pretty.step', $definition);217 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettySkippedStepPrinter', array(218 new Reference('output.node.printer.pretty.step_text_painter'),219 new Reference(self::RESULT_TO_STRING_CONVERTER_ID),220 new Reference('output.node.printer.pretty.path'),221 ));222 $container->setDefinition('output.node.printer.pretty.skipped_step', $definition);223 }224 /**225 * Loads table outline printer.226 *227 * @param ContainerBuilder $container228 */229 protected function loadTableOutlinePrinter(ContainerBuilder $container)230 {231 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettyOutlineTablePrinter', array(232 new Reference('output.node.printer.pretty.scenario'),233 new Reference('output.node.printer.pretty.skipped_step'),234 new Reference(self::RESULT_TO_STRING_CONVERTER_ID)235 ));236 $container->setDefinition('output.node.printer.pretty.outline_table', $definition);237 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettyExampleRowPrinter', array(238 new Reference(self::RESULT_TO_STRING_CONVERTER_ID),239 new Reference(ExceptionExtension::PRESENTER_ID)240 ));241 $container->setDefinition('output.node.printer.pretty.example_row', $definition);242 }243 /**244 * Loads expanded outline printer.245 *246 * @param ContainerBuilder $container247 */248 protected function loadExpandedOutlinePrinter(ContainerBuilder $container)249 {250 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettyOutlinePrinter', array(251 new Reference('output.node.printer.pretty.scenario'),252 new Reference('output.node.printer.pretty.skipped_step'),253 new Reference(self::RESULT_TO_STRING_CONVERTER_ID)254 ));255 $container->setDefinition('output.node.printer.pretty.outline', $definition);256 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettyExamplePrinter', array(257 new Reference('output.node.printer.pretty.path'),258 ));259 $container->setDefinition('output.node.printer.pretty.example', $definition);260 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettyStepPrinter', array(261 new Reference('output.node.printer.pretty.step_text_painter'),262 new Reference(self::RESULT_TO_STRING_CONVERTER_ID),263 new Reference('output.node.printer.pretty.path'),264 new Reference(ExceptionExtension::PRESENTER_ID),265 8266 ));267 $container->setDefinition('output.node.printer.pretty.example_step', $definition);268 }269 /**270 * Loads hook printers.271 *272 * @param ContainerBuilder $container273 */274 protected function loadHookPrinters(ContainerBuilder $container)275 {276 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettySetupPrinter', array(277 new Reference(self::RESULT_TO_STRING_CONVERTER_ID),278 new Reference(ExceptionExtension::PRESENTER_ID),279 0,280 true,281 true282 ));283 $container->setDefinition('output.node.printer.pretty.suite_setup', $definition);284 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettySetupPrinter', array(285 new Reference(self::RESULT_TO_STRING_CONVERTER_ID),286 new Reference(ExceptionExtension::PRESENTER_ID),287 0,288 false,289 true290 ));291 $container->setDefinition('output.node.printer.pretty.feature_setup', $definition);292 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettySetupPrinter', array(293 new Reference(self::RESULT_TO_STRING_CONVERTER_ID),294 new Reference(ExceptionExtension::PRESENTER_ID),295 2296 ));297 $container->setDefinition('output.node.printer.pretty.scenario_setup', $definition);298 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettySetupPrinter', array(299 new Reference(self::RESULT_TO_STRING_CONVERTER_ID),300 new Reference(ExceptionExtension::PRESENTER_ID),301 4302 ));303 $container->setDefinition('output.node.printer.pretty.step_setup', $definition);304 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettySetupPrinter', array(305 new Reference(self::RESULT_TO_STRING_CONVERTER_ID),306 new Reference(ExceptionExtension::PRESENTER_ID),307 8308 ));309 $container->setDefinition('output.node.printer.pretty.example_step_setup', $definition);310 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettySetupPrinter', array(311 new Reference(self::RESULT_TO_STRING_CONVERTER_ID),312 new Reference(ExceptionExtension::PRESENTER_ID),313 6314 ));315 $container->setDefinition('output.node.printer.pretty.example_setup', $definition);316 }317 /**318 * Loads statistics printer.319 *320 * @param ContainerBuilder $container321 */322 protected function loadStatisticsPrinter(ContainerBuilder $container)323 {324 $definition = new Definition('Behat\Behat\Output\Node\Printer\CounterPrinter', array(325 new Reference(self::RESULT_TO_STRING_CONVERTER_ID),326 new Reference(TranslatorExtension::TRANSLATOR_ID),327 ));328 $container->setDefinition('output.node.printer.counter', $definition);329 $definition = new Definition('Behat\Behat\Output\Node\Printer\ListPrinter', array(330 new Reference(self::RESULT_TO_STRING_CONVERTER_ID),331 new Reference(ExceptionExtension::PRESENTER_ID),332 new Reference(TranslatorExtension::TRANSLATOR_ID),333 '%paths.base%'334 ));335 $container->setDefinition('output.node.printer.list', $definition);336 $definition = new Definition('Behat\Behat\Output\Node\Printer\Pretty\PrettyStatisticsPrinter', array(337 new Reference('output.node.printer.counter'),338 new Reference('output.node.printer.list')339 ));340 $container->setDefinition('output.node.printer.pretty.statistics', $definition);341 }342 /**343 * Loads printer helpers.344 *345 * @param ContainerBuilder $container346 */347 protected function loadPrinterHelpers(ContainerBuilder $container)348 {349 $definition = new Definition('Behat\Behat\Output\Node\Printer\Helper\WidthCalculator');350 $container->setDefinition('output.node.printer.pretty.width_calculator', $definition);351 $definition = new Definition('Behat\Behat\Output\Node\Printer\Helper\StepTextPainter', array(352 new Reference(DefinitionExtension::PATTERN_TRANSFORMER_ID),353 new Reference(self::RESULT_TO_STRING_CONVERTER_ID)354 ));355 $container->setDefinition('output.node.printer.pretty.step_text_painter', $definition);356 $definition = new Definition('Behat\Behat\Output\Node\Printer\Helper\ResultToStringConverter');357 $container->setDefinition(self::RESULT_TO_STRING_CONVERTER_ID, $definition);358 }359 /**360 * Creates output printer definition.361 *362 * @return Definition363 */364 protected function createOutputPrinterDefinition()365 {366 return new Definition('Behat\Testwork\Output\Printer\StreamOutputPrinter', array(367 new Definition('Behat\Behat\Output\Printer\ConsoleOutputFactory'),368 ));369 }370 /**371 * Creates root listener definition.372 *373 * @param mixed $listener374 *375 * @return Definition376 */377 protected function rearrangeBackgroundEvents($listener)378 {379 return new Definition('Behat\Behat\Output\Node\EventListener\Flow\FirstBackgroundFiresFirstListener', array(380 new Definition('Behat\Behat\Output\Node\EventListener\Flow\OnlyFirstBackgroundFiresListener', array(381 $listener382 ))383 ));384 }385 /**386 * Creates contextual proxy listener.387 *388 * @param string $beforeEventName389 * @param string $afterEventName390 * @param Definition[] $listeners391 *392 * @return Definition393 */394 protected function proxySiblingEvents($beforeEventName, $afterEventName, array $listeners)395 {396 return new Definition('Behat\Behat\Output\Node\EventListener\Flow\FireOnlySiblingsListener',397 array(398 $beforeEventName,399 $afterEventName,400 new Definition('Behat\Testwork\Output\Node\EventListener\ChainEventListener', array($listeners))401 )402 );403 }404 /**405 * Creates contextual proxy listener.406 *407 * @param string $name408 * @param mixed $value409 * @param mixed $listener410 *411 * @return Definition412 */413 protected function proxyEventsIfParameterIsSet($name, $value, Definition $listener)414 {...
PimFormatterFactory.php
Source:PimFormatterFactory.php
...10use Behat\Behat\Output\Node\Printer\JUnit\JUnitStepPrinter;11use Behat\Behat\Output\Node\Printer\JUnit\JUnitSuitePrinter;12use Behat\Behat\Output\Statistics\PhaseStatistics;13use Behat\Testwork\Exception\ServiceContainer\ExceptionExtension;14use Behat\Testwork\Output\Node\EventListener\ChainEventListener;15use Behat\Testwork\Output\NodeEventListeningFormatter;16use Behat\Testwork\Output\Printer\Factory\FilesystemOutputFactory;17use Behat\Testwork\Output\Printer\JUnitOutputPrinter;18use Behat\Testwork\Output\ServiceContainer\Formatter\FormatterFactory;19use Behat\Testwork\Output\ServiceContainer\OutputExtension;20use Pim\Behat\Extension\PimFormatter\Output\Node\EventListener\PimFeatureElementListener;21use Pim\Behat\Extension\PimFormatter\Output\Node\Printer\PimScenarioPrinter;22use Symfony\Component\DependencyInjection\ContainerBuilder;23use Symfony\Component\DependencyInjection\Definition;24use Symfony\Component\DependencyInjection\Reference;25/**26 * PIM formatter factory, based on junit factory.27 *28 * @author Alexandre Hocquard <alexandre.hocquard@akeneo.com>29 * @copyright 2017 Akeneo SAS (http://www.akeneo.com)30 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)31 *32 * @see \Behat\Behat\Output\ServiceContainer\Formatter\JUnitFormatterFactory33 */34final class PimFormatterFactory implements FormatterFactory35{36 /*37 * Available services38 */39 const ROOT_LISTENER_ID = 'pim.output.node.listener.junit';40 const RESULT_TO_STRING_CONVERTER_ID = 'pim.output.node.printer.result_to_string';41 /**42 * {@inheritdoc}43 */44 public function buildFormatter(ContainerBuilder $container)45 {46 $this->loadRootNodeListener($container);47 $this->loadPrinterHelpers($container);48 $this->loadCorePrinters($container);49 $this->loadFormatter($container);50 }51 /**52 * {@inheritdoc}53 */54 public function processFormatter(ContainerBuilder $container)55 {56 }57 /**58 * Loads printer helpers.59 *60 * @param ContainerBuilder $container61 */62 private function loadPrinterHelpers(ContainerBuilder $container) : void63 {64 $definition = new Definition(ResultToStringConverter::class);65 $container->setDefinition(self::RESULT_TO_STRING_CONVERTER_ID, $definition);66 }67 /**68 * Loads the specific printers for Akeneo PIM.69 *70 * @param ContainerBuilder $container71 */72 private function loadCorePrinters(ContainerBuilder $container) : void73 {74 $definition = new Definition(JUnitSuitePrinter::class, [75 new Reference('pim.output.junit.statistics'),76 ]);77 $container->setDefinition('pim.output.node.printer.junit.suite', $definition);78 $definition = new Definition(JUnitFeaturePrinter::class, [79 new Reference('pim.output.junit.statistics'),80 ]);81 $container->setDefinition('pim.output.node.printer.junit.feature', $definition);82 $definition = new Definition(PimScenarioPrinter::class, [83 '%paths.base%',84 new Reference(self::RESULT_TO_STRING_CONVERTER_ID),85 new Reference('pim.output.node.listener.junit.outline'),86 ]);87 $container->setDefinition('pim.output.node.printer.pim.scenario', $definition);88 $definition = new Definition(JUnitStepPrinter::class, [89 new Reference(ExceptionExtension::PRESENTER_ID),90 ]);91 $container->setDefinition('pim.output.node.printer.junit.step', $definition);92 }93 /**94 * Loads the node listeners required for JUnit printers to work.95 *96 * @param ContainerBuilder $container97 */98 private function loadRootNodeListener(ContainerBuilder $container) : void99 {100 $definition = new Definition(JUnitOutlineStoreListener::class, [101 new Reference('pim.output.node.printer.junit.suite')102 ]103 );104 $container->setDefinition('pim.output.node.listener.junit.outline', $definition);105 $definition = new Definition(ChainEventListener::class, [106 [107 new Reference('pim.output.node.listener.junit.outline'),108 new Definition(PimFeatureElementListener::class, [109 new Reference('pim.output.node.printer.junit.feature'),110 new Reference('pim.output.node.printer.pim.scenario'),111 new Reference('pim.output.node.printer.junit.step'),112 ]),113 ],114 ]);115 $container->setDefinition(self::ROOT_LISTENER_ID, $definition);116 }117 /**118 * Loads formatter itself.119 *120 * @param ContainerBuilder $container121 */122 private function loadFormatter(ContainerBuilder $container) : void123 {124 $definition = new Definition(PhaseStatistics::class);125 $container->setDefinition('pim.output.junit.statistics', $definition);126 $definition = new Definition(NodeEventListeningFormatter::class, [127 'pim',128 'Outputs the failures in JUnit compatible files, with path to the failing scenario instead of namespace.',129 ['timer' => true],130 $this->createOutputPrinterDefinition(),131 new Definition(ChainEventListener::class, [132 [133 new Reference(self::ROOT_LISTENER_ID),134 new Definition(ScenarioStatsListener::class, [135 new Reference('pim.output.junit.statistics')136 ]),137 new Definition(StepStatsListener::class, [138 new Reference('pim.output.junit.statistics'),139 new Reference(ExceptionExtension::PRESENTER_ID)140 ]),141 new Definition(HookStatsListener::class, [142 new Reference('pim.output.junit.statistics'),143 new Reference(ExceptionExtension::PRESENTER_ID)144 ]),145 ],...
JUnitFormatterFactory.php
Source:JUnitFormatterFactory.php
...93 new Reference('output.node.printer.junit.suite')94 )95 );96 $container->setDefinition('output.node.listener.junit.outline', $definition);97 $definition = new Definition('Behat\Testwork\Output\Node\EventListener\ChainEventListener', array(98 array(99 new Reference('output.node.listener.junit.outline'),100 new Definition('Behat\Behat\Output\Node\EventListener\JUnit\JUnitFeatureElementListener', array(101 new Reference('output.node.printer.junit.feature'),102 new Reference('output.node.printer.junit.scenario'),103 new Reference('output.node.printer.junit.step'),104 new Reference('output.node.printer.junit.setup'),105 )),106 ),107 ));108 $container->setDefinition(self::ROOT_LISTENER_ID, $definition);109 }110 /**111 * Loads formatter itself.112 *113 * @param ContainerBuilder $container114 */115 private function loadFormatter(ContainerBuilder $container)116 {117 $definition = new Definition('Behat\Behat\Output\Statistics\PhaseStatistics');118 $container->setDefinition('output.junit.statistics', $definition);119 $definition = new Definition('Behat\Testwork\Output\NodeEventListeningFormatter', array(120 'junit',121 'Outputs the failures in JUnit compatible files.',122 array(123 'timer' => true,124 ),125 $this->createOutputPrinterDefinition(),126 new Definition('Behat\Testwork\Output\Node\EventListener\ChainEventListener', array(127 array(128 new Reference(self::ROOT_LISTENER_ID),129 new Definition('Behat\Behat\Output\Node\EventListener\Statistics\ScenarioStatsListener', array(130 new Reference('output.junit.statistics')131 )),132 new Definition('Behat\Behat\Output\Node\EventListener\Statistics\StepStatsListener', array(133 new Reference('output.junit.statistics'),134 new Reference(ExceptionExtension::PRESENTER_ID)135 )),136 new Definition('Behat\Behat\Output\Node\EventListener\Statistics\HookStatsListener', array(137 new Reference('output.junit.statistics'),138 new Reference(ExceptionExtension::PRESENTER_ID)139 )),140 ),...
BehatJsonFormatterExtension2.php
Source:BehatJsonFormatterExtension2.php
1<?php2namespace CCB\JsonFormatter\Behat;3use Behat\Behat\Output\Printer\ConsoleOutputFactory;4use Behat\Testwork\Exception\ServiceContainer\ExceptionExtension;5use Behat\Testwork\Output\Node\EventListener\ChainEventListener;6use CCB\JsonFormatter\Behat\Listeners\JsonListener;7use Behat\Testwork\Output\ServiceContainer\OutputExtension;8use Behat\Testwork\ServiceContainer\Extension;9use Behat\Testwork\ServiceContainer\ExtensionManager;10use Behat\Testwork\ServiceContainer\ServiceProcessor;11use CCB\JsonFormatter\Behat\Printers2\JsonOutputPrinter;12use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;13use Symfony\Component\DependencyInjection\ContainerBuilder;14use Symfony\Component\DependencyInjection\Definition;15use Symfony\Component\DependencyInjection\Reference;16class BehatJsonFormatterExtension2 implements Extension 17{18 /**19 * @var ServiceProcessor20 */21 private $processor;22 /*23 * Available services24 */25 const ROOT_LISTENER_ID = 'output.node.listener.json';26 const RESULT_TO_STRING_CONVERTER_ID = 'output.node.printer.result_to_string';27 /*28 * Available extension points29 */30 const ROOT_LISTENER_WRAPPER_TAG = 'output.node.listener.json.wrapper';31 /**32 * Initializes extension.33 *34 * @param null|ServiceProcessor $processor35 */36 public function __construct(ServiceProcessor $processor = null)37 {38 $this->processor = $processor ? : new ServiceProcessor();39 }40 public function process(ContainerBuilder $container)41 {42 $this->processListenerWrappers($container);43 }44 public function getConfigKey()45 {46 return 'json';47 }48 public function initialize(ExtensionManager $extensionManager)49 {50 }51 public function configure(ArrayNodeDefinition $builder)52 {53 }54 public function load(ContainerBuilder $container, array $config)55 {56 $this->loadRootNodeListener($container);57 $this->loadPrinterHelpers($container);58 $this->loadFormatter($container);59 }60 /**61 * {@inheritdoc}62 */63 public function processFormatter(ContainerBuilder $container)64 {65 $this->processListenerWrappers($container);66 }67 /**68 * Loads printer helpers.69 *70 * @param ContainerBuilder $container71 */72 private function loadPrinterHelpers(ContainerBuilder $container)73 {74 $definition = new Definition('Behat\Behat\Output\Node\Printer\Helper\ResultToStringConverter');75 $container->setDefinition(self::RESULT_TO_STRING_CONVERTER_ID, $definition);76 }77 /**78 * Loads json formatter node event listener.79 *80 * @param ContainerBuilder $container81 */82 protected function loadRootNodeListener(ContainerBuilder $container)83 {84 $definition = new Definition(JsonListener::class);85 $container->setDefinition('output.node.listener.junit.all', $definition);86 $definition = new Definition(ChainEventListener::class, [87 [88 new Reference('output.node.listener.junit.all'),89 ]90 ]);91 $container->setDefinition(self::ROOT_LISTENER_ID, $definition);92 }93 /**94 * Loads formatter itself.95 *96 * @param ContainerBuilder $container97 */98 protected function loadFormatter(ContainerBuilder $container)99 {100 $definition = new Definition('Behat\Behat\Output\Statistics\PhaseStatistics');101 $container->setDefinition('output.json.statistics', $definition);102 $definition = new Definition('Behat\Testwork\Output\NodeEventListeningFormatter', array(103 'json',104 'Outputs in json.',105 array(106 'timer' => true,107 'expand' => false,108 'paths' => true,109 'multiline' => false,110 ),111 $this->createOutputPrinterDefinition(),112 new Definition('Behat\Testwork\Output\Node\EventListener\ChainEventListener', array(113 array(114 $this->rearrangeBackgroundEvents(115 new Reference(self::ROOT_LISTENER_ID)116 ),117 new Definition('Behat\Behat\Output\Node\EventListener\Statistics\ScenarioStatsListener', array(118 new Reference('output.junit.statistics')119 )),120 new Definition('Behat\Behat\Output\Node\EventListener\Statistics\StepStatsListener', array(121 new Reference('output.junit.statistics'),122 new Reference(ExceptionExtension::PRESENTER_ID)123 )),124 new Definition('Behat\Behat\Output\Node\EventListener\Statistics\HookStatsListener', array(125 new Reference('output.junit.statistics'),126 new Reference(ExceptionExtension::PRESENTER_ID)...
StatisticFormatterFactory.php
Source:StatisticFormatterFactory.php
1<?php2namespace Labudzinski\TestFrameworkBundle\BehatStatisticExtension\ServiceContainer\Formatter;3use Behat\Testwork\Output\Node\EventListener\ChainEventListener;4use Behat\Testwork\Output\NodeEventListeningFormatter;5use Behat\Testwork\Output\ServiceContainer\Formatter\FormatterFactory;6use Behat\Testwork\Output\ServiceContainer\OutputExtension;7use Labudzinski\TestFrameworkBundle\BehatStatisticExtension\EventListener\FeatureStatisticSubscriber;8use Labudzinski\TestFrameworkBundle\BehatStatisticExtension\Output\Printer\NullOutputPrinter;9use Symfony\Component\DependencyInjection\ContainerBuilder;10use Symfony\Component\DependencyInjection\Definition;11use Symfony\Component\DependencyInjection\Reference;12final class StatisticFormatterFactory implements FormatterFactory13{14 /**15 * Builds formatter configuration.16 *17 * @param ContainerBuilder $container18 */19 public function buildFormatter(ContainerBuilder $container)20 {21 $this->defineStatisticModels($container);22 $this->loadSubscribers($container);23 $this->loadFormatter($container);24 }25 /**26 * Processes formatter configuration.27 *28 * @param ContainerBuilder $container29 */30 public function processFormatter(ContainerBuilder $container)31 {32 $subsriber = $container->getDefinition('behat_statistic.listener.feature_statistic_subscriber');33 $subsriber->addMethodCall('setOutput', [$container->get('cli.output')]);34 }35 /**36 * @param ContainerBuilder $container37 */38 private function defineStatisticModels(ContainerBuilder $container)39 {40 $container->setParameter(41 'oro_behat_statistic.models',42 [43 'Labudzinski\TestFrameworkBundle\BehatStatisticExtension\Model\FeatureStatistic',44 ]45 );46 }47 /**48 * Loads formatter itself.49 *50 * @param ContainerBuilder $container51 */52 private function loadFormatter(ContainerBuilder $container)53 {54 $definition = new Definition(NodeEventListeningFormatter::class, [55 'statistic',56 'Outputs statistic in database.',57 [],58 new Definition(NullOutputPrinter::class),59 new Definition(ChainEventListener::class, [60 [61 new Reference('behat_statistic.listener.feature_statistic_subscriber'),62 ],63 ]),64 ]);65 $definition->addTag(OutputExtension::FORMATTER_TAG, ['priority' => 100]);66 $container->setDefinition(OutputExtension::FORMATTER_TAG . '.statistic', $definition);67 }68 /**69 * @param ContainerBuilder $container70 */71 private function loadSubscribers(ContainerBuilder $container)72 {73 $featureStatisticSubscriber = new Definition(...
ChainEventListener.php
Source:ChainEventListener.php
...16 * Used to compose formatter event listeners.17 *18 * @author Konstantin Kudryashov <ever.zet@gmail.com>19 */20class ChainEventListener implements EventListener, Countable, IteratorAggregate21{22 /**23 * @var EventListener[]24 */25 private $listeners;26 /**27 * Initializes collection.28 *29 * @param EventListener[] $listeners30 */31 public function __construct(array $listeners)32 {33 $this->listeners = $listeners;34 }...
ChainEventListener
Using AI Code Generation
1require_once 'vendor/autoload.php';2use Behat\Mink\Driver\GoutteDriver;3use Behat\Mink\Session;4use Behat\Mink\Driver\BrowserKitDriver;5use Behat\Mink\Element\DocumentElement;6use Behat\Mink\Element\NodeElement;7use Behat\Mink\Exception\ElementNotFoundException;8use Behat\Mink\Exception\ExpectationException;9use Behat\Mink\Selector\Xpath\Escaper;10use Behat\Mink\Driver\Selenium2Driver;11use Behat\Mink\Driver\DriverInterface;12use Behat\Mink\Exception\DriverException;13use Behat\Mink\Exception\UnsupportedDriverActionException;14use Behat\Mink\Exception\ElementHtmlException;15use Behat\Mink\Exception\ElementTextException;16use Behat\Mink\Exception\ExpectationException;17use Behat\Mink\Exception\UnsupportedDriverActionException;18use Behat\Mink\Exception\DriverException;19use Behat\Mink\Exception\ElementHtmlException;20use Behat\Mink\Exception\ElementTextException;21use Behat\Mink\Exception\ExpectationException;22use Behat\Mink\Exception\UnsupportedDriverActionException;23use Behat\Mink\Exception\UnsupportedDriverActionException;24use Behat\Mink\Exception\UnsupportedDriverActionException;25use Behat\Mink\Exception\ElementHtmlException;26use Behat\Mink\Exception\ElementTextException;27use Behat\Mink\Exception\ExpectationException;28use Behat\Mink\Exception\UnsupportedDriverActionException;29use Behat\Mink\Exception\UnsupportedDriverActionException;30use Behat\Mink\Exception\ElementHtmlException;31use Behat\Mink\Exception\ElementTextException;32use Behat\Mink\Exception\ExpectationException;33use Behat\Mink\Exception\UnsupportedDriverActionException;34use Behat\Mink\Exception\UnsupportedDriverActionException;35use Behat\Mink\Exception\ElementHtmlException;36use Behat\Mink\Exception\ElementTextException;37use Behat\Mink\Exception\ExpectationException;38use Behat\Mink\Exception\UnsupportedDriverActionException;39use Behat\Mink\Exception\UnsupportedDriverActionException;40use Behat\Mink\Exception\ElementHtmlException;41use Behat\Mink\Exception\ElementTextException;42use Behat\Mink\Exception\ExpectationException;43use Behat\Mink\Exception\UnsupportedDriverActionException;44use Behat\Mink\Exception\UnsupportedDriverActionException;
ChainEventListener
Using AI Code Generation
1$driver = new GoutteDriver();2$session = new Session($driver);3$session->start();4$element = $session->getPage()->find('css', 'a');5$listener = new ChainEventListener();6$listener->addListener(new MyListener());7$driver->getClient()->setListener($listener);8$element->click();9echo $session->getPage()->getContent();10echo "Hello World";
ChainEventListener
Using AI Code Generation
1$chainEventListener = new ChainEventListener();2$session->getDriver()->getWebDriverSession()->execute(3 array(4 'script' => $chainEventListener->getScript(),5 'args' => array()6);7$chainEventListener = new ChainEventListener();8$session->getDriver()->getWebDriverSession()->execute(9 array(10 'script' => $chainEventListener->getScript(),11 'args' => array()12);13$chainEventListener = new ChainEventListener();14$session->getDriver()->getWebDriverSession()->execute(15 array(16 'script' => $chainEventListener->getScript(),17 'args' => array()18);19$chainEventListener = new ChainEventListener();20$session->getDriver()->getWebDriverSession()->execute(21 array(22 'script' => $chainEventListener->getScript(),23 'args' => array()24);25$chainEventListener = new ChainEventListener();26$session->getDriver()->getWebDriverSession()->execute(27 array(28 'script' => $chainEventListener->getScript(),29 'args' => array()30);31$chainEventListener = new ChainEventListener();32$session->getDriver()->getWebDriverSession()->execute(33 array(34 'script' => $chainEventListener->getScript(),35 'args' => array()36);
ChainEventListener
Using AI Code Generation
1$driver = $this->getSession()->getDriver();2$driver->getClient()->followRedirects(false);3$driver->getClient()->getHistory()->clear();4$driver->visit($this->locatePath('/'));5$driver->getBrowser()->clickLink('Link 1');6$driver->getBrowser()->clickLink('Link 2');7$driver->getBrowser()->clickLink('Link 3');8$driver->visit($this->locatePath('/'));9$driver->getBrowser()->clickLink('Link 1');10$driver->getBrowser()->clickLink('Link 2');11$driver->getBrowser()->clickLink('Link 3');12$driver->getBrowser()->clickLink('Link 4');13$driver->getBrowser()->clickLink('Link 5');14$driver->getBrowser()->clickLink('Link 6');15$driver->getBrowser()->clickLink('Link 7');16$driver->getBrowser()->clickLink('Link 8');17$driver->getBrowser()->clickLink('Link 9');18$driver->getBrowser()->clickLink('Link 10');19$driver->getBrowser()->clickLink('Link 11');20$driver->getBrowser()->clickLink('Link 12');21$driver->getBrowser()->clickLink('Link 13');22$driver->getBrowser()->clickLink('Link 14');23$driver->getBrowser()->clickLink('Link 15');24$driver->getBrowser()->clickLink('Link 16');25$driver->getBrowser()->clickLink('Link 17');26$driver->getBrowser()->clickLink('Link 18');27$driver->getBrowser()->clickLink('Link 19');28$driver->getBrowser()->clickLink('Link 20');29$driver->getBrowser()->clickLink('Link 21');30$driver->getBrowser()->clickLink('Link 22');31$driver->getBrowser()->clickLink('Link 23');32$driver->getBrowser()->clickLink('Link 24');33$driver->getBrowser()->clickLink('Link 25');34$driver->getBrowser()->clickLink('Link 26');35$driver->getBrowser()->clickLink('Link 27');36$driver->getBrowser()->clickLink('Link 28');37$driver->getBrowser()->clickLink('Link 29');38$driver->getBrowser()->
ChainEventListener
Using AI Code Generation
1$dispatcher = $this->getMink()->getSession()->getDriver()->getWebDriverSession()->getDriver()->getEventDispatcher();2$dispatcher->addListener('selenium.request', function($event) {3 $request = $event->getRequest();4 $request->setMethod('POST');5});6$dispatcher->addListener('selenium.request', function($event) {7 $request = $event->getRequest();8 $request->setMethod('POST');9});10$dispatcher->addListener('selenium.request', function($event) {11 $request = $event->getRequest();12 $request->setMethod('POST');13});14PHP Fatal error: Call to undefined method Symfony\Component\EventDispatcher\GenericEvent::getRequest() in /var/www/html/Drupal/vendor/behat/mink-extension/src/Behat/MinkExtension/EventDispatcher/Listener/Selenium2Listener.php on line 3015Fatal error: Call to undefined method Symfony\Component\EventDispatcher\GenericEvent::getRequest() in /var/www/html
ChainEventListener
Using AI Code Generation
1$session = $this->getSession();2$chain = new ChainEventListener($session->getDriver());3$chain->addEvent('click', 'a#link1');4$chain->addEvent('click', 'a#link2');5$chain->addEvent('click', 'a#link3');6$chain->addEvent('click', 'a#link4');7$chain->addEvent('click', 'a#link5');8$chain->addEvent('click', 'a#link6');9$chain->addEvent('click', 'a#link7');10$chain->addEvent('click', 'a#link8');11$chain->addEvent('click', 'a#link9');12$chain->addEvent('click', 'a#link10');13$chain->addEvent('click', 'a#link11');14$chain->addEvent('click', 'a#link12');15$chain->addEvent('click', 'a#link13');16$chain->addEvent('click', 'a#link14');17$chain->addEvent('click', 'a#link15');18$chain->addEvent('click', 'a#link16');19$chain->addEvent('click', 'a#link17');20$chain->addEvent('click', 'a#link18');21$chain->addEvent('click', 'a#link19');22$chain->addEvent('click', 'a#link20');23$chain->addEvent('click', 'a#link21');24$chain->addEvent('click', 'a#link22');25$chain->addEvent('click', 'a#link23');26$chain->addEvent('click', 'a#link24');27$chain->addEvent('click', 'a#link25');28$chain->addEvent('click', 'a#link26');29$chain->addEvent('click', 'a#link27');30$chain->addEvent('click', 'a#link28');31$chain->addEvent('click', 'a#link29');32$chain->addEvent('click', 'a#link30');33$chain->addEvent('click', 'a#link31');34$chain->addEvent('click', 'a#link32');35$chain->addEvent('click', 'a#link33');36$chain->addEvent('click', 'a#link34');
ChainEventListener
Using AI Code Generation
1$driver = $this->getSession()->getDriver();2$driver->getWebDriverSession()->getCommandExecutor()->addEventListener(3 new ChainEventListener(4 new EventListener\DebugListener(),5 new EventListener\TimingListener()6);7$driver = $this->getSession()->getDriver();8$driver->getClient()->getInternalRequest()->addListener(9 new ChainEventListener(10 new EventListener\DebugListener(),11 new EventListener\TimingListener()12);13$driver = $this->getSession()->getDriver();14$driver->getClient()->getInternalRequest()->addListener(15 new ChainEventListener(16 new EventListener\DebugListener(),17 new EventListener\TimingListener()18);19$driver = $this->getSession()->getDriver();20$driver->getClient()->getInternalRequest()->addListener(21 new ChainEventListener(22 new EventListener\DebugListener(),23 new EventListener\TimingListener()24);25$driver = $this->getSession()->getDriver();26$driver->getSahi()->getCommandExecutor()->addEventListener(27 new ChainEventListener(28 new EventListener\DebugListener(),29 new EventListener\TimingListener()30);31$driver = $this->getSession()->getDriver();32$driver->getSahi()->getCommandExecutor()->addEventListener(33 new ChainEventListener(34 new EventListener\DebugListener(),35 new EventListener\TimingListener()36);37$driver = $this->getSession()->getDriver();38$driver->getClient()->getInternalRequest()->addListener(39 new ChainEventListener(40 new EventListener\DebugListener(),41 new EventListener\TimingListener()42);43$driver = $this->getSession()->getDriver();44$driver->getClient()->getInternalRequest()->addListener(45 new ChainEventListener(
ChainEventListener
Using AI Code Generation
1$chainEventListener = new ChainEventListener($this->getSession()->getDriver());2$chainEventListener->addListener('click', function ($event) {3});4$chainEventListener->removeListener('click');5$driver = $this->getSession()->getDriver();6$driver->getWebDriverSession()->postCommand('POST', '/session/:sessionId/chromium/send_command', ['cmd' => 'Network.enable', 'params' => []]);7$driver->getWebDriverSession()->postCommand('POST', '/session/:sessionId/chromium/send_command', ['cmd' => 'Network.disable', 'params' => []]);8$driver = $this->getSession()->getDriver();9$driver->getWebDriverSession()->getDriver()->getWebDriverSession()->postCommand('POST', '/session/:sessionId/chromium/send_command', ['cmd' => 'Network.enable', 'params' => []]);10$driver->getWebDriverSession()->getDriver()->getWebDriverSession()->postCommand('POST', '/session/:sessionId/chromium/send_command', ['cmd' => 'Network.disable', 'params' => []]);11$driver = $this->getSession()->getDriver();12$driver->getWebDriverSession()->getDriver()->getWebDriverSession()->getDriver()->getWebDriverSession()->postCommand('POST', '/session/:sessionId/chromium/send_command', ['cmd' => 'Network.enable', 'params' => []]);13$driver->getWebDriverSession()->getDriver()->getWebDriverSession()->getDriver()->getWebDriverSession()->postCommand('POST', '/session/:sessionId/chromium/send_command', ['cmd' => 'Network
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!