WebDriverAlert.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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;
  16. use Facebook\WebDriver\Remote\DriverCommand;
  17. use Facebook\WebDriver\Remote\ExecuteMethod;
  18. /**
  19. * An abstraction allowing the driver to manipulate the javascript alerts
  20. */
  21. class WebDriverAlert
  22. {
  23. /**
  24. * @var ExecuteMethod
  25. */
  26. protected $executor;
  27. public function __construct(ExecuteMethod $executor)
  28. {
  29. $this->executor = $executor;
  30. }
  31. /**
  32. * Accept alert
  33. *
  34. * @return WebDriverAlert The instance.
  35. */
  36. public function accept()
  37. {
  38. $this->executor->execute(DriverCommand::ACCEPT_ALERT);
  39. return $this;
  40. }
  41. /**
  42. * Dismiss alert
  43. *
  44. * @return WebDriverAlert The instance.
  45. */
  46. public function dismiss()
  47. {
  48. $this->executor->execute(DriverCommand::DISMISS_ALERT);
  49. return $this;
  50. }
  51. /**
  52. * Get alert text
  53. *
  54. * @return string
  55. */
  56. public function getText()
  57. {
  58. return $this->executor->execute(DriverCommand::GET_ALERT_TEXT);
  59. }
  60. /**
  61. * Send keystrokes to javascript prompt() dialog
  62. *
  63. * @param string $value
  64. * @return WebDriverAlert
  65. */
  66. public function sendKeys($value)
  67. {
  68. $this->executor->execute(
  69. DriverCommand::SET_ALERT_VALUE,
  70. ['text' => $value]
  71. );
  72. return $this;
  73. }
  74. }