Best Behat code snippet using TesterExtension.load
BehatExtension.php
Source:BehatExtension.php
...22use Moodle\BehatExtension\Driver\WebDriverFactory;23/**24 * Behat extension for moodle25 *26 * Provides multiple features directory loading (Gherkin\Loader\MoodleFeaturesSuiteLoader27 */28class BehatExtension implements ExtensionInterface {29 /**30 * Extension configuration ID.31 */32 const MOODLE_ID = 'moodle';33 const GHERKIN_ID = 'gherkin';34 /**35 * @var ServiceProcessor36 */37 private $processor;38 /**39 * Initializes compiler pass.40 *41 * @param null|ServiceProcessor $processor42 */43 public function __construct(ServiceProcessor $processor = null) {44 $this->processor = $processor ? : new ServiceProcessor();45 }46 /**47 * Loads moodle specific configuration.48 *49 * @param array $config Extension configuration hash (from behat.yml)50 * @param ContainerBuilder $container ContainerBuilder instance51 */52 public function load(ContainerBuilder $container, array $config) {53 $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/services'));54 $loader->load('core.xml');55 // Getting the extension parameters.56 $container->setParameter('behat.moodle.parameters', $config);57 // Load moodle progress formatter.58 $moodleprogressformatter = new MoodleProgressFormatterFactory();59 $moodleprogressformatter->buildFormatter($container);60 // Load custom step tester event dispatcher.61 $this->loadEventDispatchingStepTester($container);62 // Load chained step tester.63 $this->loadChainedStepTester($container);64 // Load step count formatter.65 $this->loadMoodleListFormatter($container);66 // Load step count formatter.67 $this->loadMoodleStepcountFormatter($container);68 // Load screenshot formatter.69 $this->loadMoodleScreenshotFormatter($container);70 // Load namespace alias.71 $this->alias_old_namespaces();72 // Load skip passed controller and list locator.73 $this->loadSkipPassedController($container, $config['passed_cache']);74 $this->loadFilesystemSkipPassedScenariosListLocator($container);75 }76 /**77 * Loads moodle List formatter.78 *79 * @param ContainerBuilder $container80 */81 protected function loadMoodleListFormatter(ContainerBuilder $container) {82 $definition = new Definition('Moodle\BehatExtension\Output\Formatter\MoodleListFormatter', array(83 'moodle_list',84 'List all scenarios. Use with --dry-run',85 array('stepcount' => false),86 $this->createOutputPrinterDefinition()87 ));88 $definition->addTag(OutputExtension::FORMATTER_TAG, array('priority' => 101));89 $container->setDefinition(OutputExtension::FORMATTER_TAG . '.moodle_list', $definition);90 }91 /**92 * Loads moodle Step count formatter.93 *94 * @param ContainerBuilder $container95 */96 protected function loadMoodleStepcountFormatter(ContainerBuilder $container) {97 $definition = new Definition('Moodle\BehatExtension\Output\Formatter\MoodleStepcountFormatter', array(98 'moodle_stepcount',99 'Count steps in feature files. Use with --dry-run',100 array('stepcount' => false),101 $this->createOutputPrinterDefinition()102 ));103 $definition->addTag(OutputExtension::FORMATTER_TAG, array('priority' => 101));104 $container->setDefinition(OutputExtension::FORMATTER_TAG . '.moodle_stepcount', $definition);105 }106 /**107 * Loads moodle screenshot formatter.108 *109 * @param ContainerBuilder $container110 */111 protected function loadMoodleScreenshotFormatter(ContainerBuilder $container) {112 $definition = new Definition('Moodle\BehatExtension\Output\Formatter\MoodleScreenshotFormatter', array(113 'moodle_screenshot',114 'Take screenshot of all steps. Use --format-settings \'{"formats": "html,image"}\' to get specific o/p type',115 array('formats' => 'html,image'),116 $this->createOutputPrinterDefinition()117 ));118 $definition->addTag(OutputExtension::FORMATTER_TAG, array('priority' => 102));119 $container->setDefinition(OutputExtension::FORMATTER_TAG . '.moodle_screenshot', $definition);120 }121 /**122 * Creates output printer definition.123 *124 * @return Definition125 */126 protected function createOutputPrinterDefinition() {127 return new Definition('Behat\Testwork\Output\Printer\StreamOutputPrinter', array(128 new Definition('Behat\Behat\Output\Printer\ConsoleOutputFactory'),129 ));130 }131 /**132 * Loads skip passed controller.133 *134 * @param ContainerBuilder $container135 * @param null|string $cachePath136 */137 protected function loadSkipPassedController(ContainerBuilder $container, $cachePath) {138 $definition = new Definition('Moodle\BehatExtension\Tester\Cli\SkipPassedController', array(139 new Reference(EventDispatcherExtension::DISPATCHER_ID),140 $cachePath,141 $container->getParameter('paths.base')142 ));143 $definition->addTag(CliExtension::CONTROLLER_TAG, array('priority' => 200));144 $container->setDefinition(CliExtension::CONTROLLER_TAG . '.passed', $definition);145 }146 /**147 * Loads filesystem passed scenarios list locator.148 *149 * @param ContainerBuilder $container150 */151 private function loadFilesystemSkipPassedScenariosListLocator(ContainerBuilder $container) {152 $definition = new Definition('Moodle\BehatExtension\Locator\FilesystemSkipPassedListLocator', array(153 new Reference(self::GHERKIN_ID)154 ));155 $definition->addTag(SpecificationExtension::LOCATOR_TAG, array('priority' => 50));156 $container->setDefinition(SpecificationExtension::LOCATOR_TAG . '.filesystem_skip_passed_scenarios_list', $definition);157 }158 /**159 * Loads definition printers.160 *161 * @param ContainerBuilder $container162 */163 private function loadDefinitionPrinters(ContainerBuilder $container) {164 $definition = new Definition('Moodle\BehatExtension\Definition\Printer\ConsoleDefinitionInformationPrinter', array(165 new Reference(CliExtension::OUTPUT_ID),166 new Reference(DefinitionExtension::PATTERN_TRANSFORMER_ID),167 new Reference(DefinitionExtension::DEFINITION_TRANSLATOR_ID),168 new Reference(GherkinExtension::KEYWORDS_ID)169 ));170 $container->removeDefinition('definition.information_printer');171 $container->setDefinition('definition.information_printer', $definition);172 }173 /**174 * Loads definition controller.175 *176 * @param ContainerBuilder $container177 */178 private function loadController(ContainerBuilder $container) {179 $definition = new Definition('Moodle\BehatExtension\Definition\Cli\AvailableDefinitionsController', array(180 new Reference(SuiteExtension::REGISTRY_ID),181 new Reference(DefinitionExtension::WRITER_ID),182 new Reference('definition.list_printer'),183 new Reference('definition.information_printer'))184 );185 $container->removeDefinition(CliExtension::CONTROLLER_TAG . '.available_definitions');186 $container->setDefinition(CliExtension::CONTROLLER_TAG . '.available_definitions', $definition);187 }188 /**189 * Loads chained step tester.190 *191 * @param ContainerBuilder $container192 */193 protected function loadChainedStepTester(ContainerBuilder $container) {194 // Chained steps.195 $definition = new Definition('Moodle\BehatExtension\EventDispatcher\Tester\ChainedStepTester', array(196 new Reference(TesterExtension::STEP_TESTER_ID),197 ));198 $definition->addTag(TesterExtension::STEP_TESTER_WRAPPER_TAG, array('priority' => 100));199 $container->setDefinition(TesterExtension::STEP_TESTER_WRAPPER_TAG . '.substep', $definition);200 }201 /**202 * Loads event-dispatching step tester.203 *204 * @param ContainerBuilder $container205 */206 protected function loadEventDispatchingStepTester(ContainerBuilder $container) {207 $definition = new Definition('Moodle\BehatExtension\EventDispatcher\Tester\MoodleEventDispatchingStepTester', array(208 new Reference(TesterExtension::STEP_TESTER_ID),209 new Reference(EventDispatcherExtension::DISPATCHER_ID)210 ));211 $definition->addTag(TesterExtension::STEP_TESTER_WRAPPER_TAG, array('priority' => -9999));212 $container->setDefinition(TesterExtension::STEP_TESTER_WRAPPER_TAG . '.event_dispatching', $definition);213 }214 /**215 * Setups configuration for current extension.216 *217 * @param ArrayNodeDefinition $builder218 */219 public function configure(ArrayNodeDefinition $builder) {220 $builder->221 children()->222 arrayNode('capabilities')->223 useAttributeAsKey('key')->224 prototype('variable')->end()->225 end()->226 arrayNode('steps_definitions')->227 useAttributeAsKey('key')->228 prototype('variable')->end()->229 end()->230 scalarNode('moodledirroot')->231 defaultNull()->232 end()->233 scalarNode('passed_cache')->234 info('Sets the passed cache path')->235 defaultValue(236 is_writable(sys_get_temp_dir())237 ? sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'behat_passed_cache'238 : null)->239 end()->240 end()->241 end();242 }243 /**244 * {@inheritDoc}245 */246 public function getConfigKey() {247 return self::MOODLE_ID;248 }249 /**250 * {@inheritdoc}251 */252 public function initialize(ExtensionManager $extensionManager) {253 if (null !== $minkExtension = $extensionManager->getExtension('mink')) {254 $minkExtension->registerDriverFactory(new WebDriverFactory());255 }256 }257 public function process(ContainerBuilder $container) {258 // Load controller for definition printing.259 $this->loadDefinitionPrinters($container);260 $this->loadController($container);261 }262 /**263 * Alias old namespace of given. when and then for BC.264 */265 private function alias_old_namespaces() {266 class_alias('Moodle\\BehatExtension\\Context\\Step\\Given', 'Behat\\Behat\\Context\\Step\\Given', true);267 class_alias('Moodle\\BehatExtension\\Context\\Step\\When', 'Behat\\Behat\\Context\\Step\\When', true);268 class_alias('Moodle\\BehatExtension\\Context\\Step\\Then', 'Behat\\Behat\\Context\\Step\\Then', true);269 }270}...
EventDispatcherExtension.php
Source:EventDispatcherExtension.php
...24{25 /**26 * {@inheritdoc}27 */28 public function load(ContainerBuilder $container, array $config)29 {30 parent::load($container, $config);31 $this->loadStopOnFailureController($container);32 $this->loadEventDispatchingBackgroundTester($container);33 $this->loadEventDispatchingFeatureTester($container);34 $this->loadEventDispatchingOutlineTester($container);35 $this->loadEventDispatchingScenarioTester($container);36 $this->loadEventDispatchingExampleTester($container);37 $this->loadEventDispatchingStepTester($container);38 }39 /**40 * Loads stop on failure controller.41 *42 * @param ContainerBuilder $container43 */44 protected function loadStopOnFailureController(ContainerBuilder $container)45 {46 $definition = new Definition('Behat\Behat\EventDispatcher\Cli\StopOnFailureController', array(47 new Reference(EventDispatcherExtension::DISPATCHER_ID)48 ));49 $definition->addTag(CliExtension::CONTROLLER_TAG, array('priority' => 100));50 $container->setDefinition(CliExtension::CONTROLLER_TAG . '.stop_on_failure', $definition);51 }52 /**53 * Loads event-dispatching background tester.54 *55 * @param ContainerBuilder $container56 */57 protected function loadEventDispatchingBackgroundTester(ContainerBuilder $container)58 {59 $definition = new Definition('Behat\Behat\EventDispatcher\Tester\EventDispatchingBackgroundTester', array(60 new Reference(TesterExtension::BACKGROUND_TESTER_ID),61 new Reference(self::DISPATCHER_ID)62 ));63 $definition->addTag(TesterExtension::BACKGROUND_TESTER_WRAPPER_TAG, array('priority' => -9999));64 $container->setDefinition(TesterExtension::BACKGROUND_TESTER_WRAPPER_TAG . '.event_dispatching', $definition);65 }66 /**67 * Loads event-dispatching feature tester.68 *69 * @param ContainerBuilder $container70 */71 protected function loadEventDispatchingFeatureTester(ContainerBuilder $container)72 {73 $definition = new Definition('Behat\Behat\EventDispatcher\Tester\EventDispatchingFeatureTester', array(74 new Reference(TesterExtension::SPECIFICATION_TESTER_ID),75 new Reference(self::DISPATCHER_ID)76 ));77 $definition->addTag(TesterExtension::SPECIFICATION_TESTER_WRAPPER_TAG, array('priority' => -9999));78 $container->setDefinition(TesterExtension::SPECIFICATION_TESTER_WRAPPER_TAG . '.event_dispatching', $definition);79 }80 /**81 * Loads event-dispatching outline tester.82 *83 * @param ContainerBuilder $container84 */85 protected function loadEventDispatchingOutlineTester(ContainerBuilder $container)86 {87 $definition = new Definition('Behat\Behat\EventDispatcher\Tester\EventDispatchingOutlineTester', array(88 new Reference(TesterExtension::OUTLINE_TESTER_ID),89 new Reference(self::DISPATCHER_ID)90 ));91 $definition->addTag(TesterExtension::OUTLINE_TESTER_WRAPPER_TAG, array('priority' => -9999));92 $container->setDefinition(TesterExtension::OUTLINE_TESTER_WRAPPER_TAG . '.event_dispatching', $definition);93 }94 /**95 * Loads event-dispatching scenario tester.96 *97 * @param ContainerBuilder $container98 */99 protected function loadEventDispatchingScenarioTester(ContainerBuilder $container)100 {101 $definition = new Definition('Behat\Behat\EventDispatcher\Tester\EventDispatchingScenarioTester', array(102 new Reference(TesterExtension::SCENARIO_TESTER_ID),103 new Reference(self::DISPATCHER_ID),104 ScenarioTested::BEFORE,105 ScenarioTested::AFTER_SETUP,106 ScenarioTested::BEFORE_TEARDOWN,107 ScenarioTested::AFTER108 ));109 $definition->addTag(TesterExtension::SCENARIO_TESTER_WRAPPER_TAG, array('priority' => -9999));110 $container->setDefinition(TesterExtension::SCENARIO_TESTER_WRAPPER_TAG . '.event_dispatching', $definition);111 }112 /**113 * Loads event-dispatching example tester.114 *115 * @param ContainerBuilder $container116 */117 protected function loadEventDispatchingExampleTester(ContainerBuilder $container)118 {119 $definition = new Definition('Behat\Behat\EventDispatcher\Tester\EventDispatchingScenarioTester', array(120 new Reference(TesterExtension::EXAMPLE_TESTER_ID),121 new Reference(self::DISPATCHER_ID),122 ExampleTested::BEFORE,123 ExampleTested::AFTER_SETUP,124 ExampleTested::BEFORE_TEARDOWN,125 ExampleTested::AFTER126 ));127 $definition->addTag(TesterExtension::EXAMPLE_TESTER_WRAPPER_TAG, array('priority' => -9999));128 $container->setDefinition(TesterExtension::EXAMPLE_TESTER_WRAPPER_TAG . '.event_dispatching', $definition);129 }130 /**131 * Loads event-dispatching step tester.132 *133 * @param ContainerBuilder $container134 */135 protected function loadEventDispatchingStepTester(ContainerBuilder $container)136 {137 $definition = new Definition('Behat\Behat\EventDispatcher\Tester\EventDispatchingStepTester', array(138 new Reference(TesterExtension::STEP_TESTER_ID),139 new Reference(self::DISPATCHER_ID)140 ));141 $definition->addTag(TesterExtension::STEP_TESTER_WRAPPER_TAG, array('priority' => -9999));142 $container->setDefinition(TesterExtension::STEP_TESTER_WRAPPER_TAG . '.event_dispatching', $definition);143 }144}...
load
Using AI Code Generation
1$tester = new TesterExtension();2$tester->load();3$tester = new TesterExtension();4$tester->load();5$tester = new TesterExtension();6$tester->load();7$tester = new TesterExtension();8$tester->load();9$tester = new TesterExtension();10$tester->load();11$tester = new TesterExtension();12$tester->load();13$tester = new TesterExtension();14$tester->load();15$tester = new TesterExtension();16$tester->load();17$tester = new TesterExtension();18$tester->load();19$tester = new TesterExtension();20$tester->load();21$tester = new TesterExtension();22$tester->load();23$tester = new TesterExtension();24$tester->load();25$tester = new TesterExtension();26$tester->load();27$tester = new TesterExtension();28$tester->load();29$tester = new TesterExtension();30$tester->load();31$tester = new TesterExtension();32$tester->load();33$tester = new TesterExtension();34$tester->load();
load
Using AI Code Generation
1$loader = new Twig_Loader_Filesystem('path/to/templates');2$twig = new Twig_Environment($loader);3$twig->addExtension(new TesterExtension());4$loader = new Twig_Loader_Filesystem('path/to/templates');5$twig = new Twig_Environment($loader);6$twig->addExtension(new TesterExtension());7$loader = new Twig_Loader_Filesystem('path/to/templates');8$twig = new Twig_Environment($loader);9$twig->addExtension(new TesterExtension());10$loader = new Twig_Loader_Filesystem('path/to/templates');11$twig = new Twig_Environment($loader);12$twig->addExtension(new TesterExtension());
load
Using AI Code Generation
1$tester = new TesterExtension();2$tester->load('test.txt');3$tester = new TesterExtension();4$tester->load('test.txt');5$tester = new TesterExtension();6$tester->load('test.txt');7$tester = new TesterExtension();8$tester->load('test.txt');9$tester = new TesterExtension();10$tester->load('test.txt');11$tester = new TesterExtension();12$tester->load('test.txt');13$tester = new TesterExtension();14$tester->load('test.txt');15$tester = new TesterExtension();16$tester->load('test.txt');17$tester = new TesterExtension();18$tester->load('test.txt');19$tester = new TesterExtension();20$tester->load('test.txt');21$tester = new TesterExtension();22$tester->load('test.txt');23$tester = new TesterExtension();24$tester->load('test.txt');25$tester = new TesterExtension();26$tester->load('test.txt');27$tester = new TesterExtension();28$tester->load('test.txt');29$tester = new TesterExtension();30$tester->load('test.txt');
load
Using AI Code Generation
1$loader = new Twig_Loader_Filesystem('/path/to/templates');2$twig = new Twig_Environment($loader);3$twig->addExtension(new TesterExtension());4$twig->addExtension(new TesterExtension());5$twig->addExtension(new TesterExtension());6$twig->addExtension(new TesterExtension());7$twig->addExtension(new TesterExtension());8$twig->addExtension(new TesterExtension());9$twig->addExtension(new TesterExtension());10$twig->addExtension(new TesterExtension());11$twig->addExtension(new TesterExtension());12$loader = new Twig_Loader_Filesystem('/path/to/templates');13$twig = new Twig_Environment($loader);14$twig->addExtension(new TesterExtension());15$twig->addExtension(new TesterExtension());16$twig->addExtension(new TesterExtension());17$twig->addExtension(new TesterExtension());18$twig->addExtension(new TesterExtension());19$twig->addExtension(new TesterExtension());20$twig->addExtension(new TesterExtension());21$twig->addExtension(new TesterExtension());22$twig->addExtension(new TesterExtension());23$loader = new Twig_Loader_Filesystem('/path/to/templates');24$twig = new Twig_Environment($loader);25$twig->addExtension(new TesterExtension());26$twig->addExtension(new TesterExtension());
load
Using AI Code Generation
1$tester = new TesterExtension();2$tester->load();3$tester->load();4$tester = new TesterExtension();5$tester->load();6$tester->load();7$tester = new TesterExtension();8$tester->load();9$tester->load();10$tester = new TesterExtension();11$tester->load();12$tester->load();13$tester = new TesterExtension();14$tester->load();15$tester->load();16$tester = new TesterExtension();17$tester->load();18$tester->load();19$tester = new TesterExtension();20$tester->load();21$tester->load();22$tester = new TesterExtension();23$tester->load();24$tester->load();25$tester = new TesterExtension();26$tester->load();27$tester->load();28$tester = new TesterExtension();29$tester->load();30$tester->load();31$tester = new TesterExtension();32$tester->load();33$tester->load();
load
Using AI Code Generation
1$tester = new TesterExtension();2$tester->load('test.txt');3echo $tester->get();4$tester = new TesterExtension();5$tester->load('test.txt');6echo $tester->get();7$tester = new TesterExtension();8$tester->load('test.txt');9echo $tester->get();10$tester = new TesterExtension();11$tester->load('test.txt', true);12echo $tester->get();
load
Using AI Code Generation
1$tester = new \TesterExtension();2$tester->load($this);3$tester = new \TesterExtension();4$tester->load($this);5$tester = new \TesterExtension();6$tester->load($this);7$tester = new \TesterExtension();8$tester->load($this);9$tester = new \TesterExtension();10$tester->load($this);11$tester = new \TesterExtension();12$tester->load($this);13$tester = new \TesterExtension();14$tester->load($this);15$tester = new \TesterExtension();16$tester->load($this);17$tester = new \TesterExtension();18$tester->load($this);19$tester = new \TesterExtension();20$tester->load($this);21$tester = new \TesterExtension();22$tester->load($this);23$tester = new \TesterExtension();24$tester->load($this
load
Using AI Code Generation
1$tester = new TesterExtension();2$tester->load('test.txt');3$tester = new TesterExtension();4$tester->save('test.txt', 'test data');5$tester = new TesterExtension();6$tester->save('test.txt', 'test data');7$tester = new TesterExtension();8$tester->save('test.txt', 'test data');9$tester = new TesterExtension();10$tester->save('test.txt', 'test data');11$tester = new TesterExtension();12$tester->save('test.txt', 'test data');13$tester = new TesterExtension();14$tester->save('test.txt', 'test data');15$tester = new TesterExtension();16$tester->save('test.txt', 'test data');17$tester = new TesterExtension();18$tester->save('test.txt', 'test data');19$tester = new TesterExtension();20$tester->save('test.txt', 'test data');21$tester = new TesterExtension();22$tester->save('test.txt', 'test data');23$tester = new TesterExtension();24$tester->save('test.txt', 'test data');25$tester = new TesterExtension();
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.
Execute automation tests with load on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!