如何扩展Laravel Dusk浏览器?

时间:2019-06-23 00:33:55

标签: laravel laravel-dusk

我希望重写\ Laravel \ Dusk \ Browser方法,并用我自己的方法扩展它,并进行一些增强。这是我到目前为止所做的,但它给了我这个错误:

  

TypeError:传递给Tests \ Browser \ SequentialAppTest :: Tests \ Browser {closure}()的参数1必须是Tests \ MyBrowser的实例,是Laravel \ Dusk \ Browser的实例,
  呼入   /var/www/gtest/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php上   第67行

     

/var/www/gtest/tests/Browser/SequentialAppTest.php:135   /var/www/gtest/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:67   /var/www/gtest/tests/Browser/SequentialAppTest.php:157

文件:tests / MyBrowser.php

<?php

namespace Tests;

class MyBrowser extends \Laravel\Dusk\Browser 
{

}

文件:tests / Browser / SequentialAppTest.php     命名空间Tests \ Browser;

use Tests\DuskTestCase;
use Tests\MyBrowser as Browser;

...

class SequentialAppTest extends DuskTestCase 
{
 ....
}

1 个答案:

答案 0 :(得分:1)

在测试或newBrowser()中覆盖DuskTestCase

use Tests\DuskTestCase;
use Tests\MyBrowser as Browser;

class SequentialAppTest extends DuskTestCase 
{
    protected function newBrowser($driver)
    {
        return new Browser($driver);
    }
}