Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SwaggerUiPage.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Client\Locator;
10 use Magento\Mtf\Client\BrowserInterface;
11 
16 {
20  const MCA = 'swagger/';
21 
27  protected $url;
28 
34  protected $browser;
35 
41  protected $titleSelector = '.title';
42 
50  public function __construct(BrowserInterface $browser)
51  {
52  $this->browser = $browser;
53  $this->url = $_ENV['app_frontend_url'] . self::MCA;
54  }
55 
61  public function open()
62  {
63  $this->openSwaggerUrl();
64  $this->waitForPageToLoad();
65  }
66 
72  public function close()
73  {
74  $this->browser->closeWindow();
75  }
76 
84  public function isElementVisible($selector, $strategy = Locator::SELECTOR_CSS)
85  {
86  return $this->browser->find($selector, $strategy)->isVisible();
87  }
88 
95  public function expandServiceContent($serviceName)
96  {
100  $serviceSelector = '#operations-tag-%s';
104  $endpointSelector = '//H4[@id=\'operations-tag-%s\']/following-sibling::DIV';
105  $serviceSelector = sprintf($serviceSelector, $serviceName);
106  $endpointSelector = sprintf($endpointSelector, $serviceName);
107  if (!$this->isElementVisible($endpointSelector, Locator::SELECTOR_XPATH)) {
108  $this->browser->find($serviceSelector, Locator::SELECTOR_CSS)->click();
109  }
110  }
111 
118  public function closeServiceContent($serviceName)
119  {
123  $serviceSelector = '#operations-tag-%s';
127  $serviceSelector = sprintf($serviceSelector, $serviceName);
128  $this->browser->find($serviceSelector, Locator::SELECTOR_CSS)->click();
129  }
130 
138  public function expandEndpointContent($serviceName, $endpoint)
139  {
140  $this->expandServiceContent($serviceName);
144  $endpointRefSelector = '#operations-%s-%s%s > div';
148  $endpointRefSelector = sprintf($endpointRefSelector, $serviceName, $serviceName, $endpoint);
149  $this->browser->find($endpointRefSelector, Locator::SELECTOR_CSS)->click();
150  }
151 
159  public function closeEndpointContent($serviceName, $endpoint)
160  {
161  $this->expandServiceContent($serviceName);
162 
166  $endpointRefSelector = '#operations-%s-%s%s > div';
167 
171  $endpointRefSelector = sprintf($endpointRefSelector, $serviceName, $serviceName, $endpoint);
172  $this->browser->find($endpointRefSelector, Locator::SELECTOR_CSS)->click();
173  }
174 
180  private function waitForPageToLoad()
181  {
182  $this->waitForElementVisible($this->titleSelector);
183  }
184 
192  private function waitForElementVisible($selector, $strategy = Locator::SELECTOR_CSS)
193  {
195  return $browser->waitUntil(
196  function () use ($browser, $selector, $strategy) {
197  $element = $browser->find($selector, $strategy);
198  return $element->isVisible() ? true : null;
199  }
200  );
201  }
202 
211  private function openSwaggerUrl()
212  {
215  return $browser->waitUntil(
216  function () use ($browser, $pattern) {
217  try {
218  $url = $_ENV['app_frontend_url'] . $pattern;
219  $browser->open($url);
220  return true;
221  } catch (\PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {
222  return false;
223  }
224  }
225  );
226  }
227 }
__construct(BrowserInterface $browser)
$pattern
Definition: website.php:22
closeEndpointContent($serviceName, $endpoint)
expandEndpointContent($serviceName, $endpoint)
isElementVisible($selector, $strategy=Locator::SELECTOR_CSS)
$element
Definition: element.phtml:12