WebDriverContainer.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. abstract class WebDriverContainer extends WebDriverBase {
  16. public function element($using, $value) {
  17. try {
  18. $results = $this->curl(
  19. 'POST',
  20. '/element',
  21. array(
  22. 'using' => $using,
  23. 'value' => $value));
  24. } catch (NoSuchElementWebDriverError $e) {
  25. throw new NoSuchElementWebDriverError(
  26. sprintf(
  27. 'Element not found with %s, %s',
  28. $using,
  29. $value) . "\n\n" . $e->getMessage(),
  30. $e->getResults());
  31. }
  32. return $this->webDriverElement($results['value']);
  33. }
  34. public function elements($using, $value) {
  35. $results = $this->curl(
  36. 'POST',
  37. '/elements',
  38. array(
  39. 'using' => $using,
  40. 'value' => $value
  41. ));
  42. return array_filter(array_map(
  43. array($this, 'webDriverElement'), $results['value']));
  44. }
  45. protected function webDriverElement($value) {
  46. return array_key_exists('ELEMENT', (array) $value) ?
  47. new WebDriverElement(
  48. $this->getElementPath($value['ELEMENT']), // url
  49. $value['ELEMENT']) : // id
  50. null;
  51. }
  52. abstract protected function getElementPath($element_id);
  53. }