Skip to content
Jeffrey Way edited this page Mar 28, 2015 · 6 revisions

Can I test JavaScript with this package?

Yes, but you'll need to extend the Selenium extension that is included with this package.

<?php

use Laracasts\Integrated\Extensions\Selenium;

class SeleniumTest extends Selenium
{
    /** @test */
    public function it_sees_alert_box()
    {
        $this->visit('/some-page')
             ->andSeeInAlert('I am an alert box.');
    }
}

Note: Don't forget to install Selenium Stand-Alone server for your OS, and start it up. If you wish, you may download it to your current project, and then run:

java -jar selenium-server-standalone-2.45.0.jar

You could always save this to an alias, so that you can simply type selenium.

Please note that the Selenium extension is still, somewhat, in the early stages. If you have additional functionality that you require, please open an issue and we can discuss extending the API.

Can I create my own helper methods?

Of course! Just be sure to return $this from your method. Here's an example of a registration method (which uses the Laravel extension).

class ExampleTest extends TestCase
{
    /** @test */
    public function it_registers_a_user()
    {
        $this->register(['username' => 'John'])
             ->andSee('Welcome, John!')
             ->onPage('/home');
    }

    protected function register($overrides)
    {
        $user = TestDummy::attributesFor('App\User', $overrides);

        return $this->visit('auth/register')
                    ->submitForm('Register', $user);
    }
}
Clone this wiki locally