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

bencarter78@hotmail.com's avatar

Setting Up Testing With Laravel 5.3 And Selenium

Hi there,

I'm just starting a new L5.3 project and have come to need testing some javascript functionality. I'm using Selenium, but I can't see how to set it up to use with the nice testing helpers.

I have a SeleniumTestCase which my main LoginTest file extends...

<?php

use Tests\Traits\UserTypes;

class SeleniumTestCase extends PHPUnit_Extensions_Selenium2TestCase
{
    use UserTypes;

    /**
     * @var
     */
    protected $app;

    /**
     * @var string
     */
    protected $baseUrl = 'http://my-url.dev';

    /**
     * Set up the tests
     */
    public function setUp()
    {
        $this->setBrowser('firefox');
        $this->setBrowserUrl($this->baseUrl);
        $this->createApplication();
    }

    /**
     * Creates the application.
     *
     * @return \Illuminate\Foundation\Application
     */
    public function createApplication()
    {
        $app = require __DIR__ . '/../bootstrap/app.php';

        $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

        return $app;
    }

Because I'm extending PHPUnit_Extensions_Selenium2TestCase I don't have access to the great testing helpers. In the past I've used Laracasts' Integrated package but from what I can see this seems to have been abandoned as functionality has moved into Laravel core.

How are others implementing Selenium in their projects?

Any tips on how I can set this up?

0 likes
4 replies
bencarter78@hotmail.com's avatar

Thanks for that @tomi, looks good. One thing that I would like to do is use the 'actingAs' helper so my tests don't have to go to the auth page on each request. Is there a way to achieve this? The package you suggested doesn't include this method.

Any ideas?

tomopongrac's avatar

Yes, the package does not include that method ... honestly i don't have any idea how to achieve that... maybe someone else have a idea...

zachleigh's avatar

As far as I know, the only way to make an actingAs method in Selenium tests is to make a frontend routine to follow. So go to login page, fill out form, click 'login' etc. Even if you pull in all the Laravel stuff and login your user that way, your test laravel build will not be the same as the build in the browser.

2 likes

Please or to participate in this conversation.