umpirsky / centipede

:sparkler: The Simplest automated testing tool on Earth.
MIT License
141 stars 15 forks source link

[RFC] Scenario plugin system #26

Open PedroTroller opened 8 years ago

PedroTroller commented 8 years ago

Hi.

Just a little reflection. Why not provide a system that allow you to describe some scenarios to execute before to crawl urls.

For example :

// MyProject/centipede.php
$scenarios = new Centipede\Scenario\Collection();

$scenarios->add('customer_account', function ($browser) {
    $broswer->visit('/login');
    $broswer->fillIn('login', 'account@email.com');
    $broswer->fillIn('password', 'strong_password');
    $broswer->press('Connection');
    $broswer->visit('/account');
});

$scenarios->add('backoffice', function ($browser) {
    $broswer->visit('/admin/login');
    $broswer->fillIn('seller[uuid]', '1122334455');
    $broswer->fillIn('seller[password]', 'strong_password');
    $broswer->press('Access to dashboard');
    $broswer->visit('/admin/dashboard');
});

$scenarios->add('public', function ($browser) {
    $broswer->visit('/');
});

return $scenarios;

And then, the crawler will execute scenarios one by one and crawl urls each time.

umpirsky commented 8 years ago

Yes, this would be interesting approach. In this case browser must share same session with guzzle client used in centipede crawler.

It is in deed simple extension point without reinventing the wheel, I like it.

Thanks @PedroTroller!

Pierstoval commented 8 years ago

You could use Symfony's Client and DomCrawler classes for this (even if not asynchronous).