WebDriverTimeouts.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 element if it is not immediately present.
  33. *
  34. * @param int $seconds Wait time in second.
  35. * @return WebDriverTimeouts The current instance.
  36. */
  37. public function implicitlyWait($seconds)
  38. {
  39. $this->executor->execute(
  40. DriverCommand::IMPLICITLY_WAIT,
  41. ['ms' => $seconds * 1000]
  42. );
  43. return $this;
  44. }
  45. /**
  46. * Set the amount of time to wait for an asynchronous script to finish execution before throwing an error.
  47. *
  48. * @param int $seconds Wait time in second.
  49. * @return WebDriverTimeouts The current instance.
  50. */
  51. public function setScriptTimeout($seconds)
  52. {
  53. $this->executor->execute(
  54. DriverCommand::SET_SCRIPT_TIMEOUT,
  55. ['ms' => $seconds * 1000]
  56. );
  57. return $this;
  58. }
  59. /**
  60. * Set the amount of time to wait for a page load to complete before throwing an error.
  61. *
  62. * @param int $seconds Wait time in second.
  63. * @return WebDriverTimeouts The current instance.
  64. */
  65. public function pageLoadTimeout($seconds)
  66. {
  67. $this->executor->execute(DriverCommand::SET_TIMEOUT, [
  68. 'type' => 'page load',
  69. 'ms' => $seconds * 1000,
  70. ]);
  71. return $this;
  72. }
  73. }