TreeElement.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Mtf\Client\Element;
  7. use Magento\Mtf\Client\ElementInterface;
  8. use Magento\Mtf\Client\Locator;
  9. /**
  10. * Typified element class for Tree elements.
  11. */
  12. class TreeElement extends Tree
  13. {
  14. /**
  15. * All selected checkboxes.
  16. *
  17. * @var string
  18. */
  19. protected $selectedCheckboxes = '//input[@checked=""]';
  20. /**
  21. * Selector for plus image.
  22. *
  23. * @var string
  24. */
  25. protected $imagePlus = './div/img[contains(@class, "-plus")]';
  26. /**
  27. * Selector for input.
  28. *
  29. * @var string
  30. */
  31. protected $input = '/div/a/span';
  32. /**
  33. * Selector for parent element.
  34. *
  35. * @var string
  36. */
  37. protected $parentElement = './../../../../../div/a/span';
  38. /**
  39. * Selected checkboxes.
  40. *
  41. * @var string
  42. */
  43. protected $selectedLabels = '//input[@checked=""]/../a/span';
  44. /**
  45. * Pattern for child element node.
  46. *
  47. * @var string
  48. */
  49. protected $pattern = '//li[@class="x-tree-node" and div/a/span[contains(text(),"%s")]]';
  50. /**
  51. * Regular pattern mask for node label.
  52. *
  53. * @var string
  54. */
  55. protected $regPatternLabel = '`(.+) \(.*`';
  56. /**
  57. * Clear data for element.
  58. *
  59. * @return void
  60. */
  61. public function clear()
  62. {
  63. $checkboxes = $this->getElements($this->selectedCheckboxes, Locator::SELECTOR_XPATH, 'checkbox');
  64. foreach ($checkboxes as $checkbox) {
  65. $checkbox->setValue('No');
  66. }
  67. }
  68. /**
  69. * Display children.
  70. *
  71. * @param string $element
  72. * @return void
  73. */
  74. protected function displayChildren($element)
  75. {
  76. $element = $this->find(sprintf($this->pattern, $element), Locator::SELECTOR_XPATH);
  77. $plusButton = $element->find($this->imagePlus, Locator::SELECTOR_XPATH);
  78. if ($plusButton->isVisible()) {
  79. $plusButton->click();
  80. $this->waitLoadChildren($element);
  81. }
  82. }
  83. /**
  84. * Get element label.
  85. *
  86. * @param ElementInterface $element
  87. * @return string
  88. */
  89. protected function getElementLabel(ElementInterface $element)
  90. {
  91. $value = $element->getText();
  92. preg_match($this->regPatternLabel, $value, $matches);
  93. return trim($matches[1]);
  94. }
  95. }