3f998fa9d451e4b52a4a4508a94dbbc88b9fab8f
[yaffs-website] / vendor / jcalderonzumba / gastonjs / src / Browser / BrowserPageElementTrait.php
1 <?php
2
3 namespace Zumba\GastonJS\Browser;
4
5 /**
6  * Trait BrowserPageElementTrait
7  * @package Zumba\GastonJS\Browser
8  */
9 trait BrowserPageElementTrait {
10   /**
11    * Find elements given a method and a selector
12    * @param $method
13    * @param $selector
14    * @return array
15    */
16   public function find($method, $selector) {
17     $result = $this->command('find', $method, $selector);
18     $found["page_id"] = $result["page_id"];
19     foreach ($result["ids"] as $id) {
20       $found["ids"][] = $id;
21     }
22     return $found;
23   }
24
25   /**
26    * Find elements within a page, method and selector
27    * @param $pageId
28    * @param $elementId
29    * @param $method
30    * @param $selector
31    * @return mixed
32    */
33   public function findWithin($pageId, $elementId, $method, $selector) {
34     return $this->command('find_within', $pageId, $elementId, $method, $selector);
35   }
36
37   /**
38    * @param $pageId
39    * @param $elementId
40    * @return mixed
41    */
42   public function getParents($pageId, $elementId) {
43     return $this->command('parents', $pageId, $elementId);
44   }
45
46   /**
47    * Returns the text of a given page and element
48    * @param $pageId
49    * @param $elementId
50    * @return mixed
51    */
52   public function allText($pageId, $elementId) {
53     return $this->command('all_text', $pageId, $elementId);
54   }
55
56   /**
57    * Returns the inner or outer html of the given page and element
58    * @param $pageId
59    * @param $elementId
60    * @param $type
61    * @return mixed
62    * @throws \Zumba\GastonJS\Exception\BrowserError
63    * @throws \Exception
64    */
65   public function allHtml($pageId, $elementId, $type = "inner") {
66     return $this->command('all_html', $pageId, $elementId, $type);
67   }
68
69   /**
70    * Returns ONLY the visible text of a given page and element
71    * @param $pageId
72    * @param $elementId
73    * @return mixed
74    */
75   public function visibleText($pageId, $elementId) {
76     return $this->command('visible_text', $pageId, $elementId);
77   }
78
79   /**
80    * Deletes the text of a given page and element
81    * @param $pageId
82    * @param $elementId
83    * @return mixed
84    */
85   public function deleteText($pageId, $elementId) {
86     return $this->command('delete_text', $pageId, $elementId);
87   }
88
89   /**
90    * Gets the tag name of a given element and page
91    * @param $pageId
92    * @param $elementId
93    * @return string
94    */
95   public function tagName($pageId, $elementId) {
96     return strtolower($this->command('tag_name', $pageId, $elementId));
97   }
98
99   /**
100    * Check if two elements are the same on a give
101    * @param $pageId
102    * @param $firstId
103    * @param $secondId
104    * @return bool
105    */
106   public function equals($pageId, $firstId, $secondId) {
107     return $this->command('equals', $pageId, $firstId, $secondId);
108   }
109
110   /**
111    * Returns the attributes of an element in a given page
112    * @param $pageId
113    * @param $elementId
114    * @return mixed
115    */
116   public function attributes($pageId, $elementId) {
117     return $this->command('attributes', $pageId, $elementId);
118   }
119
120   /**
121    * Returns the attribute of an element by name in a given page
122    * @param $pageId
123    * @param $elementId
124    * @param $name
125    * @return mixed
126    */
127   public function attribute($pageId, $elementId, $name) {
128     return $this->command('attribute', $pageId, $elementId, $name);
129   }
130
131   /**
132    * Set an attribute to the given element in the given page
133    * @param $pageId
134    * @param $elementId
135    * @param $name
136    * @param $value
137    * @return mixed
138    * @throws \Zumba\GastonJS\Exception\BrowserError
139    * @throws \Exception
140    */
141   public function setAttribute($pageId, $elementId, $name, $value) {
142     return $this->command('set_attribute', $pageId, $elementId, $name, $value);
143   }
144
145   /**
146    * Remove an attribute for a given page and element
147    * @param $pageId
148    * @param $elementId
149    * @param $name
150    * @return mixed
151    * @throws \Zumba\GastonJS\Exception\BrowserError
152    * @throws \Exception
153    */
154   public function removeAttribute($pageId, $elementId, $name) {
155     return $this->command('remove_attribute', $pageId, $elementId, $name);
156   }
157
158   /**
159    * Checks if an element is visible or not
160    * @param $pageId
161    * @param $elementId
162    * @return boolean
163    */
164   public function isVisible($pageId, $elementId) {
165     return $this->command("visible", $pageId, $elementId);
166   }
167
168   /**
169    * Sends the order to execute a key event on a given element
170    * @param $pageId
171    * @param $elementId
172    * @param $keyEvent
173    * @param $key
174    * @param $modifier
175    * @return mixed
176    */
177   public function keyEvent($pageId, $elementId, $keyEvent, $key, $modifier) {
178     return $this->command("key_event", $pageId, $elementId, $keyEvent, $key, $modifier);
179   }
180
181   /**
182    * Sends the command to select and option given a value
183    * @param      $pageId
184    * @param      $elementId
185    * @param      $value
186    * @param bool $multiple
187    * @return mixed
188    */
189   public function selectOption($pageId, $elementId, $value, $multiple = false) {
190     return $this->command("select_option", $pageId, $elementId, $value, $multiple);
191   }
192
193 }