WebDriver.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyright 2004-2017 Facebook. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. * @package WebDriver
  18. *
  19. * @author Justin Bishop <jubishop@gmail.com>
  20. * @author Anthon Pang <apang@softwaredevelopment.ca>
  21. */
  22. namespace WebDriver;
  23. /**
  24. * WebDriver class
  25. *
  26. * @package WebDriver
  27. *
  28. * @method status
  29. */
  30. class WebDriver extends AbstractWebDriver implements WebDriverInterface
  31. {
  32. /**
  33. * {@inheritdoc}
  34. */
  35. protected function methods()
  36. {
  37. return array(
  38. 'status' => 'GET',
  39. );
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function session($requiredCapabilities = Browser::FIREFOX, $desiredCapabilities = array())
  45. {
  46. // for backwards compatibility when the only required capability was browser name
  47. if (! is_array($requiredCapabilities)) {
  48. $desiredCapabilities[Capability::BROWSER_NAME] = $requiredCapabilities ?: Browser::FIREFOX;
  49. $requiredCapabilities = array();
  50. }
  51. // required
  52. $parameters = array(
  53. 'desiredCapabilities' => array_merge($desiredCapabilities, $requiredCapabilities)
  54. );
  55. // optional
  56. if (! empty($requiredCapabilities)) {
  57. $parameters['requiredCapabilities'] = $requiredCapabilities;
  58. }
  59. $result = $this->curl(
  60. 'POST',
  61. '/session',
  62. $parameters,
  63. array(CURLOPT_FOLLOWLOCATION => true)
  64. );
  65. return new Session($result['sessionUrl']);
  66. }
  67. /**
  68. * {@inheritdoc}
  69. */
  70. public function sessions()
  71. {
  72. $result = $this->curl('GET', '/sessions');
  73. $sessions = array();
  74. foreach ($result['value'] as $session) {
  75. $sessions[] = new Session($this->url . '/session/' . $session['id']);
  76. }
  77. return $sessions;
  78. }
  79. }