75 lines
2.3 KiB
PHP
75 lines
2.3 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Selenium Tor Driver.
|
|
* (c) R. Eric Wheeler <eric@rewiv.com>
|
|
* 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\ImageDownloader;
|
|
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 = array(
|
|
//'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 = array();
|
|
foreach ($elements as $element) {
|
|
$images[] = $element->getAttribute('src');
|
|
}
|
|
if (isset($images[0])) {
|
|
$image = new ImageDownloader();
|
|
$image->open($images[0]);
|
|
$image->save(__DIR__ . '/../');
|
|
$image->save(__DIR__ . '/../', true);
|
|
}
|
|
file_put_contents(__DIR__ . '/../' . 'data.json', json_encode($images, JSON_PRETTY_PRINT));
|
|
}
|
|
}
|
|
}
|