Latest

Thursday, July 13, 2017

Laravel Dusk test working in Development but failing in Production

Asked by: João Serra


Hi everyone i have a Laravel app that runs it's CI through Gitlab CI and i have a problem my test using dusk runs fine in development on my machine but for some reason it fails whenever i push it to gitlab CI...

/** @test */
public function the_login_admin_route_should_login_the_user_with_valid_credentials()
{
    /** @var Admin $user */
    $user = factory(Admin::class)->create(['password' => bcrypt('secret')]);

    $this->browse(function (Browser $browser) use ($user) {
        $browser->visit("/admin/auth/login")
                ->type("email", $user->{Admin::FIELD_EMAIL})
                ->type("password", "secret")
                ->click("#login-button")
                ->waitForText("Logged in Successfully")
                ->waitForLocation("/admin/")
                ->assertPathIs("/admin/");
    });
}

That is the test in question and the part that fails specifically is the waitForText part.

I have another Dusk test that simply checks that when you try to go do /dashboard you get redirected to the login page and that one works fine i even do an ->assertSee("Login") so i don't think the problem is xvfb but i'm deeply puzzled.

This is my gitlab CI config relative to the dusk tests

- chmod a+x ./vendor/laravel/dusk/bin/chromedriver-linux
- xvfb-run ./vendor/laravel/dusk/bin/chromedriver-linux &
- sleep 5
- php artisan serve &
- npm install --silent
- npm run production
- php -d memory_limit=-1 artisan dusk --colors

I use Model factories to generate users as you could see and i already verified that the user is in fact created and exists in the Database using a var_dump

The text in question appears as part of a Vuetify snackbar component, kind of like a toast that appears and then flashes away after 5 seconds, again this all works fine on my machine so i don't think the component itself is the problem.

Does anyone have issues with the waitForText command when running their Dusk instances in headless environments like a CI docker container?



Source

No comments:

Post a Comment

Adbox