Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
View Class Reference
Inheritance diagram for View:
AbstractConfigureBlock View Summary View View View View ViewWithSwatches

Public Member Functions

 isThresholdMessageDisplayed ()
 
 getThresholdMessage ()
 
 getPriceBlock (FixtureInterface $product=null)
 
 addToCart (FixtureInterface $product)
 
 clickAddToCart ()
 
 setQtyAndClickAddToCart ($qty)
 
 setQty ($qty)
 
 isVisibleAddToCart ()
 
 paypalCheckout ()
 
 inContextPaypalCheckout ()
 
 braintreePaypalCheckout ()
 
 getProductName ()
 
 getProductSku ()
 
 getProductShortDescription ()
 
 getProductDescription ()
 
 getTierPrices ($lineNumber=1)
 
 clickAddToCartButton ()
 
 isVisibleAddToCardButton ()
 
 stockAvailability ()
 
 clickAddToWishlist ()
 
 selectTab ($name)
 
 waitLoader ()
 
 isGalleryVisible ()
 
 isFullImageVisible ()
 
 getFullImageSource ()
 
 isBaseImageVisible ()
 
 getBaseImageSource ()
 
 clickBaseImage ()
 
 closeFullImage ()
 
 isVideoVisible ()
 
 checkVideoDataPresence ($videoData)
 
- Public Member Functions inherited from AbstractConfigureBlock
 getCustomOptionsBlock ()
 
 setQty ($qty)
 

Protected Attributes

 $tabSelector = './/div[@data-role="collapsible" and a[contains(text(),"%s")]]'
 
 $customOptionsSelector = '.product-options-wrapper'
 
 $addToCart = '.tocart'
 
 $qty = '#qty'
 
 $addToCartForm = '#product_addtocart_form'
 
 $paypalCheckout = '[data-action=checkout-form-submit]'
 
 $inContextPaypalCheckout = 'ul.checkout-methods-items a[data-action="paypal-in-context-checkout"]'
 
 $productName = '.page-title-wrapper.product h1.page-title .base'
 
 $productSku = '[itemprop="sku"]'
 
 $productDescription = '.product.attribute.description .value'
 
 $productShortDescription = '.product.attribute.overview'
 
 $stockAvailability = '.stock span'
 
 $tierPricesSelector = "//ul[contains(@class,'tier')]//*[@class='item'][%line-number%]"
 
 $priceBlock = '//*[@class="product-info-main"]//*[contains(@class,"price-box")]'
 
 $clickAddToCompare = '.action.tocompare'
 
 $addToWishlist = '[data-action="add-to-wishlist"]'
 
 $messageBlock = '.page.messages'
 
 $miniCartBlockSelector = '[data-block="minicart"]'
 
 $successMessage = '[data-ui-id$=message-success]'
 
 $mediaGallery = '[data-gallery-role="gallery"] img'
 
 $ajaxLoading = 'body.ajax-loading'
 
 $fullImage = '[data-gallery-role="gallery"] img.fotorama__img--full'
 
 $fullImageClose = '[data-gallery-role="fotorama__fullscreen-icon"]'
 
 $baseImage = '[data-gallery-role="gallery"] img.fotorama__img.fotorama__img'
 
 $galleryLoader = '.fotorama__spinner--show'
 
- Protected Attributes inherited from AbstractConfigureBlock
 $customOptionsSelector
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractConfigureBlock
 prepareCheckoutData (array $options, array $checkoutData)
 

Detailed Description

Product view block on the product page.

@SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.ExcessivePublicCount) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 22 of file View.php.

Member Function Documentation

◆ addToCart()

addToCart ( FixtureInterface  $product)

Add product to shopping cart.

Parameters
FixtureInterface$product
Returns
void

Definition at line 275 of file View.php.

276  {
277  $this->configure($product);
278  $this->clickAddToCart();
279  $this->getMiniCartBlock()->waitLoader();
280  }

◆ braintreePaypalCheckout()

braintreePaypalCheckout ( )

Press 'Check out with Braintree PayPal' button.

Returns
string

Definition at line 388 of file View.php.

389  {
390  $currentWindow = $this->browser->getCurrentWindow();
391  $this->getMiniCartBlock()->openMiniCart();
392  $this->getMiniCartBlock()->clickBraintreePaypalButton();
393  return $currentWindow;
394  }

◆ checkVideoDataPresence()

checkVideoDataPresence (   $videoData)

Check definite video data is presented on product page

Parameters
string$videoData
Returns
bool

Definition at line 675 of file View.php.

676  {
677  $dataVideoSelector = $this->productVideo . '[data-code="' . $videoData. '"]';
678  return $this->_rootElement->find($dataVideoSelector)->isPresent();
679  }

◆ clickAddToCart()

clickAddToCart ( )

Click link.

Returns
void

Definition at line 322 of file View.php.

323  {
324  $this->_rootElement->find($this->addToCart, Locator::SELECTOR_CSS)->click();
325  }
addToCart(FixtureInterface $product)
Definition: View.php:275

◆ clickAddToCartButton()

clickAddToCartButton ( )

Click "ADD TO CART" button.

Returns
void

Definition at line 480 of file View.php.

481  {
482  $this->_rootElement->find($this->addToCart, Locator::SELECTOR_CSS)->click();
483  }
addToCart(FixtureInterface $product)
Definition: View.php:275

◆ clickAddToWishlist()

clickAddToWishlist ( )

Click "Add to Wish List".

Returns
void

Definition at line 543 of file View.php.

544  {
545  $this->_rootElement->find($this->addToWishlist)->click();
546  }

◆ clickBaseImage()

clickBaseImage ( )

Click link.

Returns
void

Definition at line 631 of file View.php.

632  {
633  $this->_rootElement->find($this->baseImage, Locator::SELECTOR_CSS)->click();
634  $this->waitForElementVisible($this->fullImage);
635  }

◆ closeFullImage()

closeFullImage ( )

Click link.

Returns
void

Definition at line 642 of file View.php.

643  {
644  $this->_rootElement->waitUntil(
645  function () {
646  $this->browser->find($this->fullImage)->hover();
647 
648  if ($this->browser->find($this->fullImageClose)->isVisible()) {
649  $this->browser->find($this->fullImageClose)->click();
650 
651  return true;
652  }
653 
654  return null;
655  }
656  );
657  }

◆ getBaseImageSource()

getBaseImageSource ( )

Get full image source from media gallery into product

Returns
string

Definition at line 621 of file View.php.

622  {
623  return $this->_rootElement->find($this->baseImage)->getAttribute('src');
624  }

◆ getFullImageSource()

getFullImageSource ( )

Get full image source from media gallery into product

Returns
string

Definition at line 601 of file View.php.

602  {
603  return $this->browser->find($this->fullImage)->getAttribute('src');
604  }

◆ getPriceBlock()

getPriceBlock ( FixtureInterface  $product = null)

Get block price.

Parameters
FixtureInterface | null$product
Returns
Price

Definition at line 250 of file View.php.

251  {
252  $typeId = '';
253 
254  if ($product) {
255  $dataConfig = $product->getDataConfig();
256  $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null;
257  }
258 
259  if ($this->hasRender($typeId)) {
260  return $this->callRender($typeId, 'getPriceBlock');
261  }
262 
263  return $this->blockFactory->create(
264  \Magento\Catalog\Test\Block\Product\Price::class,
265  ['element' => $this->_rootElement->find($this->priceBlock, Locator::SELECTOR_XPATH)]
266  );
267  }

◆ getProductDescription()

getProductDescription ( )

Return product description on page.

Returns
string|null

Definition at line 434 of file View.php.

435  {
436  if ($this->_rootElement->find($this->productDescription, Locator::SELECTOR_CSS)->isVisible()) {
437  return $this->_rootElement->find($this->productDescription, Locator::SELECTOR_CSS)->getText();
438  }
439  return null;
440  }

◆ getProductName()

getProductName ( )

Get product name displayed on page.

Returns
string

Definition at line 401 of file View.php.

402  {
403  return $this->_rootElement->find($this->productName, Locator::SELECTOR_CSS)->getText();
404  }

◆ getProductShortDescription()

getProductShortDescription ( )

Return product short description on page.

Returns
string|null

Definition at line 421 of file View.php.

422  {
423  if ($this->_rootElement->find($this->productShortDescription, Locator::SELECTOR_CSS)->isVisible()) {
424  return $this->_rootElement->find($this->productShortDescription, Locator::SELECTOR_CSS)->getText();
425  }
426  return null;
427  }

◆ getProductSku()

getProductSku ( )

Get product sku displayed on page.

Returns
string

Definition at line 411 of file View.php.

412  {
413  return $this->_rootElement->find($this->productSku, Locator::SELECTOR_CSS)->getText();
414  }

◆ getThresholdMessage()

getThresholdMessage ( )

Gets threshold message.

Returns
string

Definition at line 238 of file View.php.

239  {
240  return $this->_rootElement->find($this->thresholdMessage)->getText();
241  }

◆ getTierPrices()

getTierPrices (   $lineNumber = 1)

This method return array tier prices.

Parameters
int$lineNumber[optional]
Returns
array

Definition at line 467 of file View.php.

468  {
469  return $this->_rootElement->find(
470  str_replace('%line-number%', $lineNumber, $this->tierPricesSelector),
471  Locator::SELECTOR_XPATH
472  )->getText();
473  }

◆ inContextPaypalCheckout()

inContextPaypalCheckout ( )

Press 'Check out with PayPal' button.

Returns
void

Definition at line 377 of file View.php.

378  {
379  $this->_rootElement->find($this->inContextPaypalCheckout, Locator::SELECTOR_CSS)->click();
380  $this->waitForElementNotVisible($this->inContextPaypalCheckout);
381  }

◆ isBaseImageVisible()

isBaseImageVisible ( )

Check is base image into gallery is visible for the product.

Returns
bool

Definition at line 611 of file View.php.

612  {
613  return $this->_rootElement->find($this->baseImage)->isVisible();
614  }

◆ isFullImageVisible()

isFullImageVisible ( )

Check is full image into gallery is visible for the product.

Returns
bool

Definition at line 590 of file View.php.

591  {
592  $this->waitForElementNotVisible($this->galleryLoader);
593  return $this->browser->find($this->fullImage)->isVisible();
594  }

◆ isGalleryVisible()

isGalleryVisible ( )

Check if media gallery is visible for the product.

Returns
bool

Definition at line 577 of file View.php.

578  {
579  $this->waitForElementNotVisible($this->galleryLoader);
580  $this->waitForElementVisible($this->mediaGallery);
581 
582  return true;
583  }

◆ isThresholdMessageDisplayed()

isThresholdMessageDisplayed ( )

Checks if threshold message is displayed.

Returns
bool

Definition at line 228 of file View.php.

229  {
230  return $this->_rootElement->find($this->thresholdMessage)->isVisible();
231  }

◆ isVideoVisible()

isVideoVisible ( )

Check is video is visible on product page

Returns
bool

Definition at line 664 of file View.php.

665  {
666  return $this->_rootElement->find($this->videoContainer)->isVisible();
667  }

◆ isVisibleAddToCardButton()

isVisibleAddToCardButton ( )

Check 'Add to card' button visible.

Returns
bool

Definition at line 490 of file View.php.

491  {
492  return $this->_rootElement->find($this->addToCart, Locator::SELECTOR_CSS)->isVisible();
493  }
addToCart(FixtureInterface $product)
Definition: View.php:275

◆ isVisibleAddToCart()

isVisibleAddToCart ( )

Find Add To Cart button.

Returns
bool

Definition at line 356 of file View.php.

357  {
358  return $this->_rootElement->find($this->addToCart, Locator::SELECTOR_CSS)->isVisible();
359  }
addToCart(FixtureInterface $product)
Definition: View.php:275

◆ paypalCheckout()

paypalCheckout ( )

Press 'Check out with PayPal' button.

Returns
void

Definition at line 366 of file View.php.

367  {
368  $this->_rootElement->find($this->paypalCheckout, Locator::SELECTOR_CSS)->click();
369  $this->waitForElementNotVisible($this->paypalCheckout);
370  }

◆ selectTab()

selectTab (   $name)

Select tab on the product page.

Parameters
string$name
Returns
void

Definition at line 554 of file View.php.

555  {
556  $this->_rootElement->find(sprintf($this->tabSelector, $name), Locator::SELECTOR_XPATH)->click();
557  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setQty()

setQty (   $qty)

Set quantity.

Parameters
int$qty
Returns
void

Definition at line 345 of file View.php.

346  {
347  $this->_rootElement->find($this->qty)->setValue($qty);
348  $this->_rootElement->find($this->addToCartForm)->click();
349  }

◆ setQtyAndClickAddToCart()

setQtyAndClickAddToCart (   $qty)

Set quantity and click add to cart.

Parameters
int$qty
Returns
void

Definition at line 333 of file View.php.

334  {
335  $this->_rootElement->find($this->qty, Locator::SELECTOR_CSS)->setValue($qty);
336  $this->clickAddToCart();
337  }

◆ stockAvailability()

stockAvailability ( )

Get text of Stock Availability control.

Returns
string

Definition at line 500 of file View.php.

501  {
502  return strtolower($this->_rootElement->find($this->stockAvailability)->getText());
503  }

◆ waitLoader()

waitLoader ( )

Wait loading block.

Returns
void

Definition at line 564 of file View.php.

565  {
566  try {
567  $this->waitForElementNotVisible($this->ajaxLoading);
568  } catch (\Exception $e) {
569  }
570  }

Field Documentation

◆ $addToCart

$addToCart = '.tocart'
protected

Definition at line 43 of file View.php.

◆ $addToCartForm

$addToCartForm = '#product_addtocart_form'
protected

Definition at line 57 of file View.php.

◆ $addToWishlist

$addToWishlist = '[data-action="add-to-wishlist"]'
protected

Definition at line 134 of file View.php.

◆ $ajaxLoading

$ajaxLoading = 'body.ajax-loading'
protected

Definition at line 176 of file View.php.

◆ $baseImage

$baseImage = '[data-gallery-role="gallery"] img.fotorama__img.fotorama__img'
protected

Definition at line 197 of file View.php.

◆ $clickAddToCompare

$clickAddToCompare = '.action.tocompare'
protected

Definition at line 127 of file View.php.

◆ $customOptionsSelector

$customOptionsSelector = '.product-options-wrapper'
protected

Definition at line 36 of file View.php.

◆ $fullImage

$fullImage = '[data-gallery-role="gallery"] img.fotorama__img--full'
protected

Definition at line 183 of file View.php.

◆ $fullImageClose

$fullImageClose = '[data-gallery-role="fotorama__fullscreen-icon"]'
protected

Definition at line 190 of file View.php.

◆ $galleryLoader

$galleryLoader = '.fotorama__spinner--show'
protected

Definition at line 202 of file View.php.

◆ $inContextPaypalCheckout

$inContextPaypalCheckout = 'ul.checkout-methods-items a[data-action="paypal-in-context-checkout"]'
protected

Definition at line 71 of file View.php.

◆ $mediaGallery

$mediaGallery = '[data-gallery-role="gallery"] img'
protected

Definition at line 169 of file View.php.

◆ $messageBlock

$messageBlock = '.page.messages'
protected

Definition at line 141 of file View.php.

◆ $miniCartBlockSelector

$miniCartBlockSelector = '[data-block="minicart"]'
protected

Definition at line 148 of file View.php.

◆ $paypalCheckout

$paypalCheckout = '[data-action=checkout-form-submit]'
protected

Definition at line 64 of file View.php.

◆ $priceBlock

$priceBlock = '//*[@class="product-info-main"]//*[contains(@class,"price-box")]'
protected

Definition at line 120 of file View.php.

◆ $productDescription

$productDescription = '.product.attribute.description .value'
protected

Definition at line 92 of file View.php.

◆ $productName

$productName = '.page-title-wrapper.product h1.page-title .base'
protected

Definition at line 78 of file View.php.

◆ $productShortDescription

$productShortDescription = '.product.attribute.overview'
protected

Definition at line 99 of file View.php.

◆ $productSku

$productSku = '[itemprop="sku"]'
protected

Definition at line 85 of file View.php.

◆ $qty

$qty = '#qty'
protected

Definition at line 50 of file View.php.

◆ $stockAvailability

$stockAvailability = '.stock span'
protected

Definition at line 106 of file View.php.

◆ $successMessage

$successMessage = '[data-ui-id$=message-success]'
protected

Definition at line 162 of file View.php.

◆ $tabSelector

$tabSelector = './/div[@data-role="collapsible" and a[contains(text(),"%s")]]'
protected

Definition at line 29 of file View.php.

◆ $tierPricesSelector

$tierPricesSelector = "//ul[contains(@class,'tier')]//*[@class='item'][%line-number%]"
protected

Definition at line 113 of file View.php.


The documentation for this class was generated from the following file: