Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PromotedSection.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Block\Block;
10 use Magento\Mtf\Client\Locator;
11 use Magento\Mtf\Fixture\FixtureInterface;
12 
16 class PromotedSection extends Block
17 {
23  protected $productItem = 'li.product-item';
24 
30  protected $productItemByName = './/*[contains(@class,"product-item-link") and @title="%s"]/ancestor::li';
31 
37  public function isVisible()
38  {
39  return $this->_rootElement->isVisible();
40  }
41 
48  public function getProductItem(FixtureInterface $product)
49  {
50  $locator = sprintf($this->productItemByName, $product->getName());
51 
52  return $this->blockFactory->create(
53  \Magento\Catalog\Test\Block\Product\ProductList\ProductItem::class,
54  ['element' => $this->_rootElement->find($locator, Locator::SELECTOR_XPATH)]
55  );
56  }
57 
63  public function getProducts()
64  {
65  if (!$this->_rootElement->isVisible($this->productItem)) {
66  return [];
67  }
68 
69  $elements = $this->_rootElement->getElements($this->productItem, Locator::SELECTOR_CSS);
70  $result = [];
71 
72  foreach ($elements as $element) {
73  $result[] = $this->blockFactory->create(
74  \Magento\Catalog\Test\Block\Product\ProductList\ProductItem::class,
75  ['element' => $element]
76  );
77  }
78 
79  return $result;
80  }
81 }
$element
Definition: element.phtml:12