0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Laravelでブラウザテストを試してみる

Posted at

Laravelでブラウザテストを試してみる。

環境

  • Laravel 5.5

手順

laravel duskの追加

composer require --dev laravel/dusk:"^2.0"
php artisan dusk:install

サンプルテストの確認

tests/Browser/
配下にExampleTest.phpが作成されている

<?php

namespace Tests\Browser;

use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;

class ExampleTest extends DuskTestCase
{
    /**
     * A basic browser test example.
     *
     * @return void
     */
    public function testBasicExample()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/')
                    ->assertSee('Laravel');
        });
    }
}
  • /のURLにアクセスして、Laravelという文字があればOK。となる。
  • この/でアクセスされる画面はresources/views/welcome.blade.phpになっている。

.envを修正

ここで詰まった。ポート番号を指定していないと、テスト結果がFalseになるみたいなので修正。

APP_URL=http://localhost:8000

テスト開始

php artisan serve
php artisan dusk

PHPUnit 6.5.13 by Sebastian Bergmann and contributors.

.                                                                   1 / 1 (100%)

Time: 1.88 seconds, Memory: 10.00MB

OK (1 test, 1 assertion)

成功!

参考

https://readouble.com/laravel/5.5/ja/dusk.html
https://stackoverflow.com/questions/46507791/laravel-5-5-dusk-could-not-work

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?