SeleniumSessionAnalyzer.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Mtf\Troubleshooting;
  7. use Magento\Mtf\ObjectManagerInterface;
  8. use Symfony\Component\Console\Input\InputInterface;
  9. use Symfony\Component\Console\Output\OutputInterface;
  10. use Magento\Mtf\Client\Driver\Selenium\Driver;
  11. /**
  12. * Analyze if Selenium session connection is established.
  13. */
  14. class SeleniumSessionAnalyzer extends \Symfony\Component\Console\Command\Command
  15. {
  16. /**
  17. * Object manager instance.
  18. *
  19. * @var ObjectManagerInterface
  20. */
  21. private $objectManager;
  22. /**
  23. * @param ObjectManagerInterface $objectManager
  24. */
  25. public function __construct(ObjectManagerInterface $objectManager)
  26. {
  27. parent::__construct();
  28. $this->objectManager = $objectManager;
  29. }
  30. /**
  31. * Configure command.
  32. *
  33. * @return void
  34. */
  35. protected function configure()
  36. {
  37. parent::configure();
  38. $this->setName('troubleshooting:check-selenium-session-connection')
  39. ->setDescription('Check that Selenium session connection is established.');
  40. }
  41. /**
  42. * Execute command.
  43. *
  44. * @param InputInterface $input
  45. * @param OutputInterface $output
  46. * @return void
  47. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  48. */
  49. protected function execute(InputInterface $input, OutputInterface $output)
  50. {
  51. $output = $this->objectManager->create(
  52. \Magento\Mtf\Console\Output::class,
  53. ['output' => $output]
  54. );
  55. $output->writeln("Verifying selenium server session...");
  56. try {
  57. $driver = $this->objectManager->create(Driver::class);
  58. $driver->closeWindow();
  59. } catch (\Exception $e) {
  60. $output->outputMessages(['error' =>
  61. [
  62. 'The Selenium Server session cannot be established. Check if:'
  63. . PHP_EOL . "\tSelenium server is launched."
  64. . PHP_EOL . "\tSelenium server host and port configuration are correct in etc/config.xml."
  65. . PHP_EOL . "\tThere is a valid browser name in etc/config.xml."
  66. . PHP_EOL . "\tSelenium server is run with appropriate driver."
  67. . PHP_EOL . "\tSelenium server version is compatible with web browser version."
  68. ]
  69. ]);
  70. }
  71. $output->writeln('Verification of selenium server session is finished.');
  72. }
  73. }