WebDriverNavigation.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 access the browser's history and to
  20. * navigate to a given URL.
  21. *
  22. * Note that they are all blocking functions until the page is loaded by
  23. * by default. It could be overridden by 'webdriver.load.strategy' in the
  24. * FirefoxProfile preferences.
  25. * https://code.google.com/p/selenium/wiki/DesiredCapabilities#settings
  26. */
  27. class WebDriverNavigation
  28. {
  29. protected $executor;
  30. public function __construct(ExecuteMethod $executor)
  31. {
  32. $this->executor = $executor;
  33. }
  34. /**
  35. * Move back a single entry in the browser's history, if possible.
  36. *
  37. * @return WebDriverNavigation The instance.
  38. */
  39. public function back()
  40. {
  41. $this->executor->execute(DriverCommand::GO_BACK);
  42. return $this;
  43. }
  44. /**
  45. * Move forward a single entry in the browser's history, if possible.
  46. *
  47. * @return WebDriverNavigation The instance.
  48. */
  49. public function forward()
  50. {
  51. $this->executor->execute(DriverCommand::GO_FORWARD);
  52. return $this;
  53. }
  54. /**
  55. * Refresh the current page.
  56. *
  57. * @return WebDriverNavigation The instance.
  58. */
  59. public function refresh()
  60. {
  61. $this->executor->execute(DriverCommand::REFRESH);
  62. return $this;
  63. }
  64. /**
  65. * Navigate to the given URL.
  66. *
  67. * @param string $url
  68. * @return WebDriverNavigation The instance.
  69. */
  70. public function to($url)
  71. {
  72. $params = ['url' => (string) $url];
  73. $this->executor->execute(DriverCommand::GET, $params);
  74. return $this;
  75. }
  76. }