@@ 11-66 (lines=56) @@ | ||
8 | use Symfony\Component\Console\Input\InputOption; |
|
9 | use Symfony\Component\Console\Output\OutputInterface; |
|
10 | ||
11 | class DownloadSeleniumCommand extends Command |
|
12 | { |
|
13 | /** @var SeleniumHandler */ |
|
14 | protected $seleniumHandler; |
|
15 | ||
16 | /** |
|
17 | * @param SeleniumHandler $seleniumHandler |
|
18 | */ |
|
19 | public function __construct(SeleniumHandler $seleniumHandler) |
|
20 | { |
|
21 | $this->seleniumHandler = $seleniumHandler; |
|
22 | parent::__construct('start'); |
|
23 | } |
|
24 | ||
25 | protected function configure() |
|
26 | { |
|
27 | $this |
|
28 | ->setName('get') |
|
29 | ->addOption( |
|
30 | 'selenium-version', |
|
31 | 's', |
|
32 | InputOption::VALUE_REQUIRED, |
|
33 | 'Set a custom selenium version', |
|
34 | '2.53.0' |
|
35 | ) |
|
36 | ->addOption( |
|
37 | 'selenium-destination', |
|
38 | 'd', |
|
39 | InputOption::VALUE_REQUIRED, |
|
40 | 'Set a custom selenium destination directory', |
|
41 | '.' |
|
42 | ) |
|
43 | ->setDescription('Downloads selenium server'); |
|
44 | } |
|
45 | ||
46 | /** |
|
47 | * @param InputInterface $input |
|
48 | * @param OutputInterface $output |
|
49 | * |
|
50 | * @throws \RuntimeException |
|
51 | */ |
|
52 | protected function execute(InputInterface $input, OutputInterface $output) |
|
53 | { |
|
54 | $this->setDownloaderOptionsFromInput($input); |
|
55 | $this->seleniumHandler->download(); |
|
56 | $output->writeln(PHP_EOL, true); |
|
57 | $output->writeln('Done'); |
|
58 | } |
|
59 | ||
60 | private function setDownloaderOptionsFromInput(InputInterface $input) |
|
61 | { |
|
62 | $downloaderOptions = $this->seleniumHandler->getDownloader()->getDownloaderOptions(); |
|
63 | $downloaderOptions->setSeleniumDestination($input->getOption('selenium-destination')); |
|
64 | $downloaderOptions->setSeleniumVersion($input->getOption('selenium-version')); |
|
65 | } |
|
66 | } |
|
67 |
@@ 11-67 (lines=57) @@ | ||
8 | use Symfony\Component\Console\Input\InputOption; |
|
9 | use Symfony\Component\Console\Output\OutputInterface; |
|
10 | ||
11 | class StopSeleniumCommand extends Command |
|
12 | { |
|
13 | /** @var SeleniumHandler */ |
|
14 | protected $seleniumHandler; |
|
15 | ||
16 | /** |
|
17 | * @param SeleniumHandler $seleniumHandler |
|
18 | */ |
|
19 | public function __construct(SeleniumHandler $seleniumHandler) |
|
20 | { |
|
21 | $this->seleniumHandler = $seleniumHandler; |
|
22 | parent::__construct('start'); |
|
23 | } |
|
24 | ||
25 | protected function configure() |
|
26 | { |
|
27 | $this |
|
28 | ->setName('stop') |
|
29 | ->addOption( |
|
30 | 'timeout', |
|
31 | 't', |
|
32 | InputOption::VALUE_REQUIRED, |
|
33 | 'Set how much you are willing to wait until selenium server is stopped (in seconds)', |
|
34 | 30 |
|
35 | ) |
|
36 | ->addOption( |
|
37 | 'port', |
|
38 | 'p', |
|
39 | InputOption::VALUE_REQUIRED, |
|
40 | 'Set how much you are willing to wait until selenium server is stopped (in seconds)', |
|
41 | 4444 |
|
42 | ) |
|
43 | ->setDescription('Stops selenium server'); |
|
44 | } |
|
45 | ||
46 | /** |
|
47 | * @param InputInterface $input |
|
48 | * @param OutputInterface $output |
|
49 | */ |
|
50 | protected function execute(InputInterface $input, OutputInterface $output) |
|
51 | { |
|
52 | $this->setStopperOptionsFromInput($input); |
|
53 | $this->seleniumHandler->stop(); |
|
54 | $output->writeln(PHP_EOL, true); |
|
55 | $output->writeln("\nDone"); |
|
56 | } |
|
57 | ||
58 | /** |
|
59 | * @param InputInterface $input |
|
60 | */ |
|
61 | private function setStopperOptionsFromInput(InputInterface $input) |
|
62 | { |
|
63 | $stopper = $this->seleniumHandler->getStopper(); |
|
64 | $stopper->getStopOptions()->setSeleniumPort($input->getOption('port')); |
|
65 | $stopper->getResponseWaitter()->setTimeout($input->getOption('timeout')); |
|
66 | } |
|
67 | } |
|
68 |