1: <?php
2: namespace Azalea\Selenium\App\Components;
3:
4: use Azalea\Selenium\Toolkit\View;
5:
6: class Popup extends View
7: {
8: /**
9: * Closes the popup view.
10: *
11: * @return $this
12: */
13: public function close()
14: {
15: $this->querySelector(".popup_title a.close")
16: ->click();
17: return $this;
18: }
19:
20: /**
21: * Returns the first popup view found in the DOM as
22: * a Dom object scoped to that popup.
23: *
24: * @return \Azalea\Selenium\Toolkit\Dom
25: */
26: public function first()
27: {
28: return $this->driver->filter("body > .popup");
29: }
30:
31: /**
32: * Returns the last popup view found in the DOM as
33: * a Dom object scoped to that popup.
34: *
35: * @return \Azalea\Selenium\Toolkit\Dom
36: */
37: public function last()
38: {
39: return $this->driver->filter("body > .popup:last-of-type");
40: }
41:
42: /**
43: * Gets a count of the number of popups on the screen.
44: *
45: * @return int
46: */
47: public function count()
48: {
49: $elems = $this->querySelectorAll(".popup");
50: return count($elems);
51: }
52:
53: /**
54: * A confirm popup is showing on the top of the popup stack.
55: *
56: * @return bool
57: */
58: public function confirmIsVisible()
59: {
60: return $this->last()->canSeeElement("#button_confirm");
61: }
62:
63: /**
64: * Confirm a popup confirmation.
65: *
66: * @return $this
67: */
68: public function confirmYes()
69: {
70: $this->driver->waitFor("#button_confirm")->click();
71: return $this;
72: }
73:
74: /**
75: * Cancel a popup confirmation.
76: *
77: * @return $this
78: */
79: public function confirmCancel()
80: {
81: $this->driver->waitFor("#button_cancel")->click();
82: return $this;
83: }
84:
85: /**
86: * Close all visible popups on the screen.
87: */
88: public function closeAll()
89: {
90: $elements = $this->driver->querySelectorAll("span.popup_menu > a.close");
91: if (count($elements)) {
92: foreach($elements as $element) {
93: $element->click();
94: }
95: }
96: }
97: }
98:
99: ?>