protected function execute(InputInterface $input, OutputInterface $output) { SeleniumManager::ensureSeleniumIsRunning(); $shop = ShopManager::getInstance()->getShop(null, false); $lc = $input->getArgument('TwoLettersLanguageCode'); $shop->getBackOfficeNavigator()->login(); $translations = $shop->getPageObject('AdminTranslations'); $translations->visit(); $translations->addOrUpdateLanguage($lc); }
protected function execute(InputInterface $input, OutputInterface $output) { if (!SeleniumManager::isSeleniumStarted()) { SeleniumManager::spawnSelenium(); } SeleniumManager::ensureSeleniumIsRunning(); $shop = ShopManager::getInstance()->getShop(['temporary' => false, 'use_cache' => false, 'overwrite' => true]); $shop->getInstaller()->install($shop->getOptionProvider()->getValues('ShopInstallation', $input)); $shop->getBrowser()->quit(); }
protected function execute(InputInterface $input, OutputInterface $output) { if ($data = Selenium::started(true)) { $output->writeln('<fg=green>Selenium is running (pidFile: ' . $data['pidFile'] . ')</fg=green>'); if (realpath($data['pidDirectory']) !== realpath('.')) { $output->writeln('<comment>Please note that the pid file is located in a higher directory, not your CWD.</comment>'); } } else { $output->writeln('<fg=red>Selenium is not running!</fg=red>'); } }
protected function execute(InputInterface $input, OutputInterface $output) { if (Selenium::startedInCWD()) { Selenium::stop(false); } elseif (Selenium::startedInHigherDirectory()) { $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('Selenium was started in a higher directory, do you really want to stop it? (y/N) ', false); if ($helper->ask($input, $output, $question)) { Selenium::stop(true); } } else { $output->writeln("<comment>Selenium doesn't seem to be running.</comment>"); } }
protected function execute(InputInterface $input, OutputInterface $output) { if (Selenium::startedInCWD()) { $output->writeln("<comment>Selenium seems to be already running!</comment>"); } elseif (Selenium::startedInHigherDirectory()) { $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('Selenium was started in a higher directory, do you want to spawn another instance here? (y/N) ', false); if ($helper->ask($input, $output, $question)) { Selenium::start(); } } else { Selenium::start(); } }
public static function cleanDirectory($dir = '.') { foreach (scandir($dir) as $entry) { $path = FS::join($dir, $entry); $m = []; if (preg_match('/pstaf\\.(\\w+)\\.istate\\.shop/', $entry, $m)) { echo "Removing cached shop {$entry}...\n"; FS::rmR($path); $lock = "pstaf.{$m[1]}.istate.lock"; if (file_exists($lock)) { echo "Removing useless lock file {$lock}...\n"; unlink($lock); } } elseif (preg_match('/\\.png$/', $entry)) { echo "Removing screenshot {$entry}...\n"; unlink($path); } elseif ($entry === 'selenium.log') { echo "Cleaning selenium log file {$entry}...\n"; file_put_contents($entry, ''); } elseif ($entry === 'php_errors.log') { echo "Cleaning local php error log file {$entry}...\n"; file_put_contents($path, ''); } elseif ($entry === 'test-results') { echo "Removing test results folder {$entry}...\n"; FS::rmR($path, true); } elseif ($entry === 'test-history') { foreach (scandir($path) as $nestedEntry) { if ($nestedEntry[0] === '.') { continue; } $nested = FS::join($path, $nestedEntry); if (is_dir($nested)) { FS::rmR($nested); } elseif ($nestedEntry === 'history.json.stream') { file_put_contents($nested, ''); } else { unlink($nested); } } } elseif ($entry === 'selenium.pid' && !SeleniumManager::isSeleniumStarted()) { echo "Removing stale pid file {$entry}...\n"; unlink($path); } } }
public static function setUpBeforeClass() { SeleniumManager::ensureSeleniumIsRunning(); self::getBrowser()->clearCookies(); }
protected function execute(InputInterface $input, OutputInterface $output) { if (!SeleniumManager::isSeleniumStarted()) { SeleniumManager::spawnSelenium($input->getOption('headless')); } $runners = ['phpunit', 'paratest', 'ptest', 'ftr']; $parallel = max(1, (int) $input->getOption('parallel')); $runner = $input->getOption('runner'); if (!in_array($runner, $runners)) { $output->writeln('<error>Unsupported runner! Available runners are: phpunit, paratest and ptsest.</error>'); return; } if ($parallel > 1 && $runner === 'phpunit') { $output->writeln('<error>The PHPUnit runner can\'t run tests in parallel.</error>'); return; } $info = $input->getOption('info'); if ($info && $runner !== 'ptest' && $runner !== 'ftr') { $output->writeln('<error>The info option is only supported by the ptest runner.</error>'); return; } $runner_path = realpath(FS::join(__DIR__, '/../../vendor/bin/', $runner)); if (!$runner_path) { $output->writeln(sprintf('<error>Could not find runner executable (%s). Did you run composer install?</error>', $runner)); return; } if ($input->getArgument('test_name') && $input->getOption('all')) { $output->writeln(sprintf('<error>Cannot specify both a test name / folder and the "all" option.</error>')); return; } $domain = $input->getOption('domain'); $tests_directory = realpath(FS::join(__DIR__, '..', '..', $domain)); if (!$tests_directory) { $output->writeln('<error>Couldn\'t find directory containing tests.</error>'); return; } if ($input->getOption('all')) { $tests_path = $tests_directory; } elseif (($test_name = $input->getArgument('test_name')) && !preg_match('/\\.php$/', $test_name)) { $tests_path = realpath(FS::join($tests_directory, $test_name . 'Test.php')); } elseif ($test_name) { $tests_path = realpath($test_name); } else { $rdi = new \RecursiveDirectoryIterator($tests_directory, \RecursiveDirectoryIterator::SKIP_DOTS); $rii = new \RecursiveIteratorIterator($rdi); $tests = []; foreach ($rii as $path => $info) { if ($info->getExtension() === 'php' && preg_match('/Test$/', $info->getBaseName('.php'))) { $tests[] = substr($path, strlen($tests_directory) + 1, -strlen('Test.php')); } } $question = new Question('Which test do you want to run? '); $question->setAutocompleterValues($tests); $helper = $this->getHelperSet()->get('question'); $tests_path = realpath(FS::join($tests_directory, $helper->ask($input, $output, $question) . 'Test.php')); } if (!$tests_path) { $output->writeln('<error>Could not find requested test.</error>'); } $arguments = []; $options = []; if ($runner === 'ptest' || $runner === 'ftr') { $arguments[] = 'run'; } if ($info) { $options['-i'] = ''; } $arguments[] = $tests_path; if ($runner === 'ptest' || $runner === 'paratest' || $runner === 'ftr') { $options['-p'] = $parallel; } $filter = $input->getOption('filter'); if ($filter) { $options['--filter'] = $filter; } $z = $input->getOption('data-provider-filter'); if (!empty($z)) { foreach ($z as $opt) { $options['--data-provider-filter'] = $opt; if ($runner === 'ftr') { break; // this one supports only one filter } } } if ($runner === 'ftr') { $arguments[] = '--shallow'; } $process = new \djfm\Process\Process($runner_path, $arguments, $options, ['wait' => true]); $process->setEnv('SELENIUM_HOST', SeleniumManager::getHost()); if ($input->getOption('inplace')) { echo "-----------------------------------------------------\n"; echo "- Warning, running test inplace (as asked). -\n"; echo "- Initial states will not be changed, nor restored. -\n"; echo "-----------------------------------------------------\n"; echo "\n"; $process->setEnv('PSTAF_INPLACE', 1); } if ($input->getOption('no-screenshots')) { $process->setEnv('NO_SCREENSHOTS', 1); } $process->run(STDIN, STDOUT, STDERR); }
public static function getFromCWD() { $conf = ConfigurationFile::getFromCWD(); $shop = new Shop('.', $conf->get('shop'), SeleniumManager::getMyPort()); return $shop; }
public static function getBrowser() { if (!self::get('browser')) { $browser = new Browser(['host' => SeleniumManager::getHost()]); self::set('browser', $browser); } return self::get('browser'); }