@@ -28,6 +28,19 @@ function unwind_associated_array($arr) {
2828 }
2929}
3030
31+ function unwind_array ($ arr ) {
32+ if (count ($ arr ) > 0 ) {
33+ $ u = "array( " ;
34+ foreach ($ arr as $ a ) {
35+ $ u = $ u . '" ' . $ a . '" ' . ", " ;
36+ }
37+ $ u = $ u . ") " ;
38+ return $ u ;
39+ } else {
40+ return "array() " ;
41+ }
42+ }
43+
3144class PHPWebDriver_WebDriverActionChains {
3245 protected $ session ;
3346 protected $ actions = array ();
@@ -39,7 +52,7 @@ public function __construct($session) {
3952
4053 public function perform () {
4154 foreach ($ this ->actions as $ action ) {
42- // var_dump($action);
55+ var_dump ($ action );
4356 $ before = error_get_last ();
4457 $ result = eval ($ action );
4558 $ after = error_get_last ();
@@ -95,9 +108,41 @@ public function dragAndDropByOffset($source, $target, $xOffset, $yOffset, $curl_
95108 return $ this ;
96109 }
97110
98- public function keyDown ($ value , $ onElement = null ) {}
99-
100- public function keyUp ($ value , $ onElement = null ) {}
111+ public function keyDown ($ value , $ curl_opts = array ()) {
112+ $ typing = array ();
113+ if (is_a ($ value , 'PHPWebDriver_WebDriverKeys ' )) {
114+ array_push ($ typing , $ value ->key );
115+ // }
116+ // if (is_int($value)) {
117+ // $val = strval($val);
118+ // foreach($val as $i) {
119+ // array_push($typing, $i);
120+ // }
121+ } else {
122+ array_push ($ typing , str_split ($ value ));
123+ }
124+
125+ $ this ->actions [] = '$this->session->keys(array("value" => ' . unwind_array ($ typing ) . '), ' . unwind_associated_array ($ curl_opts ) . '); ' ;
126+ return $ this ;
127+ }
128+
129+ public function keyUp ($ value , $ curl_opts = array ()) {
130+ $ typing = array ();
131+ if (is_a ($ value , 'PHPWebDriver_WebDriverKeys ' )) {
132+ array_push ($ typing , $ value ->key );
133+ // }
134+ // if (is_int($value)) {
135+ // $val = strval($val);
136+ // foreach($val as $i) {
137+ // array_push($typing, $i);
138+ // }
139+ } else {
140+ array_push ($ typing , str_split ($ value ));
141+ }
142+
143+ $ this ->actions [] = '$this->session->keys(array("value" => ' . unwind_array ($ typing ) . '), ' . unwind_associated_array ($ curl_opts ) . '); ' ;
144+ return $ this ;
145+ }
101146
102147 public function moveByOffset ($ xOffset , $ yOffset , $ curl_opts = array ()) {
103148 $ this ->actions [] = '$this->session->moveto(array("xoffset" => ' . $ xOffset . ', "yoffset" => ' . $ yOffset . ')); ' ;
@@ -109,7 +154,7 @@ public function moveToElement($toElement, $curl_opts = array()) {
109154 return $ this ;
110155 }
111156
112- public function moveToElementWithOffset ($ toElement , $ xOffset , $ yOffset ) {
157+ public function moveToElementWithOffset ($ toElement , $ xOffset , $ yOffset, $ curl_opts = array () ) {
113158 $ this ->actions [] = '$this->session->moveto(array("element" => " ' . $ toElement ->getID () . '", "xoffset" => ' .$ xOffset .', "yoffset" => ' .$ yOffset .')); ' ;
114159 return $ this ;
115160 }
@@ -122,7 +167,10 @@ public function release($on_element = null, $curl_opts = array()) {
122167 return $ this ;
123168 }
124169
125- public function sendKeys ($ keysToSend ) {}
170+ public function sendKeys ($ keysToSend , $ curl_opts = array ()) {
171+ $ this ->actions [] = '$this->session->keys(array("value" => ' . unwind_array (str_split ($ keysToSend )) . '), ' . unwind_associated_array ($ curl_opts ) . '); ' ;
172+ return $ this ;
173+ }
126174
127175 public function sendKeysToElement ($ toElement , $ keysToSend ) {}
128176}
0 commit comments