public function execute(Shooter $shooter)
 {
     $url = $this->url;
     $shooter->addInfo("Opening " . $url);
     $session = $shooter->getSession();
     $session->visit($url);
 }
 public function execute(Shooter $shooter)
 {
     $ms = $this->ms;
     $shooter->addInfo("Sleeping " . $ms . "ms");
     $session = $shooter->getSession();
     $session->wait($ms);
 }
 public function execute(Shooter $shooter)
 {
     $id = $this->id;
     $shooter->addInfo("Setting value on " . $id);
     $session = $shooter->getSession();
     $page = $session->getPage();
     $element = $page->find('css', '#' . $id);
     if (null === $element) {
         throw new InvalidArgumentException(sprintf('Could not find element by id: "%s"', $id));
     }
     $element->setValue($this->value);
 }
 public function execute(Shooter $shooter)
 {
     $id = $this->id;
     $shooter->addInfo("Selecting on " . $id);
     $session = $shooter->getSession();
     $page = $session->getPage();
     $element = $page->find('css', '#' . $id);
     $element->selectOption($this->value);
     if (null === $element) {
         throw new InvalidArgumentException(sprintf('Could not evaluate XPath: "%s"', $xpath));
     }
 }
 public function execute(Shooter $shooter)
 {
     $id = $this->id;
     $shooter->addInfo("Clicking " . $id);
     $session = $shooter->getSession();
     $page = $session->getPage();
     if ($id) {
         $element = $page->find('css', '#' . $id);
     } else {
         $element = $page->find('css', 'input[name="' . $this->name . '"]');
     }
     if (null === $element) {
         throw new InvalidArgumentException(sprintf('Could find element with id: "%s"', $id));
     }
     $element->press();
 }
 public function execute(Shooter $shooter)
 {
     $shooter->addInfo("Taking screenshot: " . $this->name);
     $session = $shooter->getSession();
     $screenshotdata = $session->getDriver()->getScreenshot();
     $image = imagecreatefromstring($screenshotdata);
     imageantialias($image, true);
     $size = getimagesizefromstring($screenshotdata);
     //$image = imagescale($image, $shooter->getWidth());
     $image_p = imagecreatetruecolor($shooter->getWidth(), $shooter->getHeight());
     imagecopyresampled($image_p, $image, 0, 0, 0, 0, $shooter->getWidth(), $shooter->getHeight(), $size[0], $size[1]);
     $image = $image_p;
     imageantialias($image, true);
     print_r($size);
     if ($this->highlightid) {
         echo "Fetching dimensions for element id " . $this->highlightid . "\n";
         $box = $session->evaluateScript("return document.getElementById('" . $this->highlightid . "').getBoundingClientRect();");
         var_dump($box);
         $color = imagecolorallocate($image, 255, 0, 0);
         for ($i = 0; $i < 4; $i++) {
             /*
             imagerectangle(
                 $image,
                 $box['left'] - $i,
                 $box['top'] - $i,
                 $box['left'] + $box['width'] + ($i),
                 $box['top'] + $box['height'] + ($i),
                 $color
             );
             */
             $x = $box['left'] + $box['width'] / 2;
             $y = $box['top'] + $box['height'] / 2;
             //imageellipse($image, $x, $y, $box['width']+$i, $box['height']+$i, $color);
             $this->imageEllipseAA($image, $x, $y, $box['width'] + $i, $box['height'] + $i, $color);
         }
     }
     if ($this->cropid) {
         // evaluate JS expression:
         echo "Fetching dimensions for element id " . $this->cropid . "\n";
         $box = $session->evaluateScript("return document.getElementById('" . $this->cropid . "').getBoundingClientRect();");
         var_dump($box);
         $width = $box['width'] + $this->cropmargin * 2;
         if ($width > $shooter->getWidth() - $box['left'] + $this->cropmargin) {
             $width = $shooter->getWidth() - $box['left'] + $this->cropmargin;
         }
         $height = $box['height'] + $this->cropmargin * 2;
         if ($height > $shooter->getHeight() - $box['top'] + $this->cropmargin) {
             $height = $shooter->getHeight() - $box['top'] + $this->cropmargin;
         }
         $rect = array('x' => $box['left'] - $this->cropmargin, 'y' => $box['top'] - $this->cropmargin, 'width' => $width, 'height' => $height);
         $image = imagecrop($image, $rect);
         $image_p = imagecreatetruecolor($shooter->getWidth(), $shooter->getHeight());
         imagecopyresampled($image_p, $image, 0, 0, 0, 0, $shooter->getWidth(), $shooter->getHeight(), $width, $height);
     }
     $tmpfilename = '/tmp/tmp-' . $this->name . '.png';
     imagepng($image, $tmpfilename, null);
     imagedestroy($image);
     $storageservice = $shooter->getStorageService();
     $storageservice->upload($this->name . '.png', $tmpfilename);
     unlink($tmpfilename);
 }