Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ArneDB's avatar

I don't fully understand how to test forms, type etc doesn't seem to be working

Hello there,

I'm trying to write some tests for some forms on my application, but I run into the problem that I can't really access any input fields.

First I tried Laravel Dusk but this is way to slow, each time I run "php artisan dusk" it takes like 10-20 seconds to boot up the chromium and run the test. Also, I run into the same issues with dusk as I do with Browserkit Testing.

So long story short, I use Browserkit Testing and I have to following setup:

    /** @test */
    public function user_can_search_for_pigeons()
    {
        $user = factory(User::class)->create();
        $pigeon = Pigeon::create([
            'father_id'         => 2,
            'mother_id'         => 3,
            'ringnumber'        => 186161207,
            'ringnumber_father' => 166021406,
            'ringnumber_mother' => 156285684,
            'name'              => 'Node',
            'gender'            => 'male',
            'color'             => null,
            'landcode'          => 'BE',
            'user_id'           => 1,
            'sold'              => null,
        ]);
        $pigeon = Pigeon::create([
            'father_id'         => 4,
            'mother_id'         => 5,
            'ringnumber'        => 166021406,
            'ringnumber_father' => 076031645,
            'ringnumber_mother' => 116115406,
            'name'              => 'Parent M',
            'gender'            => 'male',
            'color'             => null,
            'landcode'          => 'BE',
            'user_id'           => 1,
            'sold'              => null,
        ]);
        $pigeon = Pigeon::create([
            'father_id'         => 6,
            'mother_id'         => 7,
            'ringnumber'        => 156285684,
            'ringnumber_father' => '086201725',
            'ringnumber_mother' => 136056622,
            'name'              => 'Parent F',
            'gender'            => 'female',
            'color'             => null,
            'landcode'          => 'BE',
            'user_id'           => 1,
            'sold'              => null,
        ]);

        $response = $this->actingAs($user)
                    ->visit('/pigeon');

        $response->type('Node', 'ps');
        $response->press('Search');
        $response->seePageIs('/search/pigeon?q=Node');
    }

And my form

<form action="{{ route('search.pigeons') }}" method="GET">
    <div class="no-gutters">
        <div class="input-group input-group-sm">
            <div class="input-group-prepend">
                <span class="input-group-text" id="inputGroup-sizing-sm"><i class="fas fa-search"></i></span>
            </div>
            <input class="form-control" type="text" name="ps" id="pigeon_search" placeholder="Search pigeons" value="{{ request()->input('pigeon_search', old('pigeon_search')) }}">
            <select class="form-control" type="search" name="column">
                    <option
                        value=""
                        disabled hidden>
                        Pick a column
                    </option>
                    <option
                        value="name" selected
                        @if(old('column') == 'name') selected @endif>
                        Name
                    </option>
                    <option
                        value="ringnumber"
                        @if(old('column') == 'ringnumber') selected @endif>
                        Ringnumber
                    </option>
                    <option
                        value="landcode"
                        @if(old('column') == 'landcode') selected @endif>
                        Landcode
                    </option>
                </select>
            <div class="input-group-append">
                <button class="btn btn-sm btn-secondary no-border-radius-left" type="submit" style="z-index: 1;">{{ __('Search') }}</button>
            </div>
        </div>
    </div>
</form>
@if(strpos(url()->current(), 'search') !== false)
<a href="{{ route('pigeon.index') }}">{{ __('Cancel Search') }}</a> @endif

Each time I run this test I get the following error:

1) Tests\Feature\PigeonListUserCanSearch::user_can_search_for_pigeons
InvalidArgumentException: Unreachable field "ps"

But the name of the input field is ps, I don't understand why it can't find it. I'm getting my information straight from the Browserkit Testing github page https://github.com/laravel/browser-kit-testing#interacting-with-forms

0 likes
1 reply
ArneDB's avatar
ArneDB
OP
Best Answer
Level 2

Got it working via Dusk, thing is you gotta build in wait period after clicks etc, so that it has time to find and analyze the elements, very time consuming.

Please or to participate in this conversation.