Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StoreTree.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 StoreTree extends SimpleElement
16 {
22  protected $website = './/label[contains(text(), "%s")]';
23 
29  protected $selectedWebsite = '(.//input[contains(@name, "product[website_ids]") and not(@value="0")])[%d]/../label';
30 
38  public function setValue($values)
39  {
40  $this->clearValue();
41 
42  $values = is_array($values) ? $values : [$values];
43  foreach ($values as $value) {
44  $website = $this->find(sprintf($this->website, $value), Locator::SELECTOR_XPATH);
45  if (!$website->isVisible()) {
46  throw new \Exception("Can't find website: \"{$value}\".");
47  }
48  if (!$website->isSelected()) {
49  $website->click();
50  }
51  }
52  }
53 
59  public function getValue()
60  {
61  $values = [];
62 
63  $count = 1;
64  $website = $this->find(sprintf($this->selectedWebsite, $count), Locator::SELECTOR_XPATH);
65  while ($website->isVisible()) {
66  $values[] = $website->getText();
67  ++$count;
68  $website = $this->find(sprintf($this->selectedWebsite, $count), Locator::SELECTOR_XPATH);
69  }
70  return $values;
71  }
72 
78  private function clearValue()
79  {
80  foreach ($this->getValue() as $value) {
81  $this->find(sprintf($this->website, $value), Locator::SELECTOR_XPATH)->click();
82  }
83  }
84 }
$count
Definition: recent.phtml:13
taxRateField find('.mselect-list') .on( 'click.mselect-edit'
Definition: edit.phtml:162
$values
Definition: options.phtml:88
$value
Definition: gender.phtml:16