selenium-tor/Tests/SeleniumTorSimpleTest.php

68 lines
2.0 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\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));
}
}
}