1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BeubiQA\Application\Command; |
4
|
|
|
|
5
|
|
|
use BeubiQA\Application\Selenium\SeleniumHandler; |
6
|
|
|
use Symfony\Component\Console\Command\Command; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
class StartSeleniumCommand 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('start') |
29
|
|
|
->addOption( |
30
|
|
|
'selenium-location', |
31
|
|
|
'l', |
32
|
|
|
InputOption::VALUE_REQUIRED, |
33
|
|
|
'Set a custom selenium jar location', |
34
|
|
|
'./selenium-server-standalone.jar' |
35
|
|
|
) |
36
|
|
|
->addOption( |
37
|
|
|
'xvfb', |
38
|
|
|
null, |
39
|
|
|
InputOption::VALUE_NONE, |
40
|
|
|
'Use xvfb to start selenium server' |
41
|
|
|
) |
42
|
|
|
->addOption( |
43
|
|
|
'follow', |
44
|
|
|
'f', |
45
|
|
|
InputOption::VALUE_OPTIONAL, |
46
|
|
|
'Follow selenium log. You may choose a specific level to follow. E.g. --follow ERROR ', |
47
|
|
|
false |
48
|
|
|
) |
49
|
|
|
->addOption( |
50
|
|
|
'timeout', |
51
|
|
|
't', |
52
|
|
|
InputOption::VALUE_REQUIRED, |
53
|
|
|
'Set how much you are willing to wait until selenium server is started (in seconds)', |
54
|
|
|
30 |
55
|
|
|
) |
56
|
|
|
->addOption( |
57
|
|
|
'log-location', |
58
|
|
|
null, |
59
|
|
|
InputOption::VALUE_REQUIRED, |
60
|
|
|
'Set the location of the selenium.log file', |
61
|
|
|
'selenium.log' |
62
|
|
|
) |
63
|
|
|
->addOption( |
64
|
|
|
'selextra', |
65
|
|
|
null, |
66
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
67
|
|
|
'Extra options to selenium cmd. You may give multiple options. E.g.: firefoxProfileTemplate=/profileDir', |
68
|
|
|
[] |
69
|
|
|
) |
70
|
|
|
->setDescription('Starts selenium server'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param InputInterface $input |
75
|
|
|
* @param OutputInterface $output |
76
|
|
|
* |
77
|
|
|
* @throws \RuntimeException |
78
|
|
|
*/ |
79
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
80
|
|
|
{ |
81
|
|
|
$starter = $this->seleniumHandler->getStarter(); |
82
|
|
|
$this->setStarterOptionsFromInput($input); |
83
|
|
|
$starter->start(); |
84
|
|
|
$output->writeln(PHP_EOL, true); |
85
|
|
|
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { |
86
|
|
|
$output->writeln($starter->getStartCommand(), true); |
87
|
|
|
} |
88
|
|
|
$output->writeln('Done', true); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
private function setStarterOptionsFromInput(InputInterface $input) |
92
|
|
|
{ |
93
|
|
|
$starter = $this->seleniumHandler->getStarter(); |
94
|
|
|
$starter->getResponseWaitter()->setTimeout($input->getOption('timeout')); |
95
|
|
|
$starterOptions = $starter->getStartOptions(); |
96
|
|
|
$starterOptions->setSeleniumLogLocation($input->getOption('log-location')); |
97
|
|
|
$starterOptions->setSeleniumJarLocation($input->getOption('selenium-location')); |
98
|
|
|
if ($input->getOption('xvfb')) { |
99
|
|
|
$starterOptions->enabledXvfb(); |
100
|
|
|
} |
101
|
|
|
$this->processSeleniumExtraArguments($input->getOption('selextra')); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
private function processSeleniumExtraArguments(array $cmdExtraArgs) |
105
|
|
|
{ |
106
|
|
|
$starterOptions = $this->seleniumHandler->getStarter()->getStartOptions(); |
107
|
|
|
$extraArgs = []; |
108
|
|
|
foreach ($cmdExtraArgs as $cmdExtraArgString) { |
109
|
|
|
$resultArray = explode('=', $cmdExtraArgString); |
110
|
|
|
$argName = $resultArray[0]; |
111
|
|
|
$argValue = $resultArray[1]; |
112
|
|
|
$extraArgs[$argName] = $argValue; |
113
|
|
|
} |
114
|
|
|
$starterOptions->setSeleniumExtraArguments($extraArgs); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|