11<?php
2+ // Copyright 2004-present Facebook. All Rights Reserved.
3+ //
4+ // Licensed under the Apache License, Version 2.0 (the "License");
5+ // you may not use this file except in compliance with the License.
6+ // You may obtain a copy of the License at
7+ //
8+ // http://www.apache.org/licenses/LICENSE-2.0
9+ //
10+ // Unless required by applicable law or agreed to in writing, software
11+ // distributed under the License is distributed on an "AS IS" BASIS,
12+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ // See the License for the specific language governing permissions and
14+ // limitations under the License.
215
3-
16+ /**
17+ * Execute keyboard commands for RemoteWebDriver.
18+ */
419class RemoteKeyboard implements WebDriverKeyboard {
520
621 private $ executor ;
@@ -18,7 +33,7 @@ public function __construct($executor) {
1833 * @return $this
1934 */
2035 public function sendKeys ($ keys ) {
21- $ this ->sendKeysToActiveElement (WebDriverKeys::encode ($ keys ));
36+ $ this ->sendKeysToActiveElement (WebDriverKeys::encode (func_get_args () ));
2237 return $ this ;
2338 }
2439
@@ -31,8 +46,7 @@ public function sendKeys($keys) {
3146 */
3247 public function press ($ key )
3348 {
34- $ this ->ensureModifier ($ key );
35- $ this ->sendKeysToActiveElement (WebDriverKeys::encode (array ($ key )));
49+ $ this ->sendKeysToActiveElement ($ this ->getModifierKey ($ key ));
3650 return $ this ;
3751 }
3852
@@ -45,8 +59,7 @@ public function press($key)
4559 */
4660 public function release ($ key )
4761 {
48- $ this ->ensureModifier ($ key );
49- $ this ->sendKeysToActiveElement (WebDriverKeys::encode (array ($ key )));
62+ $ this ->sendKeysToActiveElement ($ this ->getModifierKey ($ key ));
5063 return $ this ;
5164 }
5265
@@ -58,9 +71,10 @@ private function sendKeysToActiveElement($value)
5871 $ this ->executor ->execute ('sendKeysToActiveElement ' , $ params );
5972 }
6073
61- private function ensureModifier ($ key )
74+ private function getModifierKey ($ key )
6275 {
6376 if (!in_array ($ key , $ this ->modifiers ))
6477 throw new InvalidArgumentException ("$ key is not a modifier key, expected one of " .implode (', ' ,$ this ->modifiers ));
78+ return array (constant ('WebDriverKeys:: ' .strtoupper ($ key )));
6579 }
6680}
0 commit comments