Exemple #1
0
 /**
  * @covers Pachico\Voyeur\Voyeur::shoot
  * @covers Pachico\Voyeur\Voyeur::get_shots
  * @covers Pachico\Voyeur\Voyeur::get_camera
  * @covers Pachico\Voyeur\Voyeur::_get_script_file_content
  * @covers Pachico\Voyeur\Voyeur::_shoot_shot
  * @covers Pachico\Voyeur\Voyeur::_log_out
  */
 public function testShootLog()
 {
     $mocked_camera = $this->_get_mocked_camera();
     $this->_voyeur = new Voyeur($mocked_camera, $this->_get_mocked_film(), true);
     $valid_shot = new Shot(TEST_URI, TEST_DESTINATION_FILE_NAME);
     $valid_shot->add_scripts(TEST_SCRIPTS_FOLDER . 'banner1.js')->set_window_size(1024, 800)->add_wait_for(1000)->add_wait_for(1000, '1 === 1');
     $this->assertInstanceOf('Pachico\\Voyeur\\Voyeur', $this->_voyeur->add_shot($valid_shot));
     $invalid_shot = new Shot('whatever', 'whatever');
     $cannot_be_saved_shot = new Shot('whatever', 'whatever');
     $this->_voyeur->add_shot($invalid_shot)->add_shot($cannot_be_saved_shot);
     $shots = $this->_voyeur->shoot();
     $this->assertInternalType('array', $shots);
     $this->assertCount(3, $shots);
     foreach ($shots as $shot) {
         $this->assertInstanceOf('Pachico\\Voyeur\\Shot', $shot);
     }
     $shots_from_getter = $this->_voyeur->get_shots();
     $this->assertInternalType('array', $shots_from_getter);
     $this->assertSame($shots, $shots_from_getter);
     $this->assertSame($this->_voyeur->get_camera(), $mocked_camera);
 }
Exemple #2
0
<?php

/**
 * @author Mariano F.co Benítez Mulet <*****@*****.**>
 * @copyright (c) 2016-2019, Mariano F.co Benítez Mulet
 *
 * This is a real working example.
 * To run it make sure sure you have started PhantomJS
 * in the same machine (or change the hub address when instanciating
 * the Camera class.
 *
 */
use Pachico\Voyeur\Voyeur, Pachico\Voyeur\Shot, Pachico\Voyeur\Film, Pachico\Voyeur\Camera;
require __DIR__ . '/../bootstrap.php';
// We create a Camera indicating the path where Selenium/Phantomjs is running
$camera = new Camera(Camera::DRIVER_NAME_PHAMTOMJS, 'http://localhost:8910');
// We indicate what is the folder path where screenshots will be saved
$film = new Film(TEST_PICTURE_FOLDER);
// We create a Voyeur instance
$voyeur = new Voyeur($camera, $film, true);
// We instanciate as many Shots as we want url and destination file
$shot1 = (new Shot('http://www.example.com/', uniqid() . '.png'))->add_scripts(TEST_SCRIPTS_FOLDER . 'banner1.js')->set_window_size(400, 300);
$shot2 = (new Shot('http://locallhost.com/', uniqid() . '.png'))->add_scripts(TEST_SCRIPTS_FOLDER . 'banner2.js')->set_window_size(1024, 800);
// Add the Shot to Voyeur and shot
$shots = $voyeur->add_shot($shot1)->add_shot($shot2)->shoot();
echo "Saved files: \n";
foreach ($shots as $shot) {
    echo "\t" . TEST_SCRIPTS_FOLDER . (string) $shot . "\n";
}