Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
WidgetView.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Mtf\Block\Block;
11 use Magento\Mtf\Client\Locator;
12 
16 class WidgetView extends Block
17 {
23  protected $widgetLinkSelector = '//a[contains(.,"%s")]';
24 
30  protected $widgetSelector = '//div[contains(.,"%s")]';
31 
40  public function isWidgetVisible(Widget $widget, $widgetText)
41  {
42  $widgetType = $this->getWidgetType($widget);
43  if ($this->hasRender($widgetType)) {
44  return $this->callRender(
45  $widgetType,
46  'isWidgetVisible',
47  ['widget' => $widget, 'widgetText' => $widgetText]
48  );
49  } else {
50  if (isset($this->widgetSelector)) {
51  return $this->_rootElement->find(
52  sprintf($this->widgetSelector, $widgetText),
53  Locator::SELECTOR_XPATH
54  )->isVisible();
55  } else {
56  throw new \Exception('Determine how to find the widget on the page.');
57  }
58  }
59  }
60 
69  public function clickToWidget(Widget $widget, $widgetText)
70  {
71  $widgetType = $this->getWidgetType($widget);
72  if ($this->hasRender($widgetType)) {
73  $this->callRender($widgetType, 'clickToWidget', ['widget' => $widget, 'widgetText' => $widgetText]);
74  } else {
75  if (isset($this->widgetLinkSelector)) {
76  $this->_rootElement->find(
77  sprintf($this->widgetLinkSelector, $widgetText),
78  Locator::SELECTOR_XPATH
79  )->click();
80  } else {
81  throw new \Exception('Determine how to find the widget on the page.');
82  }
83  }
84  }
85 
92  protected function getWidgetType(Widget $widget)
93  {
94  return lcfirst(str_replace(' ', '', ucwords(strtolower($widget->getCode()))));
95  }
96 }
isWidgetVisible(Widget $widget, $widgetText)
Definition: WidgetView.php:40
clickToWidget(Widget $widget, $widgetText)
Definition: WidgetView.php:69