DuskTestCase.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Dcat\Admin\Tests;
  3. use Dcat\Admin\Models\Administrator;
  4. use Facebook\WebDriver\Chrome\ChromeOptions;
  5. use Facebook\WebDriver\Remote\DesiredCapabilities;
  6. use Facebook\WebDriver\Remote\RemoteWebDriver;
  7. use Laravel\Dusk\Browser;
  8. use Laravel\Dusk\TestCase as BaseTestCase;
  9. abstract class DuskTestCase extends BaseTestCase
  10. {
  11. use CreatesApplication;
  12. /**
  13. * @var Administrator
  14. */
  15. protected $user;
  16. protected $login = true;
  17. public function login(Browser $browser)
  18. {
  19. $browser->loginAs($this->getUser(), 'admin');
  20. }
  21. public function setUp(): void
  22. {
  23. parent::setUp();
  24. $this->boot();
  25. }
  26. public function tearDown(): void
  27. {
  28. $this->destory();
  29. parent::tearDown();
  30. }
  31. /**
  32. * Prepare for Dusk test execution.
  33. *
  34. * @beforeClass
  35. *
  36. * @return void
  37. */
  38. public static function prepare()
  39. {
  40. static::startChromeDriver();
  41. }
  42. /**
  43. * Create the RemoteWebDriver instance.
  44. *
  45. * @return \Facebook\WebDriver\Remote\RemoteWebDriver
  46. */
  47. protected function driver()
  48. {
  49. $options = (new ChromeOptions())->addArguments([
  50. '--disable-gpu',
  51. '--headless',
  52. '--window-size=1920,1080',
  53. ]);
  54. return RemoteWebDriver::create(
  55. 'http://localhost:9515',
  56. DesiredCapabilities::chrome()->setCapability(
  57. ChromeOptions::CAPABILITY,
  58. $options
  59. )
  60. );
  61. }
  62. }