diff --git a/.gitignore b/.gitignore index 1bfac7f..1021153 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /vendor/ -*~ \ No newline at end of file +*~ +.idea/ \ No newline at end of file diff --git a/.idea/composerJson.xml b/.idea/composerJson.xml new file mode 100644 index 0000000..4199499 --- /dev/null +++ b/.idea/composerJson.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/deployment.xml b/.idea/deployment.xml new file mode 100644 index 0000000..7d69a67 --- /dev/null +++ b/.idea/deployment.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..7acf5b2 --- /dev/null +++ b/.php_cs @@ -0,0 +1,19 @@ + +This source file is subject to the MIT license that is bundled +with this source code in the file LICENSE. +EOF; + +$finder = PhpCsFixer\Finder::create() + ->in([__DIR__ . '/src', __DIR__ . '/Tests']); + +return PhpCsFixer\Config::create() + ->setRules([ + '@PSR2' => true, + 'header_comment' => [ + 'header' => $header + ], + ]) + ->setFinder($finder); \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f22e078 --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +## Selenium Tor Implementation for [facebook/php-webdriver](https://github.com/facebook/php-webdriver) + +### Usage + +#### Install Composer + +* `curl -SsL https://getcomposer.org/installer|php` +* `mv composer.phar /usr/local/bin/composer` + +#### Get the code + +* Clone the repository `git clone https://repos.bgemi.net/sikofitt/selenium-tor` +* `cd selenium-tor` + +#### Install dependencies +* Then install the dependencies with `composer install` + +#### Get tor if you don't have it +* `composer download` or +* `bin/console tor:download` + +```php +use Sikofitt\WebDriver\FirefoxBinary; +use Sikofitt\WebDriver\Remote\DesiredCapabilities; +use Sikofitt\WebDriver\Tor\TorProfile; +use Sikofitt\WebDriver\TorLauncher; + + +require 'vendor/autoload.php'; + +$firefoxBinary = new FirefoxBinary(__DIR__ . '/../tor-browser_en-US/Browser/start-tor-browser'); +$caps = DesiredCapabilities::tor($firefoxBinary); +$profile = new TorProfile(); +$caps->setCapability('timeout', 3600); +$caps->setCapability(FirefoxDriver::PROFILE, $profile); + +$torProcess = TorLauncher::launch($firefoxBinary); +// Wait for Tor to connect +sleep(2); +$this->webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $caps); +$this->webDriver->navigate()->to('http://32b5oz2bbtn6gqj3.onion'); +// Or $this-webDriver->get('http://32b5oz2bbtn6gqj3.onion'); +$pageImages = $this->webDriver->findElements(WebDriverBy::tagName('img')); +$images = []; +foreach($pageImages as $image) +{ + $images[] = $image->getAttribute('src'); +} +TorLauncher::stop($torProcess); + +``` + +### Tests + +`composer test'` \ No newline at end of file diff --git a/Tests/FireFoxBinaryTest.php b/Tests/FireFoxBinaryTest.php new file mode 100644 index 0000000..16089a6 --- /dev/null +++ b/Tests/FireFoxBinaryTest.php @@ -0,0 +1,28 @@ + + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +use Sikofitt\WebDriver\FirefoxBinary; + +/** + * Created by PhpStorm. + * User: eric + * Date: 12/20/16 + * Time: 1:33 PM + */ +class FireFoxBinaryTest extends PHPUnit_Framework_TestCase +{ + + /** + * @expectedException \Exception + */ + public function testBinaryFail() + { + $fireFoxBinary = new FirefoxBinary('file'); + } +} diff --git a/Tests/GitHubTests.php b/Tests/GitHubTests.php deleted file mode 100644 index 81a795c..0000000 --- a/Tests/GitHubTests.php +++ /dev/null @@ -1,25 +0,0 @@ -webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', DesiredCapabilities::firefox()); - } - - public function tearDown() - { - $this->webDriver->quit(); - } - public function testGitHubHome() { - $this->webDriver->get($this->url); - $this->assertContains('GitHub', $this->webDriver->getTitle()); - } -} \ No newline at end of file diff --git a/Tests/SeleniumTorSimpleTest.php b/Tests/SeleniumTorSimpleTest.php new file mode 100644 index 0000000..90b0bcb --- /dev/null +++ b/Tests/SeleniumTorSimpleTest.php @@ -0,0 +1,67 @@ + + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +use Sikofitt\WebDriver\FirefoxBinary; +use Sikofitt\WebDriver\Remote\DesiredCapabilities; +use Sikofitt\WebDriver\Tor\TorProfile; +use Sikofitt\WebDriver\TorLauncher; + + +require 'vendor/autoload.php'; + +/** + * Class SeleniumTorTests + */ +class SeleniumTorSimpleTests extends PHPUnit_Framework_TestCase +{ + protected $webDriver; + protected $urls = [ + 'http://skunksworkedp2cg.onion/sites.html' => 'A list of onion sites ordered by hostname', + 'http://32b5oz2bbtn6gqj3.onion' => 'The Hidden Wiki', + ]; + + protected $process; + protected $torProcess; + + public function setUp() + { + $firefoxBinary = new FirefoxBinary(__DIR__ . '/../tor-browser_en-US/Browser/start-tor-browser'); + $caps = DesiredCapabilities::tor($firefoxBinary); + $profile = new TorProfile(); + $caps->setCapability('timeout', 3600); + $caps->setCapability(FirefoxDriver::PROFILE, $profile); + + $this->torProcess = TorLauncher::launch($firefoxBinary); + + // Wait for Tor to connect + sleep(2); + $this->webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $caps); + } + + public function tearDown() + { + $this->webDriver->quit(); + TorLauncher::stop($this->torProcess); + } + + + public function testOnionCoreSite() + { + foreach ($this->urls as $url => $title) { + $this->webDriver->navigate()->to($url); + $elements = $this->webDriver->findElements(WebDriverBy::tagName('img')); + $this->assertEquals($title, $this->webDriver->getTitle()); + $images = []; + foreach ($elements as $element) { + $images[] = $element->getAttribute('src'); + } + file_put_contents(__DIR__ . '/../' . 'data.json', json_encode($images, JSON_PRETTY_PRINT)); + } + } +} diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..06dd961 --- /dev/null +++ b/bin/console @@ -0,0 +1,18 @@ +#!/usr/bin/env php +add(new Sikofitt\Console\Command\TorBrowserDownloadCommand()); + +$app->run(); \ No newline at end of file diff --git a/composer.json b/composer.json index 415a813..8259e33 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,22 @@ { "require-dev": { "phpunit/phpunit": "*", - "facebook/webdriver": "^1.2", - "se/selenium-server-standalone": "~2" + "friendsofphp/php-cs-fixer": "^2.0" }, "require": { + "facebook/webdriver": "dev-master", + "se/selenium-server-standalone": "~2", + "guzzlehttp/guzzle": "^6.2", + "symfony/console": "^3.2", + "symfony/process": "^3.2" + }, + "autoload": { + "psr-4": { + "Sikofitt\\":"src/Sikofitt" } + }, + "scripts": { + "tests": "vendor/bin/phpunit", + "download":"php bin/console tor:download" + } } diff --git a/composer.lock b/composer.lock index 5dd2dce..c2c98ad 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,586 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "ecde7686e58544317cd07bc652dbb9c8", - "content-hash": "1247b0f750bb71ef5d87826c4b347753", - "packages": [], + "hash": "9adf3cf7906f0b5209fd592d4f1e55e2", + "content-hash": "54e275391a6e9e2bb1973efbc562ecd9", + "packages": [ + { + "name": "facebook/webdriver", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/facebook/php-webdriver.git", + "reference": "575600dfcfebad49fd0fc59d781b0696462a1f4e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/facebook/php-webdriver/zipball/575600dfcfebad49fd0fc59d781b0696462a1f4e", + "reference": "575600dfcfebad49fd0fc59d781b0696462a1f4e", + "shasum": "" + }, + "require": { + "php": ">=5.3.19" + }, + "require-dev": { + "phpdocumentor/phpdocumentor": "2.*", + "phpunit/phpunit": "3.7.*" + }, + "type": "library", + "autoload": { + "classmap": [ + "lib/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "description": "A php client for WebDriver", + "homepage": "https://github.com/facebook/php-webdriver", + "keywords": [ + "facebook", + "php", + "selenium", + "webdriver" + ], + "time": "2015-06-09 17:09:16" + }, + { + "name": "guzzlehttp/guzzle", + "version": "6.2.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ebf29dee597f02f09f4d5bbecc68230ea9b08f60", + "reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60", + "shasum": "" + }, + "require": { + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.3.1", + "php": ">=5.5" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.0", + "psr/log": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.2-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2016-10-08 15:01:37" + }, + { + "name": "guzzlehttp/promises", + "version": "v1.3.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2016-12-20 10:07:11" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.3.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/5c6447c9df362e8f8093bda8f5d8873fe5c7f65b", + "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "PSR-7 message implementation", + "keywords": [ + "http", + "message", + "stream", + "uri" + ], + "time": "2016-06-24 23:00:38" + }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06 14:39:51" + }, + { + "name": "psr/log", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10 12:19:37" + }, + { + "name": "se/selenium-server-standalone", + "version": "v2.53.1", + "source": { + "type": "git", + "url": "https://github.com/sveneisenschmidt/selenium-server-standalone.git", + "reference": "ef4eea9c99efb9c0e3084e9cae625662ccd43361" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sveneisenschmidt/selenium-server-standalone/zipball/ef4eea9c99efb9c0e3084e9cae625662ccd43361", + "reference": "ef4eea9c99efb9c0e3084e9cae625662ccd43361", + "shasum": "" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "bin": [ + "bin/selenium-server-standalone" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache 2.0" + ], + "authors": [ + { + "name": "Sven Eisenschmidt", + "email": "sven.eisenschmidt@gmail.com" + } + ], + "description": "Composer distribution of Selenium Server Standalone, the browser automation framework. Adds a executable to your composer bin directory.", + "homepage": "https://github.com/sveneisenschmidt/selenium-server-standalone", + "keywords": [ + "selenium", + "testing" + ], + "time": "2016-07-01 14:16:52" + }, + { + "name": "symfony/console", + "version": "v3.2.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "d12aa9ca20f4db83ec58410978dab6afcb9d6aaa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/d12aa9ca20f4db83ec58410978dab6afcb9d6aaa", + "reference": "d12aa9ca20f4db83ec58410978dab6afcb9d6aaa", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/debug": "~2.8|~3.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/event-dispatcher": "~2.8|~3.0", + "symfony/filesystem": "~2.8|~3.0", + "symfony/process": "~2.8|~3.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/filesystem": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "time": "2016-12-11 14:34:22" + }, + { + "name": "symfony/debug", + "version": "v3.2.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "9f923e68d524a3095c5a2ae5fc7220c7cbc12231" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug/zipball/9f923e68d524a3095c5a2ae5fc7220c7cbc12231", + "reference": "9f923e68d524a3095c5a2ae5fc7220c7cbc12231", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "psr/log": "~1.0" + }, + "conflict": { + "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2" + }, + "require-dev": { + "symfony/class-loader": "~2.8|~3.0", + "symfony/http-kernel": "~2.8|~3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Debug Component", + "homepage": "https://symfony.com", + "time": "2016-11-16 22:18:16" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/e79d363049d1c2128f133a2667e4f4190904f7f4", + "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2016-11-14 01:06:16" + }, + { + "name": "symfony/process", + "version": "v3.2.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "02ea84847aad71be7e32056408bb19f3a616cdd3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/02ea84847aad71be7e32056408bb19f3a616cdd3", + "reference": "02ea84847aad71be7e32056408bb19f3a616cdd3", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "https://symfony.com", + "time": "2016-11-24 10:40:28" + } + ], "packages-dev": [ { "name": "doctrine/instantiator", @@ -63,51 +640,69 @@ "time": "2015-06-14 21:17:01" }, { - "name": "facebook/webdriver", - "version": "1.2.0", + "name": "friendsofphp/php-cs-fixer", + "version": "v2.0.0", "source": { "type": "git", - "url": "https://github.com/facebook/php-webdriver.git", - "reference": "af21de3ae5306a8ca0bcc02a19735dadc43e83f3" + "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", + "reference": "f3baf72eb2f58bf275b372540f5b47d25aed910f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/facebook/php-webdriver/zipball/af21de3ae5306a8ca0bcc02a19735dadc43e83f3", - "reference": "af21de3ae5306a8ca0bcc02a19735dadc43e83f3", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/f3baf72eb2f58bf275b372540f5b47d25aed910f", + "reference": "f3baf72eb2f58bf275b372540f5b47d25aed910f", "shasum": "" }, "require": { - "ext-curl": "*", - "php": "^5.5 || ~7.0" + "ext-tokenizer": "*", + "php": "^5.3.6 || >=7.0 <7.2", + "sebastian/diff": "^1.1", + "symfony/console": "^2.3 || ^3.0", + "symfony/event-dispatcher": "^2.1 || ^3.0", + "symfony/filesystem": "^2.4 || ^3.0", + "symfony/finder": "^2.2 || ^3.0", + "symfony/polyfill-php54": "^1.0", + "symfony/process": "^2.3 || ^3.0", + "symfony/stopwatch": "^2.5 || ^3.0" + }, + "conflict": { + "hhvm": "<3.9" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^1.11", - "php-mock/php-mock-phpunit": "^1.1", - "phpunit/phpunit": "4.6.* || ~5.0", - "squizlabs/php_codesniffer": "^2.6" + "gecko-packages/gecko-php-unit": "^2.0", + "phpunit/phpunit": "^4.5|^5", + "satooshi/php-coveralls": "^1.0" }, - "suggest": { - "phpdocumentor/phpdocumentor": "2.*" + "bin": [ + "php-cs-fixer" + ], + "type": "application", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } }, - "type": "library", "autoload": { "psr-4": { - "Facebook\\WebDriver\\": "lib/" + "PhpCsFixer\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "Apache-2.0" + "MIT" ], - "description": "A PHP client for WebDriver", - "homepage": "https://github.com/facebook/php-webdriver", - "keywords": [ - "facebook", - "php", - "selenium", - "webdriver" + "authors": [ + { + "name": "Dariusz RumiƄski", + "email": "dariusz.ruminski@gmail.com" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } ], - "time": "2016-10-14 15:16:51" + "description": "A tool to automatically fix PHP code style", + "time": "2016-12-01 06:18:06" }, { "name": "myclabs/deep-copy", @@ -362,16 +957,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "4.0.3", + "version": "4.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "903fd6318d0a90b4770a009ff73e4a4e9c437929" + "reference": "c14196e64a78570034afd0b7a9f3757ba71c2a0a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/903fd6318d0a90b4770a009ff73e4a4e9c437929", - "reference": "903fd6318d0a90b4770a009ff73e4a4e9c437929", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c14196e64a78570034afd0b7a9f3757ba71c2a0a", + "reference": "c14196e64a78570034afd0b7a9f3757ba71c2a0a", "shasum": "" }, "require": { @@ -421,7 +1016,7 @@ "testing", "xunit" ], - "time": "2016-11-28 16:00:31" + "time": "2016-12-20 15:22:42" }, { "name": "phpunit/php-file-iterator", @@ -606,38 +1201,38 @@ }, { "name": "phpunit/phpunit", - "version": "5.5.4", + "version": "5.7.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "3e6e88e56c912133de6e99b87728cca7ed70c5f5" + "reference": "af91da3f2671006ff5d0628023de3b7ac4d1ef09" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3e6e88e56c912133de6e99b87728cca7ed70c5f5", - "reference": "3e6e88e56c912133de6e99b87728cca7ed70c5f5", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/af91da3f2671006ff5d0628023de3b7ac4d1ef09", + "reference": "af91da3f2671006ff5d0628023de3b7ac4d1ef09", "shasum": "" }, "require": { "ext-dom": "*", "ext-json": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", "myclabs/deep-copy": "~1.3", "php": "^5.6 || ^7.0", - "phpspec/prophecy": "^1.3.1", - "phpunit/php-code-coverage": "^4.0.1", + "phpspec/prophecy": "^1.6.2", + "phpunit/php-code-coverage": "^4.0.3", "phpunit/php-file-iterator": "~1.4", "phpunit/php-text-template": "~1.2", "phpunit/php-timer": "^1.0.6", "phpunit/phpunit-mock-objects": "^3.2", - "sebastian/comparator": "~1.1", + "sebastian/comparator": "~1.2.2", "sebastian/diff": "~1.2", - "sebastian/environment": "^1.3 || ^2.0", - "sebastian/exporter": "~1.2", - "sebastian/global-state": "~1.0", - "sebastian/object-enumerator": "~1.0", + "sebastian/environment": "^1.3.4 || ^2.0", + "sebastian/exporter": "~2.0", + "sebastian/global-state": "^1.0 || ^2.0", + "sebastian/object-enumerator": "~2.0", "sebastian/resource-operations": "~1.0", "sebastian/version": "~1.0|~2.0", "symfony/yaml": "~2.1|~3.0" @@ -645,7 +1240,11 @@ "conflict": { "phpdocumentor/reflection-docblock": "3.0.2" }, + "require-dev": { + "ext-pdo": "*" + }, "suggest": { + "ext-xdebug": "*", "phpunit/php-invoker": "~1.1" }, "bin": [ @@ -654,7 +1253,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.5.x-dev" + "dev-master": "5.7.x-dev" } }, "autoload": { @@ -680,7 +1279,7 @@ "testing", "xunit" ], - "time": "2016-08-26 07:11:44" + "time": "2016-12-13 16:19:44" }, { "name": "phpunit/phpunit-mock-objects", @@ -741,45 +1340,6 @@ ], "time": "2016-12-08 20:27:08" }, - { - "name": "se/selenium-server-standalone", - "version": "v2.53.1", - "source": { - "type": "git", - "url": "https://github.com/sveneisenschmidt/selenium-server-standalone.git", - "reference": "ef4eea9c99efb9c0e3084e9cae625662ccd43361" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sveneisenschmidt/selenium-server-standalone/zipball/ef4eea9c99efb9c0e3084e9cae625662ccd43361", - "reference": "ef4eea9c99efb9c0e3084e9cae625662ccd43361", - "shasum": "" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "bin": [ - "bin/selenium-server-standalone" - ], - "type": "library", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache 2.0" - ], - "authors": [ - { - "name": "Sven Eisenschmidt", - "email": "sven.eisenschmidt@gmail.com" - } - ], - "description": "Composer distribution of Selenium Server Standalone, the browser automation framework. Adds a executable to your composer bin directory.", - "homepage": "https://github.com/sveneisenschmidt/selenium-server-standalone", - "keywords": [ - "selenium", - "testing" - ], - "time": "2016-07-01 14:16:52" - }, { "name": "sebastian/code-unit-reverse-lookup", "version": "1.0.0", @@ -993,21 +1553,21 @@ }, { "name": "sebastian/exporter", - "version": "1.2.2", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4" + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4", - "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", "shasum": "" }, "require": { "php": ">=5.3.3", - "sebastian/recursion-context": "~1.0" + "sebastian/recursion-context": "~2.0" }, "require-dev": { "ext-mbstring": "*", @@ -1016,7 +1576,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1056,7 +1616,7 @@ "export", "exporter" ], - "time": "2016-06-17 09:04:28" + "time": "2016-11-19 08:54:04" }, { "name": "sebastian/global-state", @@ -1111,21 +1671,21 @@ }, { "name": "sebastian/object-enumerator", - "version": "1.0.0", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "d4ca2fb70344987502567bc50081c03e6192fb26" + "reference": "96f8a3f257b69e8128ad74d3a7fd464bcbaa3b35" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/d4ca2fb70344987502567bc50081c03e6192fb26", - "reference": "d4ca2fb70344987502567bc50081c03e6192fb26", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/96f8a3f257b69e8128ad74d3a7fd464bcbaa3b35", + "reference": "96f8a3f257b69e8128ad74d3a7fd464bcbaa3b35", "shasum": "" }, "require": { "php": ">=5.6", - "sebastian/recursion-context": "~1.0" + "sebastian/recursion-context": "~2.0" }, "require-dev": { "phpunit/phpunit": "~5" @@ -1133,7 +1693,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1153,20 +1713,20 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2016-01-28 13:25:10" + "time": "2016-11-19 07:35:10" }, { "name": "sebastian/recursion-context", - "version": "1.0.2", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "913401df809e99e4f47b27cdd781f4a258d58791" + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/913401df809e99e4f47b27cdd781f4a258d58791", - "reference": "913401df809e99e4f47b27cdd781f4a258d58791", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a", "shasum": "" }, "require": { @@ -1178,7 +1738,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1206,7 +1766,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-11-11 19:50:13" + "time": "2016-11-19 07:33:16" }, { "name": "sebastian/resource-operations", @@ -1293,6 +1853,271 @@ "homepage": "https://github.com/sebastianbergmann/version", "time": "2016-10-03 07:35:21" }, + { + "name": "symfony/event-dispatcher", + "version": "v3.2.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "e8f47a327c2f0fd5aa04fa60af2b693006ed7283" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/e8f47a327c2f0fd5aa04fa60af2b693006ed7283", + "reference": "e8f47a327c2f0fd5aa04fa60af2b693006ed7283", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.8|~3.0", + "symfony/dependency-injection": "~2.8|~3.0", + "symfony/expression-language": "~2.8|~3.0", + "symfony/stopwatch": "~2.8|~3.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "https://symfony.com", + "time": "2016-10-13 06:29:04" + }, + { + "name": "symfony/filesystem", + "version": "v3.2.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "8d4cf7561a5b17e5eb7a02b80d0b8f014a3796d4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/8d4cf7561a5b17e5eb7a02b80d0b8f014a3796d4", + "reference": "8d4cf7561a5b17e5eb7a02b80d0b8f014a3796d4", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Filesystem Component", + "homepage": "https://symfony.com", + "time": "2016-11-24 00:46:43" + }, + { + "name": "symfony/finder", + "version": "v3.2.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/finder.git", + "reference": "a69cb5d455b4885ca376dc5bb3e1155cc8c08c4b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/finder/zipball/a69cb5d455b4885ca376dc5bb3e1155cc8c08c4b", + "reference": "a69cb5d455b4885ca376dc5bb3e1155cc8c08c4b", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Finder\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Finder Component", + "homepage": "https://symfony.com", + "time": "2016-12-13 09:39:43" + }, + { + "name": "symfony/polyfill-php54", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php54.git", + "reference": "90e085822963fdcc9d1c5b73deb3d2e5783b16a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php54/zipball/90e085822963fdcc9d1c5b73deb3d2e5783b16a0", + "reference": "90e085822963fdcc9d1c5b73deb3d2e5783b16a0", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php54\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 5.4+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2016-11-14 01:06:16" + }, + { + "name": "symfony/stopwatch", + "version": "v3.2.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/stopwatch.git", + "reference": "5b139e1c4290e6c7640ba80d9c9b5e49ef22b841" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/5b139e1c4290e6c7640ba80d9c9b5e49ef22b841", + "reference": "5b139e1c4290e6c7640ba80d9c9b5e49ef22b841", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Stopwatch\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Stopwatch Component", + "homepage": "https://symfony.com", + "time": "2016-06-29 05:43:10" + }, { "name": "symfony/yaml", "version": "v3.2.1", @@ -1401,7 +2226,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "facebook/webdriver": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": [], diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..d710944 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,30 @@ + + + + Tests/ + src/ + *.php + + + \ No newline at end of file diff --git a/src/Sikofitt/Console/Command/TorBrowserDownloadCommand.php b/src/Sikofitt/Console/Command/TorBrowserDownloadCommand.php new file mode 100644 index 0000000..dd4c21c --- /dev/null +++ b/src/Sikofitt/Console/Command/TorBrowserDownloadCommand.php @@ -0,0 +1,139 @@ + + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Sikofitt\Console\Command; + +use GuzzleHttp\Client; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\Process\Process; +use Symfony\Component\Process\ProcessBuilder; + +/** + * Class TorBrowserDownloadCommand + * + * @package Sikofitt\Console\Command + */ +class TorBrowserDownloadCommand extends Command +{ + const TOR_VERSION = '6.0.8'; + const TOR_DOWNLOAD_URL = 'https://www.torproject.org/dist/torbrowser'; + const TOR_PACKAGE_LINUX_I386 = 'tor-browser-linux32-6.0.8_en-US.tar.xz'; + const TOR_PACKAGE_LINUX_X64 = 'tor-browser-linux64-6.0.8_en-US.tar.xz'; + const TOR_PACKAGE_WIN = 'torbrowser-install-6.0.8_en-US.exe'; + + private $url; + + /** + * {@inheritdoc} + */ + public function configure() + { + $this->setName('tor:download') + ->setDescription('Downloads the tor browser.'); + } + + /** + * Downloads and extracts the tor browser. + * + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Symfony\Component\Console\Output\OutputInterface $output + * @return void + */ + public function execute(InputInterface $input, OutputInterface $output) + { + $this->url = $this->getDownloadUrl(); + $io = $this->getStyle($input, $output); + + $download = $io->confirm('Download Tor?', true); + if (false === $download) { + exit(255); + } + + $io->note('Downloading ' . $this->getDownloadUrl() . ' ...'); + if (false === file_exists(BASE_DIR . $this->getFileName())) { + $client = new Client(); + try { + $data = $client->get($this->url); + } catch (\Exception $e) { + $io->error($e->getMessage()); + exit; + } + + file_put_contents(BASE_DIR . $this->getFileName(), $data->getBody()->getContents()); + } + $io->success('Downloaded'); + $io->note('Extracting ...'); + $tar = new ProcessBuilder(); + $tar + ->setPrefix('tar') + ->setArguments(array('-xvf', BASE_DIR . $this->getFileName())) + ->getProcess()->run(); + } + + /** + * Helper method to get symfony style + * + * @param \Symfony\Component\Console\Input\InputInterface $input + * The Input instance + * @param \Symfony\Component\Console\Output\OutputInterface $output + * The output instance + * + * @return \Symfony\Component\Console\Style\SymfonyStyle + * Instance of SymfonyStyle + */ + private function getStyle(InputInterface $input, OutputInterface $output) + { + return new SymfonyStyle($input, $output); + } + + private function getFileName() + { + $arch = $this->getArch(); + $os = $this->getOS(); + + switch ($os) { + case 'linux': + default: + switch ($arch) { + case 'i386': + $package = self::TOR_PACKAGE_LINUX_I386; + break; + case 'x86_64': + default: + $package = self::TOR_PACKAGE_LINUX_X64; + break; + } + break; + case 'win': + case 'windows': + $package = self::TOR_PACKAGE_WIN; + break; + } + return $package; + } + + private function getDownloadUrl() + { + $package = $this->getFileName(); + return sprintf('%s/%s/%s', self::TOR_DOWNLOAD_URL, self::TOR_VERSION, $package); + } + + private function getArch() + { + return strtolower(php_uname('m')); + } + + private function getOS() + { + return strtolower(PHP_OS); + } +} diff --git a/src/Sikofitt/WebDriver/FirefoxBinary.php b/src/Sikofitt/WebDriver/FirefoxBinary.php new file mode 100644 index 0000000..7c83d03 --- /dev/null +++ b/src/Sikofitt/WebDriver/FirefoxBinary.php @@ -0,0 +1,35 @@ + + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Sikofitt\WebDriver; + +use Symfony\Component\Process\Process; + +/** + * Class FirefoxBinary + * + * @package Sikofitt\WebDriver + */ +class FirefoxBinary extends \SplFileInfo +{ + + /** + * @var string + */ + private $binaryName; + + public function __construct($binaryName) + { + parent::__construct($binaryName); + $this->binaryName = $binaryName; + if (false === $this->isExecutable()) { + throw new \Exception(sprintf('%s is not executable.', $this->binaryName)); + } + } +} diff --git a/src/Sikofitt/WebDriver/Remote/DesiredCapabilities.php b/src/Sikofitt/WebDriver/Remote/DesiredCapabilities.php new file mode 100644 index 0000000..b54af73 --- /dev/null +++ b/src/Sikofitt/WebDriver/Remote/DesiredCapabilities.php @@ -0,0 +1,37 @@ + + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Sikofitt\WebDriver\Remote; + +use Sikofitt\WebDriver\FirefoxBinary; +use WebDriverCapabilityType; +use WebDriverPlatform; +use DesiredCapabilities as FaceBookDesiredCapabilities; + +class DesiredCapabilities extends FaceBookDesiredCapabilities +{ + + /** + * @param FirefoxBinary|null $firefoxBinary + * + * @return static DesiredCapabilities + */ + public static function tor(FirefoxBinary $firefoxBinary = null) + { + $caps = new static([ + WebDriverCapabilityType::BROWSER_NAME => 'firefox', + WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY, + ]); + if (null !== $firefoxBinary) { + $caps->setCapability('firefox_binary', $firefoxBinary->getPathname()); + } + + return $caps; + } +} diff --git a/src/Sikofitt/WebDriver/Tor/TorDriver.php b/src/Sikofitt/WebDriver/Tor/TorDriver.php new file mode 100644 index 0000000..6817204 --- /dev/null +++ b/src/Sikofitt/WebDriver/Tor/TorDriver.php @@ -0,0 +1,17 @@ + + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Sikofitt\WebDriver\Tor; + +use FirefoxDriver; + +class TorDriver extends FirefoxDriver +{ + const PROFILE = '/home/eric/projects/selenium-tor/tor-browser_en-US/Browser/TorBrowser/Data/Browser/profile.default'; +} diff --git a/src/Sikofitt/WebDriver/Tor/TorPreferences.php b/src/Sikofitt/WebDriver/Tor/TorPreferences.php new file mode 100644 index 0000000..09de582 --- /dev/null +++ b/src/Sikofitt/WebDriver/Tor/TorPreferences.php @@ -0,0 +1,44 @@ + + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Sikofitt\WebDriver\Tor; + +/** + * Class TorPreferences + * + * @package Sikofitt\WebDriver\Tor + */ +class TorPreferences extends FirefoxPreferences +{ + + /** + * @var string + * Port WebDriver uses to communicate with Firefox instance + */ + const WEBDRIVER_FIREFOX_PORT = 'webdriver_firefox_port'; + + /** + * @var string + * Should the reader view (FF 38+) be enabled? NO. + * Disable the "Reader View" help tooltip, which can hide elements in the window.document + */ + const READER_PARSE_ON_LOAD_ENABLED = false; + + /** + * @var string + * Browser homepage + */ + const BROWSER_STARTUP_HOMEPAGE = 'browser.startup.homepage'; + + + + private function __construct() + { + } +} diff --git a/src/Sikofitt/WebDriver/Tor/TorProfile.php b/src/Sikofitt/WebDriver/Tor/TorProfile.php new file mode 100644 index 0000000..4b5327a --- /dev/null +++ b/src/Sikofitt/WebDriver/Tor/TorProfile.php @@ -0,0 +1,16 @@ + + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Sikofitt\WebDriver\Tor; + +use FirefoxProfile; + +class TorProfile extends FirefoxProfile +{ +} diff --git a/src/Sikofitt/WebDriver/TorLauncher.php b/src/Sikofitt/WebDriver/TorLauncher.php new file mode 100644 index 0000000..6d9bb3b --- /dev/null +++ b/src/Sikofitt/WebDriver/TorLauncher.php @@ -0,0 +1,46 @@ + + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Sikofitt\WebDriver; + +use Symfony\Component\Process\Process; +use Symfony\Component\Process\ProcessBuilder; + +class TorLauncher +{ + public static function launch(FirefoxBinary $firefoxBinary, $options = []) + { + $defaultOptions = array( + '--detach', + '--browser', + '--new-instance', + '--allow-remote', + ); + + $defaultOptions += $options; + $processBuilder = new ProcessBuilder(); + $processBuilder + ->setPrefix($firefoxBinary->getPathname()) + ->setArguments($defaultOptions); + $process = $processBuilder->getProcess(); + $process->start(); + return $process; + } + public static function stop(Process $process) + { + $process->stop(3, SIGKILL); + if ('linux' === strtolower(PHP_OS)) { + $processBuilder = new ProcessBuilder(); + $processBuilder->setPrefix('killall') + ->setArguments(['firefox']) + ->getProcess() + ->run(); + } + } +}