Esempio n. 1
0
 /**
  *
  * @param \Pachico\Voyeur\Shot $shot
  * @return string
  */
 protected function _shoot_shot(Shot $shot)
 {
     // Starting sesion if not started yet (in short, open browser)
     if (!$this->_session->isStarted()) {
         $this->_log_out('Starting camera session');
         $this->_session->start();
     }
     $this->_log_out('Loading ' . $shot->get_uri());
     $this->_log_out("Resizing window to " . $shot->get_width() . 'x' . $shot->get_height());
     $this->_session->resizeWindow($shot->get_width(), $shot->get_height());
     // Load page
     $this->_session->visit($shot->get_uri());
     $this->_log_out("Loading finished");
     // Should I wait for something?
     if (count($shot->get_wait_for()) > 0) {
         foreach ($shot->get_wait_for() as $waitings) {
             $wait_time = key($waitings);
             $condition = is_null(current($waitings)) ? null : current($waitings);
             $this->_log_out("Waiting " . $wait_time . ' microseconds');
             $condition and $this->_log_out("Or until " . $condition);
             $this->_session->wait($wait_time, $condition);
         }
     }
     // Any scripts to execute?
     if (count($shot->get_scripts()) > 0) {
         foreach ($shot->get_scripts() as $script) {
             $script = $this->_get_script_file_content($script);
             $this->_session->executeScript($script);
         }
     }
     // Finally take the screenshot and return it
     $this->_log_out("Taking screenshot");
     $picture = $this->_session->getScreenshot();
     return $picture;
 }
Esempio n. 2
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);
 }