Beispiel #1
0
 public function openLockFile()
 {
     if (!$this->fileSystem->isFile(SeleniumSetup::$APP_ROOT_PATH . DIRECTORY_SEPARATOR . SeleniumSetup::DEFAULT_LOCK_FILENAME)) {
         return false;
     }
     $contents = $this->fileSystem->readFile(SeleniumSetup::$APP_ROOT_PATH . DIRECTORY_SEPARATOR . SeleniumSetup::DEFAULT_LOCK_FILENAME);
     $lockerRaw = json_decode($contents);
     foreach ($lockerRaw as $serverObj) {
         $this->addServer(ServerItemFactory::createFromObj($serverObj));
     }
     return true;
 }
 protected function register($name, $port)
 {
     // Find filename by instance name.
     $filename = $this->getInstanceConfigFilename($name);
     // Update configuration to new instance clone.
     $this->config->setName($name);
     $this->config->setPort($port);
     $this->config->setFilePath($filename);
     // Store new filename using the default instance template.
     $this->fileSystem->createFile($filename, $this->config->toJson());
     // Append instance entry in lock-file.
     $this->locker->addServer(ServerItemFactory::createFromProperties($name, 0, $port, $filename));
     // Write lock-file settings.
     $this->locker->writeToLockFile();
 }
 public function handle()
 {
     // @todo should allow only registered instances to be called
     $this->createFolders();
     $this->downloadDrivers();
     // Add build folder to path.
     $this->env->addPathToGlobalPath($this->config->getBuildPath());
     // Warn if Chrome or Firefox binaries are not available.
     if ($chromeVersion = $this->env->getChromeVersion()) {
         $this->output->writeln('Chrome binary found, v.' . $chromeVersion);
     } else {
         $this->output->writeln('<info>WARNING: Chrome binary not found.</info>');
     }
     if ($firefoxVersion = $this->env->getFirefoxVersion()) {
         $this->output->writeln('Firefox binary found, v.' . $firefoxVersion);
     } else {
         $this->output->writeln('<info>WARNING: Firefox binary not found.</info>');
     }
     // Warn if display is not available.
     if ($this->env->isLinux()) {
         if ($this->env->hasXvfb()) {
             $this->output->writeln('<info>Xvfb is installed. Good.</info>');
         } else {
             $this->output->writeln('<info>WARNING: Xvfb is not installed.</info>');
         }
     }
     // $pid = $this->env->startDisplayProcess();
     // Start Selenium Server instance.
     $this->output->writeln(sprintf('Starting Selenium Server (%s) ... %s:%s', $this->config->getName(), $this->config->getHostname(), $this->config->getPort()));
     $pid = $this->env->startSeleniumProcess();
     if ($pid > 0) {
         // Make sure that we capture the right PID.
         while ($this->env->listenToPort($this->config->getPort()) == '') {
             $this->output->write('<info>.</info>');
         }
         $parentPid = $this->env->getPidFromListeningToPort($this->config->getPort());
         if ($parentPid) {
             $pid = $parentPid;
         }
         // @todo open the lock file only to update the status and ports, the instance was already added.
         $this->locker->openLockFile();
         $this->locker->addServer(ServerItemFactory::createFromProperties($this->config->getName(), $pid, $this->config->getPort(), $this->config->getFilePath()));
         $this->locker->writeToLockFile();
     }
     $this->output->writeln('<info>Done</info>');
     $this->output->writeln(sprintf('Test it at http://%s:%s/wd/hub/', $this->config->getHostname(), $this->config->getPort()));
 }