Skip to content

Commit bea39a9

Browse files
committed
MQE-1257: MFTF doctor command
1 parent 4908777 commit bea39a9

File tree

4 files changed

+45
-37
lines changed

4 files changed

+45
-37
lines changed

docs/commands/mftf.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ vendor/bin/mftf build:project --MAGENTO_BASE_URL=http://magento.local/ --MAGENTO
113113

114114
#### Description
115115

116-
Diagnose MFTF configuration and setup
116+
Diagnose MFTF configuration and setup. Currently this command will check the following:
117+
- Verify admin credentials are valid. Allowing MFTF authenticates and runs API requests to Magento through cURL
118+
- Verify that Selenium is up and running and available for MFTF
119+
- Verify that new session of browser can open Magento admin and store front urls
120+
- Verify that MFTF can run MagentoCLI commands
117121

118122
#### Usage
119123

src/Magento/FunctionalTestingFramework/Console/DoctorCommand.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,20 @@
1818
use Magento\FunctionalTestingFramework\Util\ModuleResolver;
1919
use Magento\FunctionalTestingFramework\Module\MagentoWebDriver;
2020
use Magento\FunctionalTestingFramework\Module\MagentoWebDriverDoctor;
21+
use Symfony\Component\Console\Style\SymfonyStyle;
2122

2223
class DoctorCommand extends Command
2324
{
2425
const CODECEPTION_AUTOLOAD_FILE = PROJECT_ROOT . '/vendor/codeception/codeception/autoload.php';
2526
const MFTF_CODECEPTION_CONFIG_FILE = ENV_FILE_PATH . 'codeception.yml';
2627
const SUITE = 'functional';
27-
const COLOR_LIGHT_GREEN = "\e[1;32m";
28-
const COLOR_LIGHT_RED = "\e[1;31m";
29-
const COLOR_LIGHT_DEFAULT = "\e[1;39m";
30-
const COLOR_RESTORE = "\e[0m";
3128

3229
/**
33-
* Command Output
30+
* Console output style
3431
*
35-
* @var OutputInterface
32+
* @var SymfonyStyle
3633
*/
37-
private $output;
34+
private $ioStyle;
3835

3936
/**
4037
* Exception Context
@@ -63,17 +60,17 @@ protected function configure()
6360
* @param OutputInterface $output
6461
* @return integer
6562
* @throws TestFrameworkException
66-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6763
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
6864
*/
6965
protected function execute(InputInterface $input, OutputInterface $output)
7066
{
67+
// For output style
68+
$this->ioStyle = new SymfonyStyle($input, $output);
69+
7170
$cmdStatus = true;
7271

7372
// Config application
7473
$verbose = $output->isVerbose();
75-
$this->input = $input;
76-
$this->output = $output;
7774
MftfApplicationConfig::create(
7875
false,
7976
MftfApplicationConfig::GENERATION_PHASE,
@@ -126,14 +123,15 @@ private function checkAuthenticationToMagentoAdmin()
126123
{
127124
$result = false;
128125
try {
129-
$this->output->writeln(
130-
"\n" . self::COLOR_LIGHT_DEFAULT . "Authenticating admin account by API ..." . self::COLOR_RESTORE
131-
);
126+
$this->ioStyle->text("Requesting API token for admin user through cURL ...");
132127
ModuleResolver::getInstance()->getAdminToken();
133-
$this->output->writeln(self::COLOR_LIGHT_GREEN . 'Successful' . self::COLOR_RESTORE);
128+
$this->ioStyle->success('Successful');
134129
$result = true;
135130
} catch (TestFrameworkException $e) {
136-
$this->output->writeln(self::COLOR_LIGHT_RED . $e->getMessage() . self::COLOR_RESTORE);
131+
$this->ioStyle->error(
132+
$e->getMessage()
133+
. "\nPlease verify MAGENTO_ADMIN_USERNAME and MAGENTO_ADMIN_PASSWORD in .env."
134+
);
137135
}
138136
return $result;
139137
}
@@ -148,14 +146,14 @@ private function checkAuthenticationToMagentoAdmin()
148146
*/
149147
private function checkContextOnStep($exceptionType, $message)
150148
{
151-
$this->output->writeln("\n" . self::COLOR_LIGHT_DEFAULT. $message . self::COLOR_RESTORE);
149+
$this->ioStyle->text($message . ' ...');
152150
$this->runMagentoWebDriverDoctor();
153151

154152
if (isset($this->context[$exceptionType])) {
155-
$this->output->writeln(self::COLOR_LIGHT_RED . $this->context[$exceptionType] . self::COLOR_RESTORE);
153+
$this->ioStyle->error($this->context[$exceptionType]);
156154
return false;
157155
} else {
158-
$this->output->writeln(self::COLOR_LIGHT_GREEN . 'Successful' . self::COLOR_RESTORE);
156+
$this->ioStyle->success('Successful');
159157
return true;
160158
}
161159
}

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriverDoctor.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,16 @@ private function connectToSeleniumServer()
9494
$this->httpProxy,
9595
$this->httpProxyPort
9696
);
97+
if (null !== $this->remoteWebDriver) {
98+
return;
99+
}
97100
} catch (\Exception $e) {
98-
throw new TestFrameworkException(
99-
"Failed to connect Selenium WebDriver at: {$this->wdHost}.\n"
100-
. "Please make sure that Selenium Server is running."
101-
);
102101
}
102+
103+
throw new TestFrameworkException(
104+
"Failed to connect Selenium WebDriver at: {$this->wdHost}.\n"
105+
. "Please make sure that Selenium Server is running."
106+
);
103107
}
104108

105109
/**
@@ -112,19 +116,21 @@ private function connectToSeleniumServer()
112116
private function loadPageAtUrl($url)
113117
{
114118
try {
115-
// Open the web page at url first
116-
$this->remoteWebDriver->get($url);
117-
118-
// Execute Javascript to retrieve HTTP response code
119-
$script = ''
120-
. 'var xhr = new XMLHttpRequest();'
121-
. "xhr.open('GET', '" . $url . "', false);"
122-
. 'xhr.send(null); '
123-
. 'return xhr.status';
124-
$status = $this->remoteWebDriver->executeScript($script);
125-
126-
if ($status === 200) {
127-
return;
119+
if (null !== $this->remoteWebDriver) {
120+
// Open the web page at url first
121+
$this->remoteWebDriver->get($url);
122+
123+
// Execute Javascript to retrieve HTTP response code
124+
$script = ''
125+
. 'var xhr = new XMLHttpRequest();'
126+
. "xhr.open('GET', '" . $url . "', false);"
127+
. 'xhr.send(null); '
128+
. 'return xhr.status';
129+
$status = $this->remoteWebDriver->executeScript($script);
130+
131+
if ($status === 200) {
132+
return;
133+
}
128134
}
129135
} catch (\Exception $e) {
130136
}

src/Magento/FunctionalTestingFramework/_bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
defined('PROJECT_ROOT') || define('PROJECT_ROOT', $projectRootPath);
1818

19-
$envFilePath = realpath($projectRootPath . '/dev/tests/acceptance/');
19+
$envFilePath = realpath($projectRootPath . '/dev/tests/acceptance/') . DIRECTORY_SEPARATOR;
2020
defined('ENV_FILE_PATH') || define('ENV_FILE_PATH', $envFilePath);
2121

2222
//Load constants from .env file

0 commit comments

Comments
 (0)