Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ChosenOption.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Client\Locator;
10 use Magento\Mtf\Client\Element\SimpleElement;
11 
15 class ChosenOption extends SimpleElement
16 {
22  protected $selectButton = '//ancestor::body//button[contains(@class,"btn-chooser")]';
23 
29  protected $loaderOld = '//ancestor::body/div[@id="loading-mask"]';
30 
31  // @codingStandardsIgnoreStart
37  protected $selectBlock = "//ancestor::body//aside[contains(@class,'_show')]//*[contains(@id,'responseCntoptions')]";
38  // @codingStandardsIgnoreEnd
39 
45  protected $pageWidgetChooserBlockClass = \Magento\Cms\Test\Block\Adminhtml\Page\Widget\Chooser::class;
46 
52  protected $categoryWidgetChooserBlockClass = \Magento\Catalog\Test\Block\Adminhtml\Category\Widget\Chooser::class;
53 
59  protected $productWidgetChooserBlockClass = \Magento\Catalog\Test\Block\Adminhtml\Product\Widget\Chooser::class;
60 
66  protected $chooserClasses = [
67  'page' => \Magento\Cms\Test\Block\Adminhtml\Page\Widget\Chooser::class,
68  'category' => \Magento\Catalog\Test\Block\Adminhtml\Category\Widget\Chooser::class,
69  'product' => \Magento\Catalog\Test\Block\Adminhtml\Product\Widget\Chooser::class,
70  ];
71 
78  public function setValue($value)
79  {
80  $this->clickSelectButton();
81  if (isset($value['filter_url_key'])) {
82  $this->getClassBlock($this->chooserClasses['page'])
83  ->searchAndOpen(['chooser_identifier' => $value['filter_url_key']]);
84  }
85  if (isset($value['filter_identifier'])) {
86  $this->getClassBlock($this->chooserClasses['page'])
87  ->searchAndOpen(['chooser_identifier' => $value['filter_identifier']]);
88  }
89  if (isset($value['category_path'])) {
90  if (isset($value['filter_sku'])) {
91  $this->getClassBlock($this->chooserClasses['category'])
92  ->selectCategoryByName($value['category_path']);
93  $this->getClassBlock($this->chooserClasses['product'])
94  ->searchAndOpen(['chooser_sku' => $value['filter_sku']]);
95  } else {
96  $this->getClassBlock($this->chooserClasses['category'])
97  ->selectCategoryByName($value['category_path']);
98  }
99  }
100  }
101 
107  protected function clickSelectButton()
108  {
109  $this->find($this->selectButton, Locator::SELECTOR_XPATH)->click();
110  $this->waitLoader();
111  }
112 
118  protected function waitLoader()
119  {
120  $browser = $this;
121  $loaderSelector = $this->loaderOld;
122  $this->waitUntil(
123  function () use ($browser, $loaderSelector) {
124  $loader = $browser->find($loaderSelector);
125  return $loader->isVisible() == false ? true : null;
126  }
127  );
128  }
129 
136  protected function getClassBlock($class)
137  {
138  return \Magento\Mtf\ObjectManager::getInstance()->create(
139  $class,
140  ['element' => $this->find($this->selectBlock, Locator::SELECTOR_XPATH)]
141  );
142  }
143 }
taxRateField find('.mselect-list') .on( 'click.mselect-edit'
Definition: edit.phtml:162
$loader
Definition: autoload.php:8
$_option $_optionId $class
Definition: date.phtml:13
$value
Definition: gender.phtml:16