Laravel¿ª·¢£ºÔõÑùʹÓÃLaravel Dusk¾ÙÐÐ×Ô¶¯»¯UI²âÊÔ£¿
Ëæ×ÅwebÓ¦ÓóÌÐòµÄÉú³¤£¬²âÊÔ×Ô¶¯»¯ÒѾ³ÉΪһ¸ö²»¿É»òȱµÄÔªËØ¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«Ì½ÌÖlaravel dusk£¬ÕâÊÇlaravel¿ò¼ÜµÄÒ»¸ö¹¦Ð§Ç¿Ê¢µÄ¹¤¾ß£¬ÓÃÓÚ×Ô¶¯»¯ui²âÊÔ¡£ laravel duskÌṩÁËÒ»¸ö¼òÆÓµÄapiÀ´ÔËÐÐÎÞÍ·ä¯ÀÀÆ÷£¬Í¨¹ýÄ£ÄâÓû§½»»¥£¬ÑéÖ¤ÄúµÄwebÓ¦ÓóÌÐòÊÇ·ñƾ֤ԤÆÚÊÂÇé¡£
ʹÓÃLaravel Dusk¾ÙÐÐ×Ô¶¯»¯UI²âÊÔµÄÀûÒæÊÇʲô£¿
¿ìËÙ¶ø¿É¿¿µÄ²âÊÔ£ºLaravel DuskÊÇÒ»¸ö¿ìËÙ¶ø¿É¿¿µÄ²âÊÔ¹¤¾ß£¬Ö¼ÔÚʹ²âÊÔÖÜÆÚËõ¶Ì£¬Í¬Ê±¼ò»¯²âÊÔ»ù´¡¼Ü¹¹¡£
¸üºÃµÄ²âÊÔÁýÕÖ¹æÄ££ºÊ¹ÓÃLaravel Dusk¿ÉÒÔ²âÊÔÄúµÄÓ¦ÓóÌÐòµÄÐí¶à·½Ã棬ÀýÈç±íµ¥ÑéÖ¤¡¢Óû§²Ù×÷ºÍÉí·ÝÑéÖ¤µÈ¡£
Ä£ÄâÏÖÊÊÓû§½»»¥£ºLaravel Duskͨ¹ýÄ£ÄâÏÖÊÊÓû§½»»¥À´²âÊÔÓ¦ÓóÌÐò£¬Òò´ËÄú¿ÉÒÔÈ·±£ÄúµÄÓ¦ÓóÌÐòÏÖʵÉÏÕýÔÚƾ֤ԤÆڵķ½·¨ÊÂÇé¡£
Çé¾³»¯²âÊÔ£ºÄú¿ÉÒÔͨ¹ý²î±ðµÄÇé¾³À´Ö´ÐвâÊÔ¡£ÕâÒâζ×ÅÄú¿ÉÒÔ²âÊÔ¶àÖÖ²î±ðµÄ¼Æ»®£¬ÀýÈç²âÊÔÌض¨µÄÍøÒ³¡¢²âÊÔ²î±ðµÄÓû§½ÇÉ«ºÍȨÏ޵ȡ£
½ÓÏÂÀ´£¬ÈÃÎÒÃÇ¿´Ò»ÏÂÔõÑùÔÚLaravelÖÐʹÓÃLaravel Dusk¾ÙÐÐ×Ô¶¯»¯UI²âÊÔ¡£
ÏȾöÌõ¼þ£º
Laravel 5.4»ò¸ü¸ß°æ±¾
PHP 7.0»ò¸ü¸ß°æ±¾
°ì·¨1£º×°ÖÃLaravel Dusk
Laravel DuskÊÇLaravel¿ò¼ÜµÄÒ»²¿·Ö£¬Òò´ËÎÒÃÇÐèÒªÏÈ×°ÖÃLaravel¿ò¼Ü¡£Òª×°ÖÃLaravel¿ò¼Ü£¬ÇëÔËÐÐÒÔÏÂÏÂÁ
$ composer create-project --prefer-dist laravel/laravel project-name
µÇ¼ºó¸´ÖÆ
½ÓÏÂÀ´£¬ÎÒÃÇÐèҪͨ¹ýÔËÐÐÒÔÏÂÏÂÁîÀ´×°ÖÃLaravel Dusk£º
$ composer require --dev laravel/dusk
µÇ¼ºó¸´ÖÆ
°ì·¨2£ºÉèÖÃDusk
Ò»µ©Äú×°ÖÃÁËLaravel Dusk£¬Äú¾ÍÐèÒªÖ´Ðм¸¸öÉèÖð취²Å»ª×îÏȲâÊÔ¡£
Ê×ÏÈ£¬DuskÐèÒªÒ»¸ö.env.dusk.localÎļþ£¬¸ÃÎļþÊÇÒ»¸ö.envÎļþµÄÑÓÉ죬ÆäÖаüÀ¨ÓÃÓÚ²âÊÔµÄÇéÐαäÁ¿¡£Äú¿ÉÒÔͨ¹ýÒÔÏ·½·¨½¨Éè.env.dusk.localÎļþ£º
$ cp .env .env.dusk.local
µÇ¼ºó¸´ÖÆ
¸ü¸Ä.env.dusk.localÎļþÖеÄÄÚÈÝÒÔÖª×ãÄúµÄ²âÊÔÐèÇó¡£
Laravel Dusk»¹ÐèÒªÒ»¸öSQLiteÊý¾Ý¿âÀ´´æ´¢²âÊÔʱ´úʹÓõÄÊý¾Ý¡£Äú¿ÉÒÔͨ¹ýÖ´ÐÐÒÔÏÂÏÂÁîÀ´½¨ÉèÊý¾Ý¿â£º
$ touch database/database.sqlite
µÇ¼ºó¸´ÖÆ
×îºó£¬ÇëÔÚÄúµÄAppServiceProviderÖÐ×¢²á»á¼ûÆ÷£¬¸Ã»á¼ûÆ÷ָʾDuskʹÓÃPHPUnitµÄChromeDriver¡£
public function register() { if ($this->app->environment('local', 'testing')) { $this->app->register(DuskServiceProvider::class); } }
µÇ¼ºó¸´ÖÆ
°ì·¨3£º±àд²âÊÔ
ÏÖÔÚ£¬Äú¿ÉÒÔ×îÏȱàдÄúµÄµÚÒ»¸öDusk²âÊÔ¡£Òª±àд²âÊÔ£¬Ç뽨ÉèÒ»¸ötests/BrowserĿ¼£¬ÔÚÆäÖн¨ÉèÒ»¸öеÄä¯ÀÀÆ÷²âÊÔÀà¡£
ʹÓÃArtisanÖÆÔìÆ÷¿ÉÒÔÀû±ã½¨Éè¸ÃÎļþ£¬ÔËÐÐÒÔÏÂÏÂÁ
$ php artisan dusk:make LoginTest
µÇ¼ºó¸´ÖÆ
ÔËÐдËÏÂÁ½¨ÉèÒ»¸öÃûΪLoginTest.phpµÄвâÊÔÀàÎļþ£¬Çëƾ֤ÒÔÏÂʾÀý´úÂë¸üдËÎļþ£º
<?php namespace TestsBrowser; use LaravelDuskBrowser; use TestsDuskTestCase; class LoginTest extends DuskTestCase { /** * A Dusk test example. * * @return void */ public function testLogin() { $this->browse(function (Browser $browser) { $browser->visit('/login') ->type('email', 'example@domain.com') ->type('password', 'password') ->press('Login') ->assertPathIs('/home'); }); } }
µÇ¼ºó¸´ÖÆ
¸ÃʾÀý²âÊÔÔÚChromeä¯ÀÀÆ÷Öз¿ªÍâµØÓ¦ÓóÌÐò£¬È»ºóÔڵǼҳÃæÊäÈëʾÀýÊý¾Ý£¬µã»÷µÇ¼°´Å¥£¬È»ºóÑéÖ¤Öض¨Ïò·¾¶ÊÇ·ñΪ¡°/home¡±¡£
×îºó£¬ÔËÐÐÒÔÏÂÏÂÁîÀ´ÔËÐвâÊÔ£º
php artisan dusk
µÇ¼ºó¸´ÖÆ
¹§Ï²£¡ÄúÏÖÔÚÒѾÍê³ÉÁËLaravel DuskµÄÈëÃŽ̡̳£Ê¹ÓÃLaravel Dusk£¬¿ÉÒÔÇáËɵرàд×Ô¶¯»¯UI²âÊÔ£¬ÒÔÈ·±£ÄúµÄÓ¦ÓóÌÐòƾ֤ԤÆڵķ½·¨ÊÂÇé¡£
ÒÔÉϾÍÊÇLaravel¿ª·¢£ºÔõÑùʹÓÃLaravel Dusk¾ÙÐÐ×Ô¶¯»¯UI²âÊÔ£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡