WebDriverTimeouts.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. * Managing timeout behavior for WebDriver instances.
  20. */
  21. class WebDriverTimeouts
  22. {
  23. /**
  24. * @var ExecuteMethod
  25. */
  26. protected $executor;
  27. public function __construct(ExecuteMethod $executor)
  28. {
  29. $this->executor = $executor;
  30. }
  31. /**
  32. * Specify the amount of time the driver should wait when searching for an
  33. * element if it is not immediately present.
  34. *
  35. * @param int $seconds Wait time in second.
  36. * @return WebDriverTimeouts The current instance.
  37. */
  38. public function implicitlyWait($seconds)
  39. {
  40. $this->executor->execute(
  41. DriverCommand::IMPLICITLY_WAIT,
  42. ['ms' => $seconds * 1000]
  43. );
  44. return $this;
  45. }
  46. /**
  47. * Set the amount of time to wait for an asynchronous script to finish
  48. * execution before throwing an error.
  49. *
  50. * @param int $seconds Wait time in second.
  51. * @return WebDriverTimeouts The current instance.
  52. */
  53. public function setScriptTimeout($seconds)
  54. {
  55. $this->executor->execute(
  56. DriverCommand::SET_SCRIPT_TIMEOUT,
  57. ['ms' => $seconds * 1000]
  58. );
  59. return $this;
  60. }
  61. /**
  62. * Set the amount of time to wait for a page load to complete before throwing
  63. * an error.
  64. *
  65. * @param int $seconds Wait time in second.
  66. * @return WebDriverTimeouts The current instance.
  67. */
  68. public function pageLoadTimeout($seconds)
  69. {
  70. $this->executor->execute(DriverCommand::SET_TIMEOUT, [
  71. 'type' => 'page load',
  72. 'ms' => $seconds * 1000,
  73. ]);
  74. return $this;
  75. }
  76. }