Skip to content

Commit

Permalink
[7.x] Remove chrome binaries (#873)
Browse files Browse the repository at this point in the history
* Remove chrome binaries

* Ignore chrome binaries

* Apply fixes from StyleCI (#872)

* Only install OS binary

* Orchestra 7.0

* Update testbench dependency

* Attempt at fixing tests

* Apply fixes from StyleCI (#875)

* Fix tests

* Fix tests
  • Loading branch information
driesvints authored Feb 15, 2021
1 parent 50a1648 commit 9a41812
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 49 deletions.
1 change: 1 addition & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chromedriver-*
Binary file removed bin/chromedriver-linux
Binary file not shown.
Binary file removed bin/chromedriver-mac
Binary file not shown.
Binary file removed bin/chromedriver-win.exe
Binary file not shown.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
},
"require-dev": {
"mockery/mockery": "^1.4.2",
"phpunit/phpunit": "^9.0|^10"
"phpunit/phpunit": "^9.0|^10",
"orchestra/testbench": "dev-phpunit10"
},
"suggest": {
"ext-pcntl": "Used to gracefully terminate Dusk when tests are running."
Expand Down
30 changes: 16 additions & 14 deletions src/Chrome/ChromeProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ChromeProcess
/**
* The path to the Chromedriver.
*
* @var string
* @var string|null
*/
protected $driver;

Expand All @@ -20,36 +20,38 @@ class ChromeProcess
*
* @param string $driver
* @return void
*
* @throws \RuntimeException
*/
public function __construct($driver = null)
{
$this->driver = $driver;

if (! is_null($driver) && realpath($driver) === false) {
throw new RuntimeException("Invalid path to Chromedriver [{$driver}].");
}
}

/**
* Build the process to run Chromedriver.
*
* @param array $arguments
* @return \Symfony\Component\Process\Process
*
* @throws \RuntimeException
*/
public function toProcess(array $arguments = [])
{
if ($this->driver) {
return $this->process($arguments);
}

if ($this->onWindows()) {
$this->driver = realpath(__DIR__.'/../../bin/chromedriver-win.exe');
$driver = $this->driver;
} elseif ($this->onWindows()) {
$driver = __DIR__.'/../../bin/chromedriver-win.exe';
} elseif ($this->onMac()) {
$this->driver = realpath(__DIR__.'/../../bin/chromedriver-mac');
$driver = __DIR__.'/../../bin/chromedriver-mac';
} else {
$this->driver = realpath(__DIR__.'/../../bin/chromedriver-linux');
$driver = __DIR__.'/../../bin/chromedriver-linux';
}

$this->driver = realpath($driver);

if ($this->driver === false) {
throw new RuntimeException(
"Invalid path to Chromedriver [{$driver}]. Make sure to install the Chromedriver first by running the dusk:chrome-driver command."
);
}

return $this->process($arguments);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function handle()

$this->comment('Downloading ChromeDriver binaries...');

$driverCommandArgs = ['--all' => true];
$driverCommandArgs = [];

if ($this->option('proxy')) {
$driverCommandArgs['--proxy'] = $this->option('proxy');
Expand Down
28 changes: 16 additions & 12 deletions tests/ChromeProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,35 @@ public function test_build_process_with_custom_driver()

public function test_build_process_for_windows()
{
$process = (new ChromeProcessWindows)->toProcess();

$this->assertInstanceOf(Process::class, $process);
$this->assertStringContainsString('chromedriver-win.exe', $process->getCommandLine());
try {
(new ChromeProcessWindows)->toProcess();
} catch (RuntimeException $exception) {
$this->assertStringContainsString('chromedriver-win.exe', $exception->getMessage());
}
}

public function test_build_process_for_darwin()
{
$process = (new ChromeProcessDarwin)->toProcess();

$this->assertInstanceOf(Process::class, $process);
$this->assertStringContainsString('chromedriver-mac', $process->getCommandLine());
try {
(new ChromeProcessDarwin)->toProcess();
} catch (RuntimeException $exception) {
$this->assertStringContainsString('chromedriver-mac', $exception->getMessage());
}
}

public function test_build_process_for_linux()
{
$process = (new ChromeProcessLinux)->toProcess();

$this->assertInstanceOf(Process::class, $process);
$this->assertStringContainsString('chromedriver-linux', $process->getCommandLine());
try {
(new ChromeProcessLinux)->toProcess();
} catch (RuntimeException $exception) {
$this->assertStringContainsString('chromedriver-linux', $exception->getMessage());
}
}

public function test_invalid_path()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Invalid path to Chromedriver [/not/a/valid/path]. Make sure to install the Chromedriver first by running the dusk:chrome-driver command.');

(new ChromeProcess('/not/a/valid/path'))->toProcess();
}
Expand Down
29 changes: 29 additions & 0 deletions tests/Concerns/SwapsUrlGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Laravel\Dusk\Tests\Concerns;

use Illuminate\Container\Container;
use Illuminate\Http\Request;
use Illuminate\Routing\RouteCollection;
use Illuminate\Routing\UrlGenerator;

trait SwapsUrlGenerator
{
protected function swapUrlGenerator()
{
Container::getInstance()->bind('url', function () {
return new class(new RouteCollection(), new Request()) extends UrlGenerator {
public function route($name, $parameters = [], $absolute = true)
{
$route = '/'.$name.'/'.implode('/', $parameters);

if ($absolute) {
$route = 'http://www.google.com'.$route;
}

return $route;
}
};
});
}
}
8 changes: 7 additions & 1 deletion tests/ElementResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

class ElementResolverTest extends TestCase
{
protected function tearDown(): void
{
m::close();
}

/**
* @throws \Exception
*/
Expand Down Expand Up @@ -65,10 +70,11 @@ public function test_resolve_for_radio_selection_falls_back_to_selectors_without
public function test_resolve_for_radio_selection_throws_exception_without_id_and_without_value()
{
$driver = m::mock(stdClass::class);
$driver->shouldReceive('findElement')->once()->andReturn('foo');
$resolver = new ElementResolver($driver);

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('No value was provided for radio button [foo].');

$resolver->resolveForRadioSelection('foo');
}

Expand Down
9 changes: 7 additions & 2 deletions tests/MakesAssertionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

class MakesAssertionsTest extends TestCase
{
protected function tearDown(): void
{
m::close();
}

public function test_assert_title()
{
$driver = m::mock(stdClass::class);
Expand Down Expand Up @@ -875,7 +880,7 @@ public function test_assert_vue()
'? JSON.parse(JSON.stringify(el.__vueParentComponent.ctx)).foo'.
': el.__vue__.foo'
)
->once()
->twice()
->andReturn('foo');

$resolver = m::mock(stdClass::class);
Expand Down Expand Up @@ -928,7 +933,7 @@ public function test_assert_vue_is_not()
'? JSON.parse(JSON.stringify(el.__vueParentComponent.ctx)).foo'.
': el.__vue__.foo'
)
->once()
->twice()
->andReturn('foo');

$resolver = m::mock(stdClass::class);
Expand Down
18 changes: 13 additions & 5 deletions tests/MakesUrlAssertionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@
namespace Laravel\Dusk\Tests;

use Laravel\Dusk\Browser;
use Laravel\Dusk\Tests\Concerns\SwapsUrlGenerator;
use Mockery as m;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\TestCase;
use stdClass;

class MakesUrlAssertionsTest extends TestCase
{
use SwapsUrlGenerator;

protected function tearDown(): void
{
m::close();
}

public function test_assert_url_is()
{
$driver = m::mock(stdClass::class);
$driver->shouldReceive('getCurrentURL')->once()->andReturn(
$driver->shouldReceive('getCurrentURL')->times(8)->andReturn(
'http://www.google.com?foo=bar',
'http://www.google.com:80/test?foo=bar'
);
Expand All @@ -37,7 +45,7 @@ public function test_assert_url_is()
public function test_assert_scheme_is()
{
$driver = m::mock(stdClass::class);
$driver->shouldReceive('getCurrentURL')->once()->andReturn(
$driver->shouldReceive('getCurrentURL')->times(5)->andReturn(
'http://www.google.com?foo=bar',
'https://www.google.com:80/test?foo=bar',
'ftp://www.google.com',
Expand Down Expand Up @@ -89,7 +97,7 @@ public function test_assert_scheme_is_not()
public function test_assert_host_is()
{
$driver = m::mock(stdClass::class);
$driver->shouldReceive('getCurrentURL')->once()->andReturn(
$driver->shouldReceive('getCurrentURL')->times(4)->andReturn(
'http://www.google.com?foo=bar',
'http://google.com?foo=bar',
'https://www.laravel.com:80/test?foo=bar',
Expand Down Expand Up @@ -141,7 +149,7 @@ public function test_assert_host_is_not()
public function test_assert_port_is()
{
$driver = m::mock(stdClass::class);
$driver->shouldReceive('getCurrentURL')->once()->andReturn(
$driver->shouldReceive('getCurrentURL')->times(4)->andReturn(
'http://www.laravel.com:80/test?foo=bar',
'https://www.laravel.com:443/test?foo=bar',
'https://www.laravel.com',
Expand Down Expand Up @@ -262,7 +270,7 @@ public function test_assert_path_is_not()

public function test_assert_route_is()
{
require_once __DIR__.'/stubs/route.php';
$this->swapUrlGenerator();

$driver = m::mock(stdClass::class);
$driver->shouldReceive('getCurrentURL')->andReturn(
Expand Down
5 changes: 5 additions & 0 deletions tests/ProvidesBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class ProvidesBrowserTest extends TestCase
{
use ProvidesBrowser;

protected function tearDown(): void
{
m::close();
}

/**
* @dataProvider testData
*/
Expand Down
15 changes: 14 additions & 1 deletion tests/SupportsChromeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
namespace Laravel\Dusk\Tests;

use Laravel\Dusk\Chrome\SupportsChrome;
use PHPUnit\Framework\TestCase;
use Laravel\Dusk\DuskServiceProvider;
use Orchestra\Testbench\TestCase;

class SupportsChromeTest extends TestCase
{
use SupportsChrome;

protected function setUp(): void
{
parent::setUp();

$this->artisan('dusk:chrome-driver');
}

public function test_it_can_run_chrome_process()
{
$process = static::buildChromeProcess();
Expand All @@ -23,4 +31,9 @@ public function test_it_can_run_chrome_process()
$this->assertStringContainsString('Starting ChromeDriver', $process->getOutput());
$this->assertSame('', $process->getErrorOutput());
}

public function getPackageProviders($app)
{
return [DuskServiceProvider::class];
}
}
10 changes: 10 additions & 0 deletions tests/WaitsForElementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

use Facebook\WebDriver\Exception\TimeOutException;
use Laravel\Dusk\Browser;
use Laravel\Dusk\Tests\Concerns\SwapsUrlGenerator;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use stdClass;

class WaitsForElementsTest extends TestCase
{
use SwapsUrlGenerator;

protected function tearDown(): void
{
m::close();
}

public function test_default_wait_time()
{
Browser::$waitSeconds = 2;
Expand Down Expand Up @@ -77,6 +85,8 @@ public function test_can_wait_for_location()

public function test_can_wait_for_route()
{
$this->swapUrlGenerator();

$driver = m::mock(stdClass::class);
$driver->shouldReceive('executeScript')->with("return window.location.pathname == '/home/';")->andReturnTrue();
$browser = new Browser($driver);
Expand Down
12 changes: 0 additions & 12 deletions tests/stubs/route.php

This file was deleted.

0 comments on commit 9a41812

Please sign in to comment.