selenium-tor/Tests/SeleniumTorSimpleTest.php

75 lines
2.3 KiB
PHP
Raw Permalink Normal View History

2016-12-20 14:32:00 -08:00
<?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;
2016-12-22 12:24:54 -08:00
use Sikofitt\WebDriver\ImageDownloader;
2016-12-20 14:32:00 -08:00
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;
2016-12-22 12:24:54 -08:00
protected $urls = array(
//'http://skunksworkedp2cg.onion/sites.html' => 'A list of onion sites ordered by hostname',
2016-12-20 14:32:00 -08:00
'http://32b5oz2bbtn6gqj3.onion' => 'The Hidden Wiki',
2016-12-22 12:24:54 -08:00
);
2016-12-20 14:32:00 -08:00
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();
2016-12-22 12:24:54 -08:00
2016-12-20 14:32:00 -08:00
$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()
{
2016-12-22 12:24:54 -08:00
//$this->webDriver->quit();
2016-12-20 14:32:00 -08:00
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());
2016-12-22 12:24:54 -08:00
$images = array();
2016-12-20 14:32:00 -08:00
foreach ($elements as $element) {
$images[] = $element->getAttribute('src');
}
2016-12-22 12:24:54 -08:00
if (isset($images[0])) {
$image = new ImageDownloader();
$image->open($images[0]);
$image->save(__DIR__ . '/../');
$image->save(__DIR__ . '/../', true);
}
2016-12-20 14:32:00 -08:00
file_put_contents(__DIR__ . '/../' . 'data.json', json_encode($images, JSON_PRETTY_PRINT));
}
}
}