--> -->
#blog2navi() *Laravel5.4+php5.6でduskをセットアップする [#eb5f67cf] ~Laravel5.4+php5.6の環境にdusk入れるメモです。 ~[[公式:https://readouble.com/laravel/5.4/ja/dusk.html]]をはじめ、詳しく導入手順を書いてあるのですが、いろいろと上手くいかない点があったのでメモ・・・(._.)φ ~ + phpのバージョン問題~ 公式の導入手順ではインストール時に以下をしろと書いてあります。 composer require --dev laravel/dusk しかし、現在duskの最新は2.0系で、これは(正確には依存パッケージが)php7.1.3以上を必要とします。そのため以下のエラーが出ます。 Problem 1 - laravel/dusk v2.0.0 requires illuminate/support ~5.5 -> satisfiable by illuminate/support[v5.5.0, v5.5.16... : - illuminate/support v5.7.9 requires php ^7.1.3 -> your PHP version (5.6.37) does not satisfy that requirement. dusk本体ではなく、依存関係のあるパッケージがphp7.1.3を要求するようです。~ そこで、duskのバージョンを指定して導入します。 composer require --dev laravel/dusk:~1.0 ~ + $this->app->environment()問題~ 次に、&inlinecode{app/Providers/AppServiceProvider.php};に以下を追加するとあります。 #code(php){{ if ($this->app->environment('local', 'testing')) { $this->app->register(DuskServiceProvider::class); } }} しかし、何故か手元の5.4.36では&inlinecode{$this->app->environment()};という関数がありません。そこで、localとtestingをそれぞれの関数でチェックするように書き換えました。 #code(php){{ if (app()->isLocal() and app()->runningUnitTests()) { $this->app->register(DuskServiceProvider::class); } }} ~ + artisanコマンド登録問題~ さらに、テスト実装のディレクトリ構造を生成するため、&inlinecode{artisan duke:install};を実行しろとあります。しかしこれがまた以下のエラーが出て実行できません。 >php artisan dusk:install There are no commands defined in the "dusk" namespace. artisan listなどしてみると、コマンドが登録されていないようです。仕方が無いので、手動で&inlinecode{app/console/kernel.php};に追記して登録します。 #code(php){{ namespace App\Console; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; use Laravel\Dusk\Console\DuskCommand; use Laravel\Dusk\Console\InstallCommand; use Laravel\Dusk\Console\MakeCommand; class Kernel extends ConsoleKernel { /** * The Artisan commands provided by your application. * * @var array */ protected $commands = [ DuskCommand::class, InstallCommand::class, MakeCommand::class, ]; : }} これでコマンドが通るようになりました。 >php artisan dusk:install Dusk scaffolding installed successfully. ~ + TTY mode is not supported on Windows platform.問題~ テストを実行しようとすると、 TTY mode is not supported on Windows platform. というメッセージが出て実行されません。 これは、[[こちらのページ:https://github.com/laravel/dusk/pull/13/files]]を参考に、ソースを修正します。~ chromeの実行は、公式サイトにも書かれている[[ChromeDriver:https://sites.google.com/a/chromium.org/chromedriver/home]]を落としてきて、ファイル名を変更して、&inlinecode{vendor\laravel\dusk\bin\chromedriver-win.exe};に置きます。~ ~ すると、php artisan dusk で自動的にchromeが立ち上がり、画面遷移しながら試験を実施してくれます。すごーい(笑)~ ~ ~※追記:これはdusk1.0の場合のようです。1.1ではwindows対応されています。chromedriver-win.exeを上記のディレクトリに配置すればソースを修正しなくても実行できます。 ~ ~でも、昔に比べてパッケージ管理が発達してしているのに、どうしてこういう違いが出てくるんでしょうね・・・。 #htmlinsert(twitterbutton.html) #hr #htmlinsert(20181115_duskin.html) RIGHT:Category: [[[Linux>日記/Category/Linux]]] - 21:28:03 ---- RIGHT:&blog2trackback(); #comment(above) #blog2navi()