describe('Manager', function () {
    beforeEach(function () {
        $this->system = $this->getProphet()->prophesize('Peridot\\WebDriverManager\\OS\\SystemInterface');
        $resolver = new BinaryResolver(null, null, $this->system->reveal());
        $this->manager = new Manager($resolver);
        $selenium = glob($this->manager->getInstallPath() . '/selenium*');
        $chrome = glob($this->manager->getInstallPath() . '/chrome*');
        $ie = glob($this->manager->getInstallPath() . '/IE*');
        $fixtures = array_merge($selenium, $chrome, $ie);
        foreach ($fixtures as $fixture) {
            unlink($fixture);
        }
    });
    describe('->start()', function () {
        it('should support arbitrary arguments', function () {
            $manager = new Manager();
            $manager->updateSingle('selenium');
            $log = tempnam(sys_get_temp_dir(), 'SEL_');
            $proc = $manager->start(true, 4444, ['-log', $log]);
            usleep(500000);
            $proc->close();
            $contents = file_get_contents($log);
            expect($contents)->to->not->be->empty;
        });
    });
    describe('->update()', function () {
        it('should update a single binary', function () {
            $this->manager->update('selenium');
            $path = $this->manager->getInstallPath();
            $selenium = glob("{$path}/selenium-server-standalone-*");
            $chrome = glob("{$path}/chromedriver*");
Example #2
0
<?php

require __DIR__ . "/spec/Api/Helpers.php";
use Behat\Mink\Driver\Selenium2Driver;
use Behat\Mink\Mink;
use Behat\Mink\Session;
use Peridot\WebDriverManager\Manager;
use Kahlan\Box\Box;
use Kahlan\Code\Code;
use Kahlan\Code\TimeoutException;
use Kahlan\Filter\Filter;
use Kahlan\Matcher;
$box = box('spec', new Box());
$box->service('manager', function () {
    $manager = new Manager();
    $manager->update();
    return $manager->startInBackground();
});
$box->service('mink', function () {
    $selenium = new Selenium2Driver('firefox', null, 'http://localhost:4444/wd/hub');
    $mink = new Mink(['firefox' => new Session($selenium)]);
    $mink->setDefaultSessionName('firefox');
    return $mink;
});
Filter::register('exclude.namespaces', function ($chain) {
    $defaults = ['Behat'];
    $excluded = $this->commandLine()->get('exclude');
    $this->commandLine()->set('exclude', array_unique(array_merge($excluded, $defaults)));
    return $chain->next();
});
Filter::register('run.webdriver', function ($chain) {
 });
 describe('->removeBinary()', function () {
     it('should remove a binary from the collection of managed binaries', function () {
         $this->manager->removeBinary('selenium');
         $binaries = $this->manager->getBinaries();
         expect($binaries)->to->not->have->property('selenium');
     });
 });
 describe('->getSeleniumProcess()', function () {
     it('should return a SeleniumProcess by default', function () {
         $manager = new Manager();
         expect($manager->getSeleniumProcess())->to->be->an->instanceof('Peridot\\WebDriverManager\\Process\\SeleniumProcess');
     });
     it('should return the SeleniumProcessInterface if given', function () {
         $process = new SeleniumProcess();
         $manager = new Manager(null, $process);
         expect($manager->getSeleniumProcess())->to->equal($process);
     });
 });
 describe('->getBinaries()', function () {
     it('should return a collection of managed binaries', function () {
         $binaries = $this->manager->getBinaries();
         expect($binaries)->to->have->length(3);
         foreach ($binaries as $binary) {
             expect($binary)->to->be->an->instanceof('Peridot\\WebDriverManager\\Binary\\BinaryInterface');
         }
     });
 });
 describe('->getDrivers()', function () {
     it('should return a collection of binaries that qualify as drivers', function () {
         $drivers = $this->manager->getDrivers();