Apr 27, 2024
0
Level 2
Run laravel dusk browser automation after form submission
I have a simple filament v3 form once the user type a text inside that form and click submit then the laravel dusk browser automation should get the value from the input field and make a search in google.
How to achieve this:
app/Filament/Pages/Search
<?php
namespace App\Filament\Pages;
use Filament\Forms\Form;
use Filament\Pages\Page;
use Filament\Actions\Action;
use Filament\Forms\Components\Wizard;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\ViewField;
use Filament\Forms\Components\Wizard\Step;
use Filament\Pages\Concerns\InteractsWithFormActions;
class Test extends Page
{
use InteractsWithFormActions;
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.pages.test';
public ?array $data = [];
public function mount(): void
{
$this->form->fill();
}
public function form(Form $form): Form
{
return $form;
}
protected function getForms(): array
{
return [
'form' => $this->form(
$this->makeForm()
->schema([
TextInput::make('text')
->label('Write something...')
->required(),
])
->statePath('data'),
),
];
}
public function submit(): void
{
dd($this->form->getState());
}
protected function getFormActions(): array
{
return [
$this->getSubmitFormAction(),
];
}
protected function getSubmitFormAction(): Action
{
return Action::make('submit')
->label(__('Submit'))
->submit('submit');
}
}
tests/Browser/SearchTest.php
<?php
use Laravel\Dusk\Browser;
test('form test', function () {
$this->browse(function (Browser $browser) {
$browser
->visit('https://www.google.com/')
->type('textarea[name="q"]', 'Elon Musk')
->waitFor('input[name="btnK"]')
->press('input[name="btnK"]')
->waitFor('.g');
});
});
Please or to participate in this conversation.