Completed
Push — dev ( 39ba5f...0b8cdb )
by Tristan
04:57 queued 04:51
created

DuskTestCase::driver()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 16
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Tests;
4
5
use Laravel\Dusk\TestCase as BaseTestCase;
6
use Facebook\WebDriver\Chrome\ChromeOptions;
7
use Facebook\WebDriver\Remote\RemoteWebDriver;
8
use Facebook\WebDriver\Remote\DesiredCapabilities;
9
use Laravel\Dusk\Browser;
10
11
abstract class DuskTestCase extends BaseTestCase
12
{
13
    use CreatesApplication;
14
15
    /**
16
     * Prepare for Dusk test execution.
17
     *
18
     * @beforeClass
19
     * @return void
20
     */
21
    public static function prepare()
22
    {
23
        static::startChromeDriver();
24
25
        // Use scrollTo macro if element is off the browser screen
26
        // Example: clicking a button that's below the visible content will eroor
27
        Browser::macro('scrollTo', function($selector) {
28
            $this->driver->executeScript("$(\"html, body\").animate({scrollTop: $(\"$selector\").offset().top}, 0);");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
Bug Best Practice introduced by
The property driver does not exist on Tests\DuskTestCase. Did you maybe forget to declare it?
Loading history...
29
            return $this;
30
        });
31
    }
32
33
    /**
34
     * Create the RemoteWebDriver instance.
35
     *
36
     * @return \Facebook\WebDriver\Remote\RemoteWebDriver
37
     */
38
    protected function driver()
39
    {
40
        $options = (new ChromeOptions)->addArguments([
0 ignored issues
show
Unused Code introduced by
The assignment to $options is dead and can be removed.
Loading history...
41
            '--disable-gpu',
42
            '--headless'
43
        ]);
44
45
        // Run tests inside Docker container
46
        switch (config('dusk.driver')) {
47
        case 'container':
48
            return RemoteWebDriver::create(
49
                'http://localhost:4444/wd/hub', DesiredCapabilities::chrome()
50
            );
51
        default: // local
52
            return RemoteWebDriver::create(
53
                'http://localhost:9515', DesiredCapabilities::chrome()
54
            );
55
        }
56
    }
57
}
58