Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

use Facebook\WebDriver\WebDriver;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverCapabilities;
use Facebook\WebDriver\WebDriverExpectedCondition;
use Panthere\Cookie\CookieJar;
use Panthere\DomCrawler\Crawler;
use Panthere\DomCrawler\Form as PanthereForm;
use Panthere\DomCrawler\Link as PanthereLink;
use Panthere\ProcessManager\BrowserManagerInterface;
use Panthere\ProcessManager\ChromeManager;
use Panthere\ProcessManager\SeleniumManager;
use Symfony\Component\BrowserKit\Client as BaseClient;
use Symfony\Component\BrowserKit\Request;
use Symfony\Component\BrowserKit\Response;
Expand Down Expand Up @@ -49,6 +51,11 @@ public static function createChromeClient(?string $chromeDriverBinary = null, ?a
return new self(new ChromeManager($chromeDriverBinary, $arguments));
}

public static function createSeleniumClient(?string $host = null, ?WebDriverCapabilities $capabilities = null): self
{
return new self(new SeleniumManager($host, $capabilities));
}

public function __construct(BrowserManagerInterface $browserManager)
{
$this->browserManager = $browserManager;
Expand Down
49 changes: 49 additions & 0 deletions src/ProcessManager/SeleniumManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the Panthère project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Panthere\ProcessManager;

use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriver;
use Facebook\WebDriver\WebDriverCapabilities;

/**
* @author Dmitry Kuzmin <rockwith@me.com>
*/
final class SeleniumManager implements BrowserManagerInterface
{
private $host;
private $capabilities;

public function __construct(
?string $host = 'http://127.0.0.1:4444/wd/hub',
?WebDriverCapabilities $capabilities = null
) {
$this->host = $host;
$this->capabilities = $capabilities ?? DesiredCapabilities::chrome();
}

public function start(): WebDriver
{
return RemoteWebDriver::create(
$this->host,
$this->capabilities
);
}

public function quit(): void
{
// nothing
}
}
53 changes: 53 additions & 0 deletions tests/ProcessManager/SeleniumManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* This file is part of the Panthère project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Panthere\Tests\ProcessManager;

use Facebook\WebDriver\Chrome\ChromeOptions;
use Panthere\ProcessManager\ChromeManager;
use Panthere\ProcessManager\SeleniumManager;
use PHPUnit\Framework\TestCase;

/**
* @author Dmitry Kuzmin <rockwith@me.com>
*/
class SeleniumManagerTest extends TestCase
{
/**
* we can mock selenium with built-in ChromeManager.
*
* @var ChromeManager
*/
protected $chromeMockManager;

public function setUp(): void
{
$this->chromeMockManager = new ChromeManager();
$this->chromeMockManager->start();
}

public function tearDown(): void
{
$this->chromeMockManager->quit();
}

public function testRun()
{
$co = new ChromeOptions();
$co->addArguments(['--headless', 'window-size=1200,1100', '--disable-gpu', '--no-sandbox']);
$manager = new SeleniumManager('http://localhost:9515', $co->toCapabilities());
$client = $manager->start();
$this->assertNotEmpty($client->getCurrentURL());
$manager->quit();
}
}