-
Notifications
You must be signed in to change notification settings - Fork 0
Events
Julien Gidel edited this page Mar 27, 2021
·
9 revisions
AutoMate use the design pattern Observer to add modularity. Thanks to this, you can create your own Transformer and register it before running AutoMate or add your own plugin.
This is the order events are dispatch when running the simple scenario example :
Event : core:runner:simple:begin
____________________________________________________________
/\ | | | \/ | | |
/ \ _ _| |_ ___ | \ / | __ _| |_ ___
/ /\ \| | | | __/ _ \| |\/| |/ _` | __/ _ \
/ ____ \ |_| | || (_) | | | | (_| | || __/
/_/ \_\__,_|\__\___/|_| |_|\__,_|\__\___|
____________________________________________________________
Event : core:step:transform
Event : core:step:transform:end
Go at adresse http://wikipedia.fr
Event : core:step:transform
Print : create-cookie
Event : core:step:transform:end
Text printed
Event : core:step:transform
Event : core:runner:error
The scenario exit with message : print events for wiki
Event : core:runner:simple:end
============================================================
[0] The scenario exit with message : print events for wiki
============================================================
The event is triggered then execute code and then print the result if everything went good.
To register your own plugin , your class MUST implements Automate\AutoMateListener
<?php
namespace MyNamespace;
use Automate\AutoMateListener;
class MyListener implements AutoMateListener{
public function onEvent() {
return AutoMateEvents::RUNNER_ENDS;
// or
return [AutoMateEvents::RUNNER_ENDS, AutoMateEvents::RUNNER_WIN];
}
public function notify(string $event, $data) : int {
//some actions...
//this is an example
if(is_array($data)) return AutoMateListener::STATE_REJECTED;
return AutoMateListener::STATE_RECEIVED;
}
and then register it when creating your Automate runner :
<?php
require __DIR__.'/../vendor/autoload.php';
use Automate\AutoMate;
use Automate\AutoMateEvents;
use MyNamespace\MyListener;
$configFile = __DIR__.'/config/config-test.yaml';
$autoMate = new AutoMate($configFile);
$autoMate->registerPlugin(new MyListener());
$autoMate->run('simple');
This is all defined events for v0.5.0 :
class AutoMateEvents
{
//When a simple scenario begins
const RUNNER_SIMPLE_BEGIN = 'core:runner:simple:begin';
//When a simple scenario ends
const RUNNER_SIMPLE_END = 'core:runner:simple:end';
//When a scenario with specification begins
const RUNNER_SPEC_BEGIN = 'core:runner:spec:begin';
//When a scenario with specification ends
const RUNNER_SPEC_END = 'core:runner:spec:end';
//When a new line of the spec is loaded
const RUNNER_SPEC_LINE = 'core:runner:spec:line';
//When runner handle an error
const RUNNER_ERROR = 'core:runner:error';
//When runner handle a win
const RUNNER_WIN = 'core:runner:win';
//When the runner ends with error(s)
const RUNNER_ENDS_ERROR = 'core:runner:end:error';
//When the runner call a transformer
const STEP_TRANSFORM = 'core:step:transform';
//When transformation is complete
const STEP_TRANSFORM_ENDS = 'core:step:transform:end';
//When the logic executor gets exception
const LOGIC_EXCEPTION = 'core:logic:exception'
}
AutoMate Wiki - v0.8.0 - This wiki can change at any moment