11<?php
22
3- class EventFiringWebDriver {
3+ class EventFiringWebDriver extends EventFiringObject {
44
55 /**
66 * @var WebDriver
77 */
88 protected $ _webdriver ;
99
10- /**
11- * @var WebDriverDispatcher
12- */
13- protected $ _dispatcher ;
14-
1510 /**
1611 * @param WebDriver $webdriver
1712 * @param WebDriverDispatcher $dispatcher
1813 */
1914 public function __construct (WebDriver $ webdriver , WebDriverDispatcher $ dispatcher = null ) {
2015
21- $ this ->_dispatcher = $ dispatcher ? $ dispatcher : new WebDriverDispatcher () ;
16+ $ this ->_dispatcher = $ dispatcher ? $ dispatcher : new WebDriverDispatcher ;
2217 if (!$ this ->_dispatcher ->getDefaultDriver ())
2318 $ this ->_dispatcher ->setDefaultDriver ($ this );
2419
@@ -28,28 +23,6 @@ public function __construct(WebDriver $webdriver, WebDriverDispatcher $dispatche
2823
2924 }
3025
31- public function __call ($ method , array $ arguments = array ()) {
32-
33- try {
34-
35- return call_user_func_array ([$ this , $ method ], $ arguments );
36-
37- } catch (WebDriverException $ exception ) {
38-
39- $ this ->_dispatch ('onException ' , $ exception , $ this );
40- throw $ exception ;
41-
42- }
43-
44- }
45-
46- /**
47- * @return WebDriverDispatcher
48- */
49- public function getDispatcher () {
50- return $ this ->_dispatcher ;
51- }
52-
5326 /**
5427 * @return WebDriver
5528 */
@@ -58,26 +31,11 @@ public function getWebDriver() {
5831 }
5932
6033 /**
61- * @param $method
62- */
63- protected function _dispatch ($ method ) {
64-
65- $ arguments = func_get_args ();
66- unset($ arguments [0 ]);
67- $ arguments [] = $ this ;
68-
69- $ this ->getDispatcher ()->dispatch ($ method , $ arguments );
70-
71- }
72-
73- /**
74- * Return the EventFiringWebElement with the given id.
75- *
76- * @param string $id The id of the element to be created.
34+ * @param WebDriverElement $element
7735 * @return EventFiringWebElement
7836 */
79- protected function newElement ($ id ) {
80- return new EventFiringWebElement ($ this -> _webdriver -> getExecutor (), $ id , $ this ->getDispatcher ());
37+ protected function newElement (WebDriverElement $ element ) {
38+ return new EventFiringWebElement ($ element , $ this ->getDispatcher ());
8139 }
8240
8341 /**
@@ -102,14 +60,9 @@ protected function findElements(WebDriverBy $by) {
10260
10361 $ this ->_dispatch ('beforeFindBy ' , $ by );
10462
105- $ raw_elements = $ this ->_webdriver ->getExecutor ()->execute ('findElements ' , [
106- 'using ' => $ by ->getMechanism (),
107- 'value ' => $ by ->getValue ()
108- ]);
109-
11063 $ elements = array ();
111- foreach ( $ raw_elements as $ raw_element )
112- $ elements [] = $ this ->newElement ($ raw_element [ ' ELEMENT ' ] );
64+ foreach ( $ this -> _webdriver -> findElements ( $ by ) as $ element )
65+ $ elements [] = $ this ->newElement ($ element );
11366
11467 $ this ->_dispatch ('afterFindBy ' , $ by , $ elements );
11568
@@ -124,13 +77,7 @@ protected function findElements(WebDriverBy $by) {
12477 protected function findElement (WebDriverBy $ by ) {
12578
12679 $ this ->_dispatch ('beforeFindBy ' , $ by );
127-
128- $ raw_element = $ this ->_webdriver ->getExecutor ()->execute ('findElement ' , [
129- 'using ' => $ by ->getMechanism (),
130- 'value ' => $ by ->getValue ()
131- ]);
132- $ element = $ this ->newElement ($ raw_element ['ELEMENT ' ]);
133-
80+ $ element = $ this ->newElement ($ this ->_webdriver ->findElement ($ by ));
13481 $ this ->_dispatch ('afterFindBy ' , $ by , $ element );
13582
13683 return $ element ;
@@ -152,34 +99,6 @@ protected function executeScript($script, array $arguments = array()) {
15299
153100 }
154101
155- /**
156- * Not yet implemented by WebDriver
157- *
158- * @return EventFiringWebDriver
159- */
160- // protected function back() {
161- //
162- // $this->_dispatch('beforeNavigateBack');
163- // $this->_webdriver->back();
164- // $this->_dispatch('afterNavigateBack');
165- // return $this;
166- //
167- // }
168-
169- /**
170- * Not yet implemented by WebDriver
171- *
172- * @return EventFiringWebDriver
173- */
174- // protected function forward() {
175- //
176- // $this->_dispatch('beforeNavigateForward');
177- // $this->_webdriver->forward();
178- // $this->_dispatch('afterNavigateForward');
179- // return $this;
180- //
181- // }
182-
183102 // Implement the following from WebDriver as protected methods so __call catches exceptions
184103
185104 /**
@@ -261,7 +180,7 @@ protected function manage() {
261180 * @return WebDriverNavigation
262181 */
263182 protected function navigate () {
264- return $ this ->_webdriver ->navigate ();
183+ return new EventFiringWebDriverNavigation ( $ this ->_webdriver ->navigate (), $ this -> getDispatcher () );
265184 }
266185
267186 /**
0 commit comments