|
39 | 39 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
40 | 40 | */ |
41 | 41 | class behat_theme_boost_union_behat_blocks extends behat_blocks { |
| 42 | + |
| 43 | + /** |
| 44 | + * Checks the order of elements before or after. |
| 45 | + * |
| 46 | + * @Then :arg1 :arg2 should display :arg3 :arg4 :arg5 |
| 47 | + * |
| 48 | + * @param string $selector1 The first element selector. |
| 49 | + * @param string $type1 The type of the first element selector. |
| 50 | + * @param string $order The expected order (before or after). |
| 51 | + * @param string $selector2 The second element selector. |
| 52 | + * @param string $type2 The type of the second element selector. |
| 53 | + */ |
| 54 | + public function assert_element_order($selector1, $type1, $order, $selector2, $type2) { |
| 55 | + $element1 = $this->find($type1, $selector1); |
| 56 | + $element2 = $this->find($type2, $selector2); |
| 57 | + |
| 58 | + if (!$element1) { |
| 59 | + throw new ElementNotFoundException($this->getSession(), 'element', $type1, $selector1); |
| 60 | + } |
| 61 | + |
| 62 | + if (!$element2) { |
| 63 | + throw new ElementNotFoundException($this->getSession(), 'element', $type2, $selector2); |
| 64 | + } |
| 65 | + |
| 66 | + $script = " |
| 67 | + return (function() { |
| 68 | + const el1 = document.querySelector('$selector1'); |
| 69 | + const el2 = document.querySelector('$selector2'); |
| 70 | + const order1 = parseInt(window.getComputedStyle(el1).order); |
| 71 | + const order2 = parseInt(window.getComputedStyle(el2).order); |
| 72 | + return order1 < order2 ? true : false; |
| 73 | + })();"; |
| 74 | + |
| 75 | + $result = $this->evaluate_script($script); |
| 76 | + |
| 77 | + if (($order === 'before' && $result == false) || ($order === 'after' && $result == true)) { |
| 78 | + throw new Exception(sprintf( |
| 79 | + 'The element "%s" (%s) is not displayed %s the element "%s" (%s).', |
| 80 | + $selector1, $type1, $order, $selector2, $type2 |
| 81 | + )); |
| 82 | + } |
| 83 | + } |
42 | 84 | } |
0 commit comments