RemoteKeyboard.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?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.
  15. namespace Facebook\WebDriver\Remote;
  16. use Facebook\WebDriver\WebDriverKeyboard;
  17. use Facebook\WebDriver\WebDriverKeys;
  18. /**
  19. * Execute keyboard commands for RemoteWebDriver.
  20. */
  21. class RemoteKeyboard implements WebDriverKeyboard
  22. {
  23. /**
  24. * @var RemoteExecuteMethod
  25. */
  26. private $executor;
  27. /**
  28. * @param RemoteExecuteMethod $executor
  29. */
  30. public function __construct(RemoteExecuteMethod $executor)
  31. {
  32. $this->executor = $executor;
  33. }
  34. /**
  35. * Send keys to active element
  36. * @param string|array $keys
  37. * @return $this
  38. */
  39. public function sendKeys($keys)
  40. {
  41. $this->executor->execute(DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT, [
  42. 'value' => WebDriverKeys::encode($keys),
  43. ]);
  44. return $this;
  45. }
  46. /**
  47. * Press a modifier key
  48. *
  49. * @see WebDriverKeys
  50. * @param string $key
  51. * @return $this
  52. */
  53. public function pressKey($key)
  54. {
  55. $this->executor->execute(DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT, [
  56. 'value' => [(string) $key],
  57. ]);
  58. return $this;
  59. }
  60. /**
  61. * Release a modifier key
  62. *
  63. * @see WebDriverKeys
  64. * @param string $key
  65. * @return $this
  66. */
  67. public function releaseKey($key)
  68. {
  69. $this->executor->execute(DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT, [
  70. 'value' => [(string) $key],
  71. ]);
  72. return $this;
  73. }
  74. }