Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PaypalIframe.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Mtf\Client\ElementInterface;
10 use Magento\Mtf\Fixture\FixtureInterface;
11 
15 class PaypalIframe extends Method
16 {
22  private $payNowButton = '#btn_pay_cc';
23 
29  private $paypalIframe = '.paypal.iframe';
30 
36  private $creditCardForm = '#formCreditCard';
37 
43  private $errorMessage = '#messageBox';
44 
50  protected $formBlockCc;
51 
57  protected $loader = '#lightBoxDiv';
58 
65  public function fillPaymentData(FixtureInterface $creditCard)
66  {
67  $iframeRootElement = $this->switchToPaypalFrame();
68  $formBlock = $this->blockFactory->create(
69  $this->formBlockCc,
70  ['element' => $this->_rootElement->find($this->creditCardForm)]
71  );
72  $formBlock->fill($creditCard, $iframeRootElement);
73  $iframeRootElement->find($this->payNowButton)->click();
74 
75  $this->waitSubmitForm($iframeRootElement);
76 
77  $this->browser->switchToFrame();
78  }
79 
86  protected function waitSubmitForm(ElementInterface $iframeRootElement)
87  {
88  $loaderElement = $iframeRootElement->find($this->loader);
89 
90  $loaderElement->waitUntil(function () use ($loaderElement) {
91  return $loaderElement->isVisible() ? true : null;
92  });
93 
94  $loaderElement->waitUntil(function () use ($loaderElement) {
95  return !$loaderElement->isVisible() ? true : null;
96  });
97  }
98 
104  public function isErrorMessageVisible()
105  {
106  $isErrorMessageVisible = false;
107  if ($this->_rootElement->find($this->paypalIframe)->isPresent()) {
108  $iframeRootElement = $this->switchToPaypalFrame();
109  $isErrorMessageVisible = $iframeRootElement->find($this->errorMessage)->isVisible();
110  $this->browser->switchToFrame();
111  }
112  return $isErrorMessageVisible;
113  }
114 
120  private function switchToPaypalFrame()
121  {
122  $iframeLocator = $this->browser->find($this->paypalIframe)->getLocator();
123  $this->browser->switchToFrame($iframeLocator);
124  return $this->browser->find('body');
125  }
126 }
waitSubmitForm(ElementInterface $iframeRootElement)