Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -0,0 +1,2 @@
coverage_clover: ./logs/coverage-clover.xml
json_path: ./logs/coveralls-upload.json

83
vendor/facebook/webdriver/.php_cs.dist vendored Normal file
View File

@@ -0,0 +1,83 @@
<?php
$finder = PhpCsFixer\Finder::create()
->in([__DIR__ . '/lib', __DIR__ . '/tests']);
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => true,
'blank_line_before_return' => true,
'cast_spaces' => true,
'concat_space' => ['spacing' => 'one'],
'function_typehint_space' => true,
'general_phpdoc_annotation_remove' => ['author'],
'linebreak_after_opening_tag' => true,
'lowercase_cast' => true,
'mb_str_functions' => true,
'method_separation' => true,
'native_function_casing' => true,
'new_with_braces' => true,
'no_alias_functions' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_consecutive_blank_lines' => [
'use',
'break',
'continue',
'extra',
'return',
'throw',
'useTrait',
'curly_brace_block',
'parenthesis_brace_block',
'square_brace_block',
],
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_unreachable_default_argument_value' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_in_blank_line' => true,
'object_operator_without_whitespace' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_construct' => true,
'php_unit_dedicate_assert' => true,
'php_unit_expectation' => true,
'php_unit_mock' => true,
'php_unit_no_expectation_annotation' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_indent' => true,
'phpdoc_no_access' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'psr4' => true,
'self_accessor' => true,
'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'visibility_required' => true,
'whitespace_after_comma_in_array' => true,
'yoda_style' => false,
])
->setRiskyAllowed(true)
->setFinder($finder);

89
vendor/facebook/webdriver/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,89 @@
# Changelog
This project versioning adheres to [Semantic Versioning](http://semver.org/).
## Unreleased
---
## 1.6.0 - 2018-05-16
### Added
- Connection and request timeouts could be specified also when creating RemoteWebDriver from existing session ID.
- Update PHPDoc for functions that return static instances of a class.
### Changed
- Disable sending 'Expect: 100-Continue' header with POST requests, as they may more easily fail when sending via eg. squid proxy.
## 1.5.0 - 2017-11-15
### Changed
- Drop PHP 5.5 support, the minimal required version of PHP is now PHP 5.6.
- Allow installation of Symfony 4 components.
### Added
- Add a `visibilityOfAnyElementsLocated()` method to `WebDriverExpectedCondition`.
## 1.4.1 - 2017-04-28
### Fixed
- Do not throw notice `Constant CURLOPT_CONNECTTIMEOUT_MS already defined`.
## 1.4.0 - 2017-03-22
### Changed
- Cookies should now be set using `Cookie` value object instead of an array when passed to to `addCookie()` method of `WebDriverOptions`.
- Cookies retrieved using `getCookieNamed()` and `getCookies()` methods of `WebDriverOptions` are now encapsulated in `Cookie` object instead of an plain array. The object implements `ArrayAccess` interface to provide backward compatibility.
- `ext-zip` is now specified as required dependency in composer.json (but the extension was already required by the code, though).
- Deprecate `WebDriverCapabilities::isJavascriptEnabled()` method.
- Deprecate `textToBePresentInElementValue` expected condition in favor of `elementValueContains`.
### Fixed
- Do not throw fatal error when `null` is passed to `sendKeys()`.
## 1.3.0 - 2017-01-13
### Added
- Added `getCapabilities()` method of `RemoteWebDriver`, to retrieve actual capabilities acknowledged by the remote driver on startup.
- Added option to pass required capabilities when creating `RemoteWebDriver`. (So far only desired capabilities were supported.)
- Added new expected conditions:
- `urlIs` - current URL exactly equals given value
- `urlContains` - current URL contains given text
- `urlMatches` - current URL matches regular expression
- `titleMatches` - current page title matches regular expression
- `elementTextIs` - text in element exactly equals given text
- `elementTextContains` (as an alias for `textToBePresentInElement`) - text in element contains given text
- `elementTextMatches` - text in element matches regular expression
- `numberOfWindowsToBe` - number of opened windows equals given number
- Possibility to select option of `<select>` by its partial text (using `selectByVisiblePartialText()`).
- `XPathEscaper` helper class to quote XPaths containing both single and double quotes.
- `WebDriverSelectInterface`, to allow implementation of custom select-like components, eg. those not built around and actual select tag.
### Changed
- `Symfony\Process` is used to start local WebDriver processes (when browsers are run directly, without Selenium server) to workaround some PHP bugs and improve portability.
- Clarified meaning of selenium server URL variable in methods of `RemoteWebDriver` class.
- Deprecated `setSessionID()` and `setCommandExecutor()` methods of `RemoteWebDriver` class; these values should be immutable and thus passed only via constructor.
- Deprecated `WebDriverExpectedCondition::textToBePresentInElement()` in favor of `elementTextContains()`.
- Throw an exception when attempting to deselect options of non-multiselect (it already didn't have any effect, but was silently ignored).
- Optimize performance of `(de)selectByIndex()` and `getAllSelectedOptions()` methods of `WebDriverSelect` when used with non-multiple select element.
### Fixed
- XPath escaping in `select*()` and `deselect*()` methods of `WebDriverSelect`.
## 1.2.0 - 2016-10-14
- Added initial support of remote Microsoft Edge browser (but starting local EdgeDriver is still not supported).
- Utilize late static binding to make eg. `WebDriverBy` and `DesiredCapabilities` classes easily extensible.
- PHP version at least 5.5 is required.
- Fixed incompatibility with Appium, caused by redundant params present in requests to Selenium server.
## 1.1.3 - 2016-08-10
- Fixed FirefoxProfile to support installation of extensions with custom namespace prefix in their manifest file.
- Comply codestyle with [PSR-2](http://www.php-fig.org/psr/psr-2/).
## 1.1.2 - 2016-06-04
- Added ext-curl to composer.json.
- Added CHANGELOG.md.
- Added CONTRIBUTING.md with information and rules for contributors.
## 1.1.1 - 2015-12-31
- Fixed strict standards error in `ChromeDriver`.
- Added unit tests for `WebDriverCommand` and `DesiredCapabilities`.
- Fixed retrieving temporary path name in `FirefoxDriver` when `open_basedir` restriction is in effect.
## 1.1.0 - 2015-12-08
- FirefoxProfile improved - added possibility to set RDF file and to add datas for extensions.
- Fixed setting 0 second timeout of `WebDriverWait`.

View File

@@ -0,0 +1,3 @@
# Code of Conduct
Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please [read the full text](https://code.facebook.com/codeofconduct) so that you can understand what actions will and will not be tolerated.

View File

@@ -0,0 +1,59 @@
# Contributing to php-webdriver
We love to have your help to make php-webdriver better!
Feel free to open an [issue](https://github.com/facebook/php-webdriver/issues) if you run into any problem, or
send a pull request (see bellow) with your contribution.
## Code of Conduct
The code of conduct is described in [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md)
## Workflow when contributing a patch
1. Fork the project on GitHub
2. Implement your code changes into separate branch
3. Make sure all PHPUnit tests passes and code-style matches PSR-2 (see below). We also have Travis CI build which will automatically run tests on your pull request.
4. When implementing notable change, fix or a new feature, add record to Unreleased section of [CHANGELOG.md](CHANGELOG.md)
5. Submit your [pull request](https://github.com/facebook/php-webdriver/pulls) against community branch
Note before any pull request can be accepted, a [Contributors Licensing Agreement](https://developers.facebook.com/opensource/cla) must be signed.
When you are going to contribute, please keep in mind that this webdriver client aims to be as close as possible to other languages Java/Ruby/Python/C#.
FYI, here is the overview of [the official Java API](http://seleniumhq.github.io/selenium/docs/api/java/)
### Run unit tests
There are two test-suites: one with unit tests only, second with functional tests, which require running selenium server.
To execute all tests simply run:
./vendor/bin/phpunit
If you want to execute just the unit tests, run:
./vendor/bin/phpunit --testsuite unit
For the functional tests you must first [download](http://selenium-release.storage.googleapis.com/index.html) and start
the selenium standalone server, start the local PHP server which will serve the test pages and then run the `functional`
test suite:
java -jar selenium-server-standalone-2.53.1.jar -log selenium.log &
php -S localhost:8000 -t tests/functional/web/ &
./vendor/bin/phpunit --testsuite functional
The functional tests will be started in HtmlUnit headless browser by default. If you want to run them in eg. Firefox,
simply set the `BROWSER` environment variable:
...
export BROWSER_NAME="firefox"
./vendor/bin/phpunit --testsuite functional
### Check coding style
Your code-style should comply with [PSR-2](http://www.php-fig.org/psr/psr-2/). To make sure your code matches this requirement run:
composer codestyle:check
To auto-fix the codestyle simply run:
composer codestyle:fix

View File

@@ -0,0 +1,21 @@
### What are you trying to achieve? (Expected behavior)
<!-- Please fill -->
### What do you get instead? (Actual behavior)
<!-- Please fill -->
### How could the issue be reproduced? (Steps to reproduce)
<!-- Please fill everything relevant - the exact code you use, how you initialize the WebDriver, HTML snippet or URL of the page where you encounter the issue etc. -->
```php
// You can insert your PHP code here (or remove this block if it is not relevant for the issue).
```
### Details
<!-- Please fill relevant following versions: -->
* Php-webdriver version:
* PHP version:
* Selenium server version:
* Operating system:
* Browser used + version:

201
vendor/facebook/webdriver/LICENCE.md vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2004-present Facebook
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

122
vendor/facebook/webdriver/README.md vendored Normal file
View File

@@ -0,0 +1,122 @@
# php-webdriver Selenium WebDriver bindings for PHP
[![Latest Stable Version](https://img.shields.io/packagist/v/facebook/webdriver.svg?style=flat-square)](https://packagist.org/packages/facebook/webdriver)
[![Travis Build](https://img.shields.io/travis/facebook/php-webdriver/community.svg?style=flat-square)](https://travis-ci.org/facebook/php-webdriver)
[![Sauce Test Status](https://saucelabs.com/buildstatus/php-webdriver)](https://saucelabs.com/u/php-webdriver)
[![Total Downloads](https://img.shields.io/packagist/dt/facebook/webdriver.svg?style=flat-square)](https://packagist.org/packages/facebook/webdriver)
[![License](https://img.shields.io/packagist/l/facebook/webdriver.svg?style=flat-square)](https://packagist.org/packages/facebook/webdriver)
## Description
Php-webdriver library is PHP language binding for Selenium WebDriver, which allows you to control web browsers from PHP.
This library is compatible with Selenium server version 2.x and 3.x.
It implements the [JsonWireProtocol](https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol), which is currently supported
by the Selenium server and will also implement the [W3C WebDriver](https://w3c.github.io/webdriver/webdriver-spec.html) specification in the future.
The concepts of this library are very similar to the "official" Java, .NET, Python and Ruby bindings from the
[Selenium project](https://github.com/SeleniumHQ/selenium/).
**As of 2013, this PHP client has been rewritten from scratch.**
Using the old version? Check out [Adam Goucher's fork](https://github.com/Element-34/php-webdriver) of it.
Looking for API documentation of php-webdriver? See [https://facebook.github.io/php-webdriver/](https://facebook.github.io/php-webdriver/latest/)
Any complaints, questions, or ideas? Post them in the user group https://www.facebook.com/groups/phpwebdriver/.
## Installation
Installation is possible using [Composer](https://getcomposer.org/).
If you don't already use Composer, you can download the `composer.phar` binary:
curl -sS https://getcomposer.org/installer | php
Then install the library:
php composer.phar require facebook/webdriver
## Getting started
### Start Server
The required server is the `selenium-server-standalone-#.jar` file provided here: http://selenium-release.storage.googleapis.com/index.html
Download and run the server by replacing # with the current server version. Keep in mind **you must have Java 8+ installed to run this command**.
java -jar selenium-server-standalone-#.jar
**NOTE:** If using Firefox, see alternate command below.
### Create a Browser Session
When creating a browser session, be sure to pass the url of your running server.
```php
// This would be the url of the host running the server-standalone.jar
$host = 'http://localhost:4444/wd/hub'; // this is the default
```
##### Launch Chrome
Make sure to have latest Chrome and [Chromedriver](https://sites.google.com/a/chromium.org/chromedriver/downloads) versions installed.
```php
$driver = RemoteWebDriver::create($host, DesiredCapabilities::chrome());
```
##### Launch Firefox
Make sure to have latest Firefox and [Geckodriver](https://github.com/mozilla/geckodriver/releases) installed.
Because Firefox (and Geckodriver) only support the new W3C WebDriver protocol (which is yet to be implemented by php-webdriver - see [issue #469](https://github.com/facebook/php-webdriver/issues/469)),
the protocols must be translated by Selenium Server - this feature is *partially* available in Selenium Server versions 3.5.0-3.8.1 and you can enable it like this:
java -jar selenium-server-standalone-3.8.1.jar -enablePassThrough false
Now you can start Firefox from your code:
```php
$driver = RemoteWebDriver::create($host, DesiredCapabilities::firefox());
```
### Customize Desired Capabilities
```php
$desired_capabilities = DesiredCapabilities::firefox();
$desired_capabilities->setCapability('acceptSslCerts', false);
$driver = RemoteWebDriver::create($host, $desired_capabilities);
```
* See https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities for more details.
**NOTE:** Above snippets are not intended to be a working example by simply copy-pasting. See [example.php](example.php) for working example.
## Changelog
For latest changes see [CHANGELOG.md](CHANGELOG.md) file.
## More information
Some how-tos are provided right here in [our GitHub wiki](https://github.com/facebook/php-webdriver/wiki).
You may also want to check out the Selenium [docs](http://docs.seleniumhq.org/docs/) and [wiki](https://github.com/SeleniumHQ/selenium/wiki).
## Testing framework integration
To take advantage of automatized testing you may want to integrate php-webdriver to your testing framework.
There are some projects already providing this:
- [Steward](https://github.com/lmc-eu/steward) integrates php-webdriver directly to [PHPUnit](https://phpunit.de/), and provides parallelization
- [Codeception](http://codeception.com) testing framework provides BDD-layer on top of php-webdriver in its [WebDriver module](http://codeception.com/docs/modules/WebDriver)
- You can also check out this [blogpost](http://codeception.com/11-12-2013/working-with-phpunit-and-selenium-webdriver.html) + [demo project](https://github.com/DavertMik/php-webdriver-demo), describing simple [PHPUnit](https://phpunit.de/) integration
## Support
We have a great community willing to help you!
- **Via our Facebook Group** - If you have questions or are an active contributor consider joining our [facebook group](https://www.facebook.com/groups/phpwebdriver/) and contribute to communal discussion and support
- **Via StackOverflow** - You can also [ask a question](https://stackoverflow.com/questions/ask?tags=php+selenium-webdriver) or find many already answered question on StackOverflow
- **Via GitHub** - Another option if you have a question (or bug report) is to [submit it here](https://github.com/facebook/php-webdriver/issues/new) as an new issue
## Contributing
We love to have your help to make php-webdriver better. See [CONTRIBUTING.md](CONTRIBUTING.md) for more information about contributing and developing php-webdriver.

65
vendor/facebook/webdriver/composer.json vendored Normal file
View File

@@ -0,0 +1,65 @@
{
"name": "facebook/webdriver",
"description": "A PHP client for Selenium WebDriver",
"keywords": ["webdriver", "selenium", "php", "facebook"],
"homepage": "https://github.com/facebook/php-webdriver",
"type": "library",
"license": "Apache-2.0",
"support": {
"issues": "https://github.com/facebook/php-webdriver/issues",
"forum": "https://www.facebook.com/groups/phpwebdriver/",
"source": "https://github.com/facebook/php-webdriver"
},
"minimum-stability": "beta",
"require": {
"php": "^5.6 || ~7.0",
"symfony/process": "^2.8 || ^3.1 || ^4.0",
"ext-curl": "*",
"ext-zip": "*",
"ext-mbstring": "*",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"sebastian/environment": "^1.3.4 || ^2.0 || ^3.0",
"friendsofphp/php-cs-fixer": "^2.0",
"squizlabs/php_codesniffer": "^2.6",
"php-mock/php-mock-phpunit": "^1.1",
"php-coveralls/php-coveralls": "^2.0",
"symfony/var-dumper": "^3.3 || ^4.0",
"jakub-onderka/php-parallel-lint": "^0.9.2"
},
"suggest": {
"ext-SimpleXML": "For Firefox profile creation"
},
"autoload": {
"psr-4": {
"Facebook\\WebDriver\\": "lib/"
}
},
"autoload-dev": {
"psr-4": {
"Facebook\\WebDriver\\": ["tests/unit", "tests/functional"]
},
"classmap": ["tests/functional/"]
},
"scripts": {
"codestyle:check": [
"vendor/bin/php-cs-fixer fix --diff --diff-format=udiff --dry-run -vvv --ansi",
"vendor/bin/phpcs --standard=PSR2 ./lib/ ./tests/"
],
"codestyle:fix": [
"vendor/bin/php-cs-fixer fix --diff --diff-format=udiff -vvv || exit 0",
"vendor/bin/phpcbf --standard=PSR2 ./lib/ ./tests/"
],
"analyze": [
"vendor/bin/parallel-lint -j 10 ./lib ./tests",
"vendor/bin/phpstan.phar analyze ./lib ./tests --level 2 -c phpstan.neon --ansi"
]
},
"extra": {
"branch-alias": {
"dev-community": "1.5-dev"
}
}
}

View File

@@ -0,0 +1,101 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Chrome;
use Facebook\WebDriver\Exception\WebDriverException;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\DriverCommand;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\Service\DriverCommandExecutor;
use Facebook\WebDriver\Remote\WebDriverCommand;
class ChromeDriver extends RemoteWebDriver
{
/**
* @return static
*/
public static function start(DesiredCapabilities $desired_capabilities = null, ChromeDriverService $service = null)
{
if ($desired_capabilities === null) {
$desired_capabilities = DesiredCapabilities::chrome();
}
if ($service === null) {
$service = ChromeDriverService::createDefaultService();
}
$executor = new DriverCommandExecutor($service);
$driver = new static($executor, null, $desired_capabilities);
$driver->startSession($desired_capabilities);
return $driver;
}
public function startSession(DesiredCapabilities $desired_capabilities)
{
$command = new WebDriverCommand(
null,
DriverCommand::NEW_SESSION,
[
'desiredCapabilities' => $desired_capabilities->toArray(),
]
);
$response = $this->executor->execute($command);
$this->sessionID = $response->getSessionID();
}
/**
* Always throws an exception. Use ChromeDriver::start() instead.
*
* @param string $selenium_server_url
* @param DesiredCapabilities|array $desired_capabilities
* @param int|null $connection_timeout_in_ms
* @param int|null $request_timeout_in_ms
* @param string|null $http_proxy
* @param int|null $http_proxy_port
* @param DesiredCapabilities $required_capabilities
* @throws WebDriverException
* @return RemoteWebDriver
*/
public static function create(
$selenium_server_url = 'http://localhost:4444/wd/hub',
$desired_capabilities = null,
$connection_timeout_in_ms = null,
$request_timeout_in_ms = null,
$http_proxy = null,
$http_proxy_port = null,
DesiredCapabilities $required_capabilities = null
) {
throw new WebDriverException('Please use ChromeDriver::start() instead.');
}
/**
* Always throws an exception. Use ChromeDriver::start() instead.
*
* @param string $session_id The existing session id
* @param string $selenium_server_url The url of the remote Selenium WebDriver server
* @param int|null $connection_timeout_in_ms Set timeout for the connect phase to remote Selenium WebDriver server
* @param int|null $request_timeout_in_ms Set the maximum time of a request to remote Selenium WebDriver server
* @throws WebDriverException
* @return RemoteWebDriver|void
*/
public static function createBySessionID(
$session_id,
$selenium_server_url = 'http://localhost:4444/wd/hub',
$connection_timeout_in_ms = null,
$request_timeout_in_ms = null
) {
throw new WebDriverException('Please use ChromeDriver::start() instead.');
}
}

View File

@@ -0,0 +1,37 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Chrome;
use Facebook\WebDriver\Remote\Service\DriverService;
class ChromeDriverService extends DriverService
{
// The environment variable storing the path to the chrome driver executable.
const CHROME_DRIVER_EXE_PROPERTY = 'webdriver.chrome.driver';
/**
* @return static
*/
public static function createDefaultService()
{
$exe = getenv(self::CHROME_DRIVER_EXE_PROPERTY);
$port = 9515; // TODO: Get another port if the default port is used.
$args = ["--port=$port"];
$service = new static($exe, $port, $args);
return $service;
}
}

View File

@@ -0,0 +1,175 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Chrome;
use Facebook\WebDriver\Remote\DesiredCapabilities;
/**
* The class manages the capabilities in ChromeDriver.
*
* @see https://sites.google.com/a/chromium.org/chromedriver/capabilities
*/
class ChromeOptions
{
/**
* The key of chrome options in desired capabilities.
*/
const CAPABILITY = 'chromeOptions';
/**
* @var array
*/
private $arguments = [];
/**
* @var string
*/
private $binary = '';
/**
* @var array
*/
private $extensions = [];
/**
* @var array
*/
private $experimentalOptions = [];
/**
* Sets the path of the Chrome executable. The path should be either absolute
* or relative to the location running ChromeDriver server.
*
* @param string $path
* @return ChromeOptions
*/
public function setBinary($path)
{
$this->binary = $path;
return $this;
}
/**
* @param array $arguments
* @return ChromeOptions
*/
public function addArguments(array $arguments)
{
$this->arguments = array_merge($this->arguments, $arguments);
return $this;
}
/**
* Add a Chrome extension to install on browser startup. Each path should be
* a packed Chrome extension.
*
* @param array $paths
* @return ChromeOptions
*/
public function addExtensions(array $paths)
{
foreach ($paths as $path) {
$this->addExtension($path);
}
return $this;
}
/**
* @param array $encoded_extensions An array of base64 encoded of the extensions.
* @return ChromeOptions
*/
public function addEncodedExtensions(array $encoded_extensions)
{
foreach ($encoded_extensions as $encoded_extension) {
$this->addEncodedExtension($encoded_extension);
}
return $this;
}
/**
* Sets an experimental option which has not exposed officially.
*
* @param string $name
* @param mixed $value
* @return ChromeOptions
*/
public function setExperimentalOption($name, $value)
{
$this->experimentalOptions[$name] = $value;
return $this;
}
/**
* @return DesiredCapabilities The DesiredCapabilities for Chrome with this options.
*/
public function toCapabilities()
{
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(self::CAPABILITY, $this);
return $capabilities;
}
/**
* @return array
*/
public function toArray()
{
$options = $this->experimentalOptions;
// The selenium server expects a 'dictionary' instead of a 'list' when
// reading the chrome option. However, an empty array in PHP will be
// converted to a 'list' instead of a 'dictionary'. To fix it, we always
// set the 'binary' to avoid returning an empty array.
$options['binary'] = $this->binary;
if ($this->arguments) {
$options['args'] = $this->arguments;
}
if ($this->extensions) {
$options['extensions'] = $this->extensions;
}
return $options;
}
/**
* Add a Chrome extension to install on browser startup. Each path should be a
* packed Chrome extension.
*
* @param string $path
* @return ChromeOptions
*/
private function addExtension($path)
{
$this->addEncodedExtension(base64_encode(file_get_contents($path)));
return $this;
}
/**
* @param string $encoded_extension Base64 encoded of the extension.
* @return ChromeOptions
*/
private function addEncodedExtension($encoded_extension)
{
$this->extensions[] = $encoded_extension;
return $this;
}
}

241
vendor/facebook/webdriver/lib/Cookie.php vendored Normal file
View File

@@ -0,0 +1,241 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver;
use InvalidArgumentException;
/**
* Set values of an cookie.
*
* Implements ArrayAccess for backwards compatibility.
*
* @see https://w3c.github.io/webdriver/webdriver-spec.html#cookies
*/
class Cookie implements \ArrayAccess
{
/** @var array */
protected $cookie = [
'name' => null,
'value' => null,
'path' => null,
'domain' => null,
'expiry' => null,
'secure' => null,
'httpOnly' => null,
];
/**
* @param string $name The name of the cookie; may not be null or an empty string.
* @param string $value The cookie value; may not be null.
*/
public function __construct($name, $value)
{
$this->validateCookieName($name);
$this->validateCookieValue($value);
$this->cookie['name'] = $name;
$this->cookie['value'] = $value;
}
/**
* @param array $cookieArray
* @return Cookie
*/
public static function createFromArray(array $cookieArray)
{
$cookie = new self($cookieArray['name'], $cookieArray['value']);
if (isset($cookieArray['path'])) {
$cookie->setPath($cookieArray['path']);
}
if (isset($cookieArray['domain'])) {
$cookie->setDomain($cookieArray['domain']);
}
if (isset($cookieArray['expiry'])) {
$cookie->setExpiry($cookieArray['expiry']);
}
if (isset($cookieArray['secure'])) {
$cookie->setSecure($cookieArray['secure']);
}
if (isset($cookieArray['httpOnly'])) {
$cookie->setHttpOnly($cookieArray['httpOnly']);
}
return $cookie;
}
/**
* @return string
*/
public function getName()
{
return $this->cookie['name'];
}
/**
* @return string
*/
public function getValue()
{
return $this->cookie['value'];
}
/**
* The path the cookie is visible to. Defaults to "/" if omitted.
*
* @param string $path
*/
public function setPath($path)
{
$this->cookie['path'] = $path;
}
/**
* @return string|null
*/
public function getPath()
{
return $this->cookie['path'];
}
/**
* The domain the cookie is visible to. Defaults to the current browsing context's document's URL domain if omitted.
*
* @param string $domain
*/
public function setDomain($domain)
{
if (mb_strpos($domain, ':') !== false) {
throw new InvalidArgumentException(sprintf('Cookie domain "%s" should not contain a port', $domain));
}
$this->cookie['domain'] = $domain;
}
/**
* @return string|null
*/
public function getDomain()
{
return $this->cookie['domain'];
}
/**
* The cookie's expiration date, specified in seconds since Unix Epoch.
*
* @param int $expiry
*/
public function setExpiry($expiry)
{
$this->cookie['expiry'] = (int) $expiry;
}
/**
* @return int|null
*/
public function getExpiry()
{
return $this->cookie['expiry'];
}
/**
* Whether this cookie requires a secure connection (https). Defaults to false if omitted.
*
* @param bool $secure
*/
public function setSecure($secure)
{
$this->cookie['secure'] = $secure;
}
/**
* @return bool|null
*/
public function isSecure()
{
return $this->cookie['secure'];
}
/**
* Whether the cookie is an HTTP only cookie. Defaults to false if omitted.
*
* @param bool $httpOnly
*/
public function setHttpOnly($httpOnly)
{
$this->cookie['httpOnly'] = $httpOnly;
}
/**
* @return bool|null
*/
public function isHttpOnly()
{
return $this->cookie['httpOnly'];
}
/**
* @return array
*/
public function toArray()
{
return $this->cookie;
}
public function offsetExists($offset)
{
return isset($this->cookie[$offset]);
}
public function offsetGet($offset)
{
return $this->cookie[$offset];
}
public function offsetSet($offset, $value)
{
$this->cookie[$offset] = $value;
}
public function offsetUnset($offset)
{
unset($this->cookie[$offset]);
}
/**
* @param string $name
*/
protected function validateCookieName($name)
{
if ($name === null || $name === '') {
throw new InvalidArgumentException('Cookie name should be non-empty');
}
if (mb_strpos($name, ';') !== false) {
throw new InvalidArgumentException('Cookie name should not contain a ";"');
}
}
/**
* @param string $value
*/
protected function validateCookieValue($value)
{
if ($value === null) {
throw new InvalidArgumentException('Cookie value is required when setting a cookie');
}
}
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class ElementNotSelectableException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class ElementNotVisibleException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class ExpectedException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class IMEEngineActivationFailedException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class IMENotAvailableException extends WebDriverException
{
}

View File

@@ -0,0 +1,7 @@
<?php
namespace Facebook\WebDriver\Exception;
class IndexOutOfBoundsException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class InvalidCookieDomainException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class InvalidCoordinatesException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class InvalidElementStateException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class InvalidSelectorException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class MoveTargetOutOfBoundsException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class NoAlertOpenException extends WebDriverException
{
}

View File

@@ -0,0 +1,7 @@
<?php
namespace Facebook\WebDriver\Exception;
class NoCollectionException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class NoScriptResultException extends WebDriverException
{
}

View File

@@ -0,0 +1,7 @@
<?php
namespace Facebook\WebDriver\Exception;
class NoStringException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class NoStringLengthException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class NoStringWrapperException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class NoSuchCollectionException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class NoSuchDocumentException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class NoSuchDriverException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class NoSuchElementException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class NoSuchFrameException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class NoSuchWindowException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class NullPointerException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class ScriptTimeoutException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class SessionNotCreatedException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class StaleElementReferenceException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class TimeOutException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class UnableToSetCookieException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class UnexpectedAlertOpenException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class UnexpectedJavascriptException extends WebDriverException
{
}

View File

@@ -0,0 +1,36 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class UnexpectedTagNameException extends WebDriverException
{
/**
* @param string $expected_tag_name
* @param string $actual_tag_name
*/
public function __construct(
$expected_tag_name,
$actual_tag_name
) {
parent::__construct(
sprintf(
'Element should have been "%s" but was "%s"',
$expected_tag_name,
$actual_tag_name
)
);
}
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class UnknownCommandException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class UnknownServerException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class UnrecognizedExceptionException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class UnsupportedOperationException extends WebDriverException
{
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class WebDriverCurlException extends WebDriverException
{
}

View File

@@ -0,0 +1,161 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
use Exception;
class WebDriverException extends Exception
{
private $results;
/**
* @param string $message
* @param mixed $results
*/
public function __construct($message, $results = null)
{
parent::__construct($message);
$this->results = $results;
}
/**
* @return mixed
*/
public function getResults()
{
return $this->results;
}
/**
* Throw WebDriverExceptions based on WebDriver status code.
*
* @param int $status_code
* @param string $message
* @param mixed $results
*
* @throws ElementNotSelectableException
* @throws ElementNotVisibleException
* @throws ExpectedException
* @throws IMEEngineActivationFailedException
* @throws IMENotAvailableException
* @throws IndexOutOfBoundsException
* @throws InvalidCookieDomainException
* @throws InvalidCoordinatesException
* @throws InvalidElementStateException
* @throws InvalidSelectorException
* @throws MoveTargetOutOfBoundsException
* @throws NoAlertOpenException
* @throws NoCollectionException
* @throws NoScriptResultException
* @throws NoStringException
* @throws NoStringLengthException
* @throws NoStringWrapperException
* @throws NoSuchCollectionException
* @throws NoSuchDocumentException
* @throws NoSuchDriverException
* @throws NoSuchElementException
* @throws NoSuchFrameException
* @throws NoSuchWindowException
* @throws NullPointerException
* @throws ScriptTimeoutException
* @throws SessionNotCreatedException
* @throws StaleElementReferenceException
* @throws TimeOutException
* @throws UnableToSetCookieException
* @throws UnexpectedAlertOpenException
* @throws UnexpectedJavascriptException
* @throws UnknownCommandException
* @throws UnknownServerException
* @throws UnrecognizedExceptionException
* @throws WebDriverCurlException
* @throws XPathLookupException
*/
public static function throwException($status_code, $message, $results)
{
switch ($status_code) {
case 1:
throw new IndexOutOfBoundsException($message, $results);
case 2:
throw new NoCollectionException($message, $results);
case 3:
throw new NoStringException($message, $results);
case 4:
throw new NoStringLengthException($message, $results);
case 5:
throw new NoStringWrapperException($message, $results);
case 6:
throw new NoSuchDriverException($message, $results);
case 7:
throw new NoSuchElementException($message, $results);
case 8:
throw new NoSuchFrameException($message, $results);
case 9:
throw new UnknownCommandException($message, $results);
case 10:
throw new StaleElementReferenceException($message, $results);
case 11:
throw new ElementNotVisibleException($message, $results);
case 12:
throw new InvalidElementStateException($message, $results);
case 13:
throw new UnknownServerException($message, $results);
case 14:
throw new ExpectedException($message, $results);
case 15:
throw new ElementNotSelectableException($message, $results);
case 16:
throw new NoSuchDocumentException($message, $results);
case 17:
throw new UnexpectedJavascriptException($message, $results);
case 18:
throw new NoScriptResultException($message, $results);
case 19:
throw new XPathLookupException($message, $results);
case 20:
throw new NoSuchCollectionException($message, $results);
case 21:
throw new TimeOutException($message, $results);
case 22:
throw new NullPointerException($message, $results);
case 23:
throw new NoSuchWindowException($message, $results);
case 24:
throw new InvalidCookieDomainException($message, $results);
case 25:
throw new UnableToSetCookieException($message, $results);
case 26:
throw new UnexpectedAlertOpenException($message, $results);
case 27:
throw new NoAlertOpenException($message, $results);
case 28:
throw new ScriptTimeoutException($message, $results);
case 29:
throw new InvalidCoordinatesException($message, $results);
case 30:
throw new IMENotAvailableException($message, $results);
case 31:
throw new IMEEngineActivationFailedException($message, $results);
case 32:
throw new InvalidSelectorException($message, $results);
case 33:
throw new SessionNotCreatedException($message, $results);
case 34:
throw new MoveTargetOutOfBoundsException($message, $results);
default:
throw new UnrecognizedExceptionException($message, $results);
}
}
}

View File

@@ -0,0 +1,20 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Exception;
class XPathLookupException extends WebDriverException
{
}

View File

@@ -0,0 +1,28 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Firefox;
/**
* @codeCoverageIgnore
*/
class FirefoxDriver
{
const PROFILE = 'firefox_profile';
private function __construct()
{
}
}

View File

@@ -0,0 +1,36 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Firefox;
/**
* Constants of common Firefox profile preferences (about:config values).
* @see http://kb.mozillazine.org/Firefox_:_FAQs_:_About:config_Entries
*
* @codeCoverageIgnore
*/
class FirefoxPreferences
{
/** @var string Port WebDriver uses to communicate with Firefox instance */
const WEBDRIVER_FIREFOX_PORT = 'webdriver_firefox_port';
/** @var string Should the reader view (FF 38+) be enabled? */
const READER_PARSE_ON_LOAD_ENABLED = 'reader.parse-on-load.enabled';
/** @var string Browser homepage */
const BROWSER_STARTUP_HOMEPAGE = 'browser.startup.homepage';
private function __construct()
{
}
}

View File

@@ -0,0 +1,302 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Firefox;
use Facebook\WebDriver\Exception\WebDriverException;
use FilesystemIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use ZipArchive;
class FirefoxProfile
{
/**
* @var array
*/
private $preferences = [];
/**
* @var array
*/
private $extensions = [];
/**
* @var array
*/
private $extensions_datas = [];
/**
* @var string
*/
private $rdf_file;
/**
* @param string $extension The path to the xpi extension.
* @return FirefoxProfile
*/
public function addExtension($extension)
{
$this->extensions[] = $extension;
return $this;
}
/**
* @param string $extension_datas The path to the folder containing the datas to add to the extension
* @return FirefoxProfile
*/
public function addExtensionDatas($extension_datas)
{
if (!is_dir($extension_datas)) {
return null;
}
$this->extensions_datas[basename($extension_datas)] = $extension_datas;
return $this;
}
/**
* @param string $rdf_file The path to the rdf file
* @return FirefoxProfile
*/
public function setRdfFile($rdf_file)
{
if (!is_file($rdf_file)) {
return null;
}
$this->rdf_file = $rdf_file;
return $this;
}
/**
* @param string $key
* @param string|bool|int $value
* @throws WebDriverException
* @return FirefoxProfile
*/
public function setPreference($key, $value)
{
if (is_string($value)) {
$value = sprintf('"%s"', $value);
} else {
if (is_int($value)) {
$value = sprintf('%d', $value);
} else {
if (is_bool($value)) {
$value = $value ? 'true' : 'false';
} else {
throw new WebDriverException(
'The value of the preference should be either a string, int or bool.'
);
}
}
}
$this->preferences[$key] = $value;
return $this;
}
/**
* @param mixed $key
* @return mixed
*/
public function getPreference($key)
{
if (array_key_exists($key, $this->preferences)) {
return $this->preferences[$key];
}
return null;
}
/**
* @return string
*/
public function encode()
{
$temp_dir = $this->createTempDirectory('WebDriverFirefoxProfile');
if (isset($this->rdf_file)) {
copy($this->rdf_file, $temp_dir . DIRECTORY_SEPARATOR . 'mimeTypes.rdf');
}
foreach ($this->extensions as $extension) {
$this->installExtension($extension, $temp_dir);
}
foreach ($this->extensions_datas as $dirname => $extension_datas) {
mkdir($temp_dir . DIRECTORY_SEPARATOR . $dirname);
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($extension_datas, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $item) {
$target_dir = $temp_dir . DIRECTORY_SEPARATOR . $dirname . DIRECTORY_SEPARATOR
. $iterator->getSubPathName();
if ($item->isDir()) {
mkdir($target_dir);
} else {
copy($item, $target_dir);
}
}
}
$content = '';
foreach ($this->preferences as $key => $value) {
$content .= sprintf("user_pref(\"%s\", %s);\n", $key, $value);
}
file_put_contents($temp_dir . '/user.js', $content);
$zip = new ZipArchive();
$temp_zip = tempnam(sys_get_temp_dir(), 'WebDriverFirefoxProfileZip');
$zip->open($temp_zip, ZipArchive::CREATE);
$dir = new RecursiveDirectoryIterator($temp_dir);
$files = new RecursiveIteratorIterator($dir);
$dir_prefix = preg_replace(
'#\\\\#',
'\\\\\\\\',
$temp_dir . DIRECTORY_SEPARATOR
);
foreach ($files as $name => $object) {
if (is_dir($name)) {
continue;
}
$path = preg_replace("#^{$dir_prefix}#", '', $name);
$zip->addFile($name, $path);
}
$zip->close();
$profile = base64_encode(file_get_contents($temp_zip));
// clean up
$this->deleteDirectory($temp_dir);
unlink($temp_zip);
return $profile;
}
/**
* @param string $extension The path to the extension.
* @param string $profile_dir The path to the profile directory.
* @return string The path to the directory of this extension.
*/
private function installExtension($extension, $profile_dir)
{
$temp_dir = $this->createTempDirectory('WebDriverFirefoxProfileExtension');
$this->extractTo($extension, $temp_dir);
// This is a hacky way to parse the id since there is no offical RDF parser library.
// Find the correct namespace for the id element.
$install_rdf_path = $temp_dir . '/install.rdf';
$xml = simplexml_load_file($install_rdf_path);
$ns = $xml->getDocNamespaces();
$prefix = '';
if (!empty($ns)) {
foreach ($ns as $key => $value) {
if (mb_strpos($value, '//www.mozilla.org/2004/em-rdf') > 0) {
if ($key != '') {
$prefix = $key . ':'; // Separate the namespace from the name.
}
break;
}
}
}
// Get the extension id from the install manifest.
$matches = [];
preg_match('#<' . $prefix . 'id>([^<]+)</' . $prefix . 'id>#', $xml->asXML(), $matches);
if (isset($matches[1])) {
$ext_dir = $profile_dir . '/extensions/' . $matches[1];
mkdir($ext_dir, 0777, true);
$this->extractTo($extension, $ext_dir);
} else {
$this->deleteDirectory($temp_dir);
throw new WebDriverException('Cannot get the extension id from the install manifest.');
}
$this->deleteDirectory($temp_dir);
return $ext_dir;
}
/**
* @param string $prefix Prefix of the temp directory.
*
* @throws WebDriverException
* @return string The path to the temp directory created.
*/
private function createTempDirectory($prefix = '')
{
$temp_dir = tempnam(sys_get_temp_dir(), $prefix);
if (file_exists($temp_dir)) {
unlink($temp_dir);
mkdir($temp_dir);
if (!is_dir($temp_dir)) {
throw new WebDriverException('Cannot create firefox profile.');
}
}
return $temp_dir;
}
/**
* @param string $directory The path to the directory.
*/
private function deleteDirectory($directory)
{
$dir = new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS);
$paths = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($paths as $path) {
if ($path->isDir() && !$path->isLink()) {
rmdir($path->getPathname());
} else {
unlink($path->getPathname());
}
}
rmdir($directory);
}
/**
* @param string $xpi The path to the .xpi extension.
* @param string $target_dir The path to the unzip directory.
*
* @throws \Exception
* @return FirefoxProfile
*/
private function extractTo($xpi, $target_dir)
{
$zip = new ZipArchive();
if (file_exists($xpi)) {
if ($zip->open($xpi)) {
$zip->extractTo($target_dir);
$zip->close();
} else {
throw new \Exception("Failed to open the firefox extension. '$xpi'");
}
} else {
throw new \Exception("Firefox extension doesn't exist. '$xpi'");
}
return $this;
}
}

View File

@@ -0,0 +1,29 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Internal;
use Facebook\WebDriver\WebDriverAction;
/**
* Move to the location and then release the mouse key.
*/
class WebDriverButtonReleaseAction extends WebDriverMouseAction implements WebDriverAction
{
public function perform()
{
$this->mouse->mouseUp($this->getActionLocation());
}
}

View File

@@ -0,0 +1,26 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Internal;
use Facebook\WebDriver\WebDriverAction;
class WebDriverClickAction extends WebDriverMouseAction implements WebDriverAction
{
public function perform()
{
$this->mouse->click($this->getActionLocation());
}
}

View File

@@ -0,0 +1,29 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Internal;
use Facebook\WebDriver\WebDriverAction;
/**
* Move the the location, click and hold.
*/
class WebDriverClickAndHoldAction extends WebDriverMouseAction implements WebDriverAction
{
public function perform()
{
$this->mouse->mouseDown($this->getActionLocation());
}
}

View File

@@ -0,0 +1,29 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Internal;
use Facebook\WebDriver\WebDriverAction;
/**
* You can call it 'Right Click' if you like.
*/
class WebDriverContextClickAction extends WebDriverMouseAction implements WebDriverAction
{
public function perform()
{
$this->mouse->contextClick($this->getActionLocation());
}
}

View File

@@ -0,0 +1,91 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Internal;
use Facebook\WebDriver\Exception\UnsupportedOperationException;
use Facebook\WebDriver\WebDriverPoint;
/**
* Interface representing basic mouse operations.
*/
class WebDriverCoordinates
{
/**
* @var null
*/
private $onScreen;
/**
* @var callable
*/
private $inViewPort;
/**
* @var callable
*/
private $onPage;
/**
* @var string
*/
private $auxiliary;
/**
* @param null $on_screen
* @param callable $in_view_port
* @param callable $on_page
* @param string $auxiliary
*/
public function __construct($on_screen, callable $in_view_port, callable $on_page, $auxiliary)
{
$this->onScreen = $on_screen;
$this->inViewPort = $in_view_port;
$this->onPage = $on_page;
$this->auxiliary = $auxiliary;
}
/**
* @throws UnsupportedOperationException
* @return WebDriverPoint
*/
public function onScreen()
{
throw new UnsupportedOperationException(
'onScreen is planned but not yet supported by Selenium'
);
}
/**
* @return WebDriverPoint
*/
public function inViewPort()
{
return call_user_func($this->inViewPort);
}
/**
* @return WebDriverPoint
*/
public function onPage()
{
return call_user_func($this->onPage);
}
/**
* @return string The attached object id.
*/
public function getAuxiliary()
{
return $this->auxiliary;
}
}

View File

@@ -0,0 +1,26 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Internal;
use Facebook\WebDriver\WebDriverAction;
class WebDriverDoubleClickAction extends WebDriverMouseAction implements WebDriverAction
{
public function perform()
{
$this->mouse->doubleClick($this->getActionLocation());
}
}

View File

@@ -0,0 +1,27 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Internal;
use Facebook\WebDriver\WebDriverAction;
class WebDriverKeyDownAction extends WebDriverSingleKeyAction implements WebDriverAction
{
public function perform()
{
$this->focusOnElement();
$this->keyboard->pressKey($this->key);
}
}

View File

@@ -0,0 +1,27 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Internal;
use Facebook\WebDriver\WebDriverAction;
class WebDriverKeyUpAction extends WebDriverSingleKeyAction implements WebDriverAction
{
public function perform()
{
$this->focusOnElement();
$this->keyboard->releaseKey($this->key);
}
}

View File

@@ -0,0 +1,61 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Internal;
use Facebook\WebDriver\Internal\WebDriverLocatable;
use Facebook\WebDriver\WebDriverKeyboard;
use Facebook\WebDriver\WebDriverMouse;
/**
* Base class for all keyboard-related actions.
*/
abstract class WebDriverKeysRelatedAction
{
/**
* @var WebDriverKeyboard
*/
protected $keyboard;
/**
* @var WebDriverMouse
*/
protected $mouse;
/**
* @var WebDriverLocatable|null
*/
protected $locationProvider;
/**
* @param WebDriverKeyboard $keyboard
* @param WebDriverMouse $mouse
* @param WebDriverLocatable $location_provider
*/
public function __construct(
WebDriverKeyboard $keyboard,
WebDriverMouse $mouse,
WebDriverLocatable $location_provider = null
) {
$this->keyboard = $keyboard;
$this->mouse = $mouse;
$this->locationProvider = $location_provider;
}
protected function focusOnElement()
{
if ($this->locationProvider) {
$this->mouse->click($this->locationProvider->getCoordinates());
}
}
}

View File

@@ -0,0 +1,61 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Internal;
use Facebook\WebDriver\Internal\WebDriverLocatable;
use Facebook\WebDriver\WebDriverMouse;
/**
* Base class for all mouse-related actions.
*/
class WebDriverMouseAction
{
/**
* @var WebDriverMouse
*/
protected $mouse;
/**
* @var WebDriverLocatable
*/
protected $locationProvider;
/**
* @param WebDriverMouse $mouse
* @param WebDriverLocatable|null $location_provider
*/
public function __construct(WebDriverMouse $mouse, WebDriverLocatable $location_provider = null)
{
$this->mouse = $mouse;
$this->locationProvider = $location_provider;
}
/**
* @return null|WebDriverCoordinates
*/
protected function getActionLocation()
{
if ($this->locationProvider !== null) {
return $this->locationProvider->getCoordinates();
}
return null;
}
protected function moveToLocation()
{
$this->mouse->mouseMove($this->locationProvider);
}
}

View File

@@ -0,0 +1,26 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Internal;
use Facebook\WebDriver\WebDriverAction;
class WebDriverMouseMoveAction extends WebDriverMouseAction implements WebDriverAction
{
public function perform()
{
$this->mouse->mouseMove($this->getActionLocation());
}
}

View File

@@ -0,0 +1,58 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Internal;
use Facebook\WebDriver\Internal\WebDriverLocatable;
use Facebook\WebDriver\WebDriverAction;
use Facebook\WebDriver\WebDriverMouse;
class WebDriverMoveToOffsetAction extends WebDriverMouseAction implements WebDriverAction
{
/**
* @var int|null
*/
private $xOffset;
/**
* @var int|null
*/
private $yOffset;
/**
* @param WebDriverMouse $mouse
* @param WebDriverLocatable|null $location_provider
* @param int|null $x_offset
* @param int|null $y_offset
*/
public function __construct(
WebDriverMouse $mouse,
WebDriverLocatable $location_provider = null,
$x_offset = null,
$y_offset = null
) {
parent::__construct($mouse, $location_provider);
$this->xOffset = $x_offset;
$this->yOffset = $y_offset;
}
public function perform()
{
$this->mouse->mouseMove(
$this->getActionLocation(),
$this->xOffset,
$this->yOffset
);
}
}

View File

@@ -0,0 +1,51 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Internal;
use Facebook\WebDriver\Internal\WebDriverLocatable;
use Facebook\WebDriver\WebDriverAction;
use Facebook\WebDriver\WebDriverKeyboard;
use Facebook\WebDriver\WebDriverMouse;
class WebDriverSendKeysAction extends WebDriverKeysRelatedAction implements WebDriverAction
{
/**
* @var string
*/
private $keys = '';
/**
* @param WebDriverKeyboard $keyboard
* @param WebDriverMouse $mouse
* @param WebDriverLocatable $location_provider
* @param string $keys
*/
public function __construct(
WebDriverKeyboard $keyboard,
WebDriverMouse $mouse,
WebDriverLocatable $location_provider = null,
$keys = ''
) {
parent::__construct($keyboard, $mouse, $location_provider);
$this->keys = $keys;
}
public function perform()
{
$this->focusOnElement();
$this->keyboard->sendKeys($this->keys);
}
}

View File

@@ -0,0 +1,37 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Internal;
use Facebook\WebDriver\Internal\WebDriverLocatable;
use Facebook\WebDriver\WebDriverAction;
use Facebook\WebDriver\WebDriverKeyboard;
use Facebook\WebDriver\WebDriverMouse;
abstract class WebDriverSingleKeyAction extends WebDriverKeysRelatedAction implements WebDriverAction
{
/** @var string */
protected $key = '';
public function __construct(
WebDriverKeyboard $keyboard,
WebDriverMouse $mouse,
WebDriverLocatable $location_provider = null,
$key = ''
) {
parent::__construct($keyboard, $mouse, $location_provider);
$this->key = $key;
}
}

View File

@@ -0,0 +1,26 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Touch;
use Facebook\WebDriver\WebDriverAction;
class WebDriverDoubleTapAction extends WebDriverTouchAction implements WebDriverAction
{
public function perform()
{
$this->touchScreen->doubleTap($this->locationProvider);
}
}

View File

@@ -0,0 +1,47 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Touch;
use Facebook\WebDriver\WebDriverAction;
class WebDriverDownAction extends WebDriverTouchAction implements WebDriverAction
{
/**
* @var int
*/
private $x;
/**
* @var int
*/
private $y;
/**
* @param WebDriverTouchScreen $touch_screen
* @param int $x
* @param int $y
*/
public function __construct(WebDriverTouchScreen $touch_screen, $x, $y)
{
$this->x = $x;
$this->y = $y;
parent::__construct($touch_screen);
}
public function perform()
{
$this->touchScreen->down($this->x, $this->y);
}
}

View File

@@ -0,0 +1,47 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Touch;
use Facebook\WebDriver\WebDriverAction;
class WebDriverFlickAction extends WebDriverTouchAction implements WebDriverAction
{
/**
* @var int
*/
private $x;
/**
* @var int
*/
private $y;
/**
* @param WebDriverTouchScreen $touch_screen
* @param int $x
* @param int $y
*/
public function __construct(WebDriverTouchScreen $touch_screen, $x, $y)
{
$this->x = $x;
$this->y = $y;
parent::__construct($touch_screen);
}
public function perform()
{
$this->touchScreen->flick($this->x, $this->y);
}
}

View File

@@ -0,0 +1,65 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Touch;
use Facebook\WebDriver\WebDriverAction;
use Facebook\WebDriver\WebDriverElement;
class WebDriverFlickFromElementAction extends WebDriverTouchAction implements WebDriverAction
{
/**
* @var int
*/
private $x;
/**
* @var int
*/
private $y;
/**
* @var int
*/
private $speed;
/**
* @param WebDriverTouchScreen $touch_screen
* @param WebDriverElement $element
* @param int $x
* @param int $y
* @param int $speed
*/
public function __construct(
WebDriverTouchScreen $touch_screen,
WebDriverElement $element,
$x,
$y,
$speed
) {
$this->x = $x;
$this->y = $y;
$this->speed = $speed;
parent::__construct($touch_screen, $element);
}
public function perform()
{
$this->touchScreen->flickFromElement(
$this->locationProvider,
$this->x,
$this->y,
$this->speed
);
}
}

View File

@@ -0,0 +1,26 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Touch;
use Facebook\WebDriver\WebDriverAction;
class WebDriverLongPressAction extends WebDriverTouchAction implements WebDriverAction
{
public function perform()
{
$this->touchScreen->longPress($this->locationProvider);
}
}

View File

@@ -0,0 +1,41 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Touch;
use Facebook\WebDriver\WebDriverAction;
class WebDriverMoveAction extends WebDriverTouchAction implements WebDriverAction
{
private $x;
private $y;
/**
* @param WebDriverTouchScreen $touch_screen
* @param int $x
* @param int $y
*/
public function __construct(WebDriverTouchScreen $touch_screen, $x, $y)
{
$this->x = $x;
$this->y = $y;
parent::__construct($touch_screen);
}
public function perform()
{
$this->touchScreen->move($this->x, $this->y);
}
}

View File

@@ -0,0 +1,41 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Touch;
use Facebook\WebDriver\WebDriverAction;
class WebDriverScrollAction extends WebDriverTouchAction implements WebDriverAction
{
private $x;
private $y;
/**
* @param WebDriverTouchScreen $touch_screen
* @param int $x
* @param int $y
*/
public function __construct(WebDriverTouchScreen $touch_screen, $x, $y)
{
$this->x = $x;
$this->y = $y;
parent::__construct($touch_screen);
}
public function perform()
{
$this->touchScreen->scroll($this->x, $this->y);
}
}

View File

@@ -0,0 +1,51 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Touch;
use Facebook\WebDriver\WebDriverAction;
use Facebook\WebDriver\WebDriverElement;
class WebDriverScrollFromElementAction extends WebDriverTouchAction implements WebDriverAction
{
private $x;
private $y;
/**
* @param WebDriverTouchScreen $touch_screen
* @param WebDriverElement $element
* @param int $x
* @param int $y
*/
public function __construct(
WebDriverTouchScreen $touch_screen,
WebDriverElement $element,
$x,
$y
) {
$this->x = $x;
$this->y = $y;
parent::__construct($touch_screen, $element);
}
public function perform()
{
$this->touchScreen->scrollFromElement(
$this->locationProvider,
$this->x,
$this->y
);
}
}

View File

@@ -0,0 +1,26 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Touch;
use Facebook\WebDriver\WebDriverAction;
class WebDriverTapAction extends WebDriverTouchAction implements WebDriverAction
{
public function perform()
{
$this->touchScreen->tap($this->locationProvider);
}
}

View File

@@ -0,0 +1,55 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Touch;
use Facebook\WebDriver\Interactions\Internal\WebDriverCoordinates;
use Facebook\WebDriver\Internal\WebDriverLocatable;
/**
* Base class for all touch-related actions.
*/
abstract class WebDriverTouchAction
{
/**
* @var WebDriverTouchScreen
*/
protected $touchScreen;
/**
* @var WebDriverLocatable
*/
protected $locationProvider;
/**
* @param WebDriverTouchScreen $touch_screen
* @param WebDriverLocatable $location_provider
*/
public function __construct(
WebDriverTouchScreen $touch_screen,
WebDriverLocatable $location_provider = null
) {
$this->touchScreen = $touch_screen;
$this->locationProvider = $location_provider;
}
/**
* @return null|WebDriverCoordinates
*/
protected function getActionLocation()
{
return $this->locationProvider !== null
? $this->locationProvider->getCoordinates() : null;
}
}

View File

@@ -0,0 +1,127 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions\Touch;
use Facebook\WebDriver\WebDriverElement;
/**
* Interface representing touch screen operations.
*/
interface WebDriverTouchScreen
{
/**
* Single tap on the touch enabled device.
*
* @param WebDriverElement $element
* @return $this
*/
public function tap(WebDriverElement $element);
/**
* Double tap on the touch screen using finger motion events.
*
* @param WebDriverElement $element
* @return $this
*/
public function doubleTap(WebDriverElement $element);
/**
* Finger down on the screen.
*
* @param int $x
* @param int $y
* @return $this
*/
public function down($x, $y);
/**
* Flick on the touch screen using finger motion events. Use this flick
* command if you don't care where the flick starts on the screen.
*
* @param int $xspeed
* @param int $yspeed
* @return $this
*/
public function flick($xspeed, $yspeed);
/**
* Flick on the touch screen using finger motion events.
* This flickcommand starts at a particular screen location.
*
* @param WebDriverElement $element
* @param int $xoffset
* @param int $yoffset
* @param int $speed
* @return $this
*/
public function flickFromElement(
WebDriverElement $element,
$xoffset,
$yoffset,
$speed
);
/**
* Long press on the touch screen using finger motion events.
*
* @param WebDriverElement $element
* @return $this
*/
public function longPress(WebDriverElement $element);
/**
* Finger move on the screen.
*
* @param int $x
* @param int $y
* @return $this
*/
public function move($x, $y);
/**
* Scroll on the touch screen using finger based motion events. Use this
* command if you don't care where the scroll starts on the screen.
*
* @param int $xoffset
* @param int $yoffset
* @return $this
*/
public function scroll($xoffset, $yoffset);
/**
* Scroll on the touch screen using finger based motion events. Use this
* command to start scrolling at a particular screen location.
*
* @param WebDriverElement $element
* @param int $xoffset
* @param int $yoffset
* @return $this
*/
public function scrollFromElement(
WebDriverElement $element,
$xoffset,
$yoffset
);
/**
* Finger up on the screen.
*
* @param int $x
* @param int $y
* @return $this
*/
public function up($x, $y);
}

View File

@@ -0,0 +1,282 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions;
use Facebook\WebDriver\Interactions\Internal\WebDriverButtonReleaseAction;
use Facebook\WebDriver\Interactions\Internal\WebDriverClickAction;
use Facebook\WebDriver\Interactions\Internal\WebDriverClickAndHoldAction;
use Facebook\WebDriver\Interactions\Internal\WebDriverContextClickAction;
use Facebook\WebDriver\Interactions\Internal\WebDriverDoubleClickAction;
use Facebook\WebDriver\Interactions\Internal\WebDriverKeyDownAction;
use Facebook\WebDriver\Interactions\Internal\WebDriverKeyUpAction;
use Facebook\WebDriver\Interactions\Internal\WebDriverMouseMoveAction;
use Facebook\WebDriver\Interactions\Internal\WebDriverMoveToOffsetAction;
use Facebook\WebDriver\Interactions\Internal\WebDriverSendKeysAction;
use Facebook\WebDriver\WebDriver;
use Facebook\WebDriver\WebDriverElement;
use Facebook\WebDriver\WebDriverHasInputDevices;
/**
* WebDriver action builder. It implements the builder pattern.
*/
class WebDriverActions
{
protected $driver;
protected $keyboard;
protected $mouse;
protected $action;
/**
* @param WebDriverHasInputDevices $driver
*/
public function __construct(WebDriverHasInputDevices $driver)
{
$this->driver = $driver;
$this->keyboard = $driver->getKeyboard();
$this->mouse = $driver->getMouse();
$this->action = new WebDriverCompositeAction();
}
/**
* A convenience method for performing the actions without calling build().
*/
public function perform()
{
$this->action->perform();
}
/**
* Mouse click.
* If $element is provided, move to the middle of the element first.
*
* @param WebDriverElement $element
* @return WebDriverActions
*/
public function click(WebDriverElement $element = null)
{
$this->action->addAction(
new WebDriverClickAction($this->mouse, $element)
);
return $this;
}
/**
* Mouse click and hold.
* If $element is provided, move to the middle of the element first.
*
* @param WebDriverElement $element
* @return WebDriverActions
*/
public function clickAndHold(WebDriverElement $element = null)
{
$this->action->addAction(
new WebDriverClickAndHoldAction($this->mouse, $element)
);
return $this;
}
/**
* Context-click (right click).
* If $element is provided, move to the middle of the element first.
*
* @param WebDriverElement $element
* @return WebDriverActions
*/
public function contextClick(WebDriverElement $element = null)
{
$this->action->addAction(
new WebDriverContextClickAction($this->mouse, $element)
);
return $this;
}
/**
* Double click.
* If $element is provided, move to the middle of the element first.
*
* @param WebDriverElement $element
* @return WebDriverActions
*/
public function doubleClick(WebDriverElement $element = null)
{
$this->action->addAction(
new WebDriverDoubleClickAction($this->mouse, $element)
);
return $this;
}
/**
* Drag and drop from $source to $target.
*
* @param WebDriverElement $source
* @param WebDriverElement $target
* @return WebDriverActions
*/
public function dragAndDrop(WebDriverElement $source, WebDriverElement $target)
{
$this->action->addAction(
new WebDriverClickAndHoldAction($this->mouse, $source)
);
$this->action->addAction(
new WebDriverMouseMoveAction($this->mouse, $target)
);
$this->action->addAction(
new WebDriverButtonReleaseAction($this->mouse, $target)
);
return $this;
}
/**
* Drag $source and drop by offset ($x_offset, $y_offset).
*
* @param WebDriverElement $source
* @param int $x_offset
* @param int $y_offset
* @return WebDriverActions
*/
public function dragAndDropBy(WebDriverElement $source, $x_offset, $y_offset)
{
$this->action->addAction(
new WebDriverClickAndHoldAction($this->mouse, $source)
);
$this->action->addAction(
new WebDriverMoveToOffsetAction($this->mouse, null, $x_offset, $y_offset)
);
$this->action->addAction(
new WebDriverButtonReleaseAction($this->mouse, null)
);
return $this;
}
/**
* Mouse move by offset.
*
* @param int $x_offset
* @param int $y_offset
* @return WebDriverActions
*/
public function moveByOffset($x_offset, $y_offset)
{
$this->action->addAction(
new WebDriverMoveToOffsetAction($this->mouse, null, $x_offset, $y_offset)
);
return $this;
}
/**
* Move to the middle of the given WebDriverElement.
* Extra shift, calculated from the top-left corner of the element, can be set by passing $x_offset and $y_offset
* parameters.
*
* @param WebDriverElement $element
* @param int $x_offset
* @param int $y_offset
* @return WebDriverActions
*/
public function moveToElement(WebDriverElement $element, $x_offset = null, $y_offset = null)
{
$this->action->addAction(new WebDriverMoveToOffsetAction(
$this->mouse,
$element,
$x_offset,
$y_offset
));
return $this;
}
/**
* Release the mouse button.
* If $element is provided, move to the middle of the element first.
*
* @param WebDriverElement $element
* @return WebDriverActions
*/
public function release(WebDriverElement $element = null)
{
$this->action->addAction(
new WebDriverButtonReleaseAction($this->mouse, $element)
);
return $this;
}
/**
* Press a key on keyboard.
* If $element is provided, focus on that element first.
*
* @see WebDriverKeys for special keys like CONTROL, ALT, etc.
* @param WebDriverElement $element
* @param string $key
* @return WebDriverActions
*/
public function keyDown(WebDriverElement $element = null, $key = null)
{
$this->action->addAction(
new WebDriverKeyDownAction($this->keyboard, $this->mouse, $element, $key)
);
return $this;
}
/**
* Release a key on keyboard.
* If $element is provided, focus on that element first.
*
* @see WebDriverKeys for special keys like CONTROL, ALT, etc.
* @param WebDriverElement $element
* @param string $key
* @return WebDriverActions
*/
public function keyUp(WebDriverElement $element = null, $key = null)
{
$this->action->addAction(
new WebDriverKeyUpAction($this->keyboard, $this->mouse, $element, $key)
);
return $this;
}
/**
* Send keys by keyboard.
* If $element is provided, focus on that element first.
*
* @see WebDriverKeys for special keys like CONTROL, ALT, etc.
* @param WebDriverElement $element
* @param string $keys
* @return WebDriverActions
*/
public function sendKeys(WebDriverElement $element = null, $keys = null)
{
$this->action->addAction(
new WebDriverSendKeysAction(
$this->keyboard,
$this->mouse,
$element,
$keys
)
);
return $this;
}
}

View File

@@ -0,0 +1,62 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions;
use Facebook\WebDriver\WebDriverAction;
/**
* An action for aggregating actions and triggering all of them afterwards.
*/
class WebDriverCompositeAction implements WebDriverAction
{
/**
* @var WebDriverAction[]
*/
private $actions = [];
/**
* Add an WebDriverAction to the sequence.
*
* @param WebDriverAction $action
* @return WebDriverCompositeAction The current instance.
*/
public function addAction(WebDriverAction $action)
{
$this->actions[] = $action;
return $this;
}
/**
* Get the number of actions in the sequence.
*
* @return int The number of actions.
*/
public function getNumberOfActions()
{
return count($this->actions);
}
/**
* Perform the sequence of actions.
*/
public function perform()
{
foreach ($this->actions as $action) {
$action->perform();
}
}
}

View File

@@ -0,0 +1,193 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Interactions;
use Facebook\WebDriver\Interactions\Touch\WebDriverDoubleTapAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverDownAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverFlickAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverFlickFromElementAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverLongPressAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverMoveAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverScrollAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverScrollFromElementAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverTapAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverTouchScreen;
use Facebook\WebDriver\WebDriver;
use Facebook\WebDriver\WebDriverElement;
use Facebook\WebDriver\WebDriverUpAction;
/**
* WebDriver action builder for touch events
*/
class WebDriverTouchActions extends WebDriverActions
{
/**
* @var WebDriverTouchScreen
*/
protected $touchScreen;
public function __construct(WebDriver $driver)
{
parent::__construct($driver);
$this->touchScreen = $driver->getTouch();
}
/**
* @param WebDriverElement $element
* @return WebDriverTouchActions
*/
public function tap(WebDriverElement $element)
{
$this->action->addAction(
new WebDriverTapAction($this->touchScreen, $element)
);
return $this;
}
/**
* @param int $x
* @param int $y
* @return WebDriverTouchActions
*/
public function down($x, $y)
{
$this->action->addAction(
new WebDriverDownAction($this->touchScreen, $x, $y)
);
return $this;
}
/**
* @param int $x
* @param int $y
* @return WebDriverTouchActions
*/
public function up($x, $y)
{
$this->action->addAction(
new WebDriverUpAction($this->touchScreen, $x, $y)
);
return $this;
}
/**
* @param int $x
* @param int $y
* @return WebDriverTouchActions
*/
public function move($x, $y)
{
$this->action->addAction(
new WebDriverMoveAction($this->touchScreen, $x, $y)
);
return $this;
}
/**
* @param int $x
* @param int $y
* @return WebDriverTouchActions
*/
public function scroll($x, $y)
{
$this->action->addAction(
new WebDriverScrollAction($this->touchScreen, $x, $y)
);
return $this;
}
/**
* @param WebDriverElement $element
* @param int $x
* @param int $y
* @return WebDriverTouchActions
*/
public function scrollFromElement(WebDriverElement $element, $x, $y)
{
$this->action->addAction(
new WebDriverScrollFromElementAction($this->touchScreen, $element, $x, $y)
);
return $this;
}
/**
* @param WebDriverElement $element
* @return WebDriverTouchActions
*/
public function doubleTap(WebDriverElement $element)
{
$this->action->addAction(
new WebDriverDoubleTapAction($this->touchScreen, $element)
);
return $this;
}
/**
* @param WebDriverElement $element
* @return WebDriverTouchActions
*/
public function longPress(WebDriverElement $element)
{
$this->action->addAction(
new WebDriverLongPressAction($this->touchScreen, $element)
);
return $this;
}
/**
* @param int $x
* @param int $y
* @return WebDriverTouchActions
*/
public function flick($x, $y)
{
$this->action->addAction(
new WebDriverFlickAction($this->touchScreen, $x, $y)
);
return $this;
}
/**
* @param WebDriverElement $element
* @param int $x
* @param int $y
* @param int $speed
* @return WebDriverTouchActions
*/
public function flickFromElement(WebDriverElement $element, $x, $y, $speed)
{
$this->action->addAction(
new WebDriverFlickFromElementAction(
$this->touchScreen,
$element,
$x,
$y,
$speed
)
);
return $this;
}
}

View File

@@ -0,0 +1,29 @@
<?php
// copyright 2004-present facebook. all rights reserved.
//
// licensed under the apache license, version 2.0 (the "license");
// you may not use this file except in compliance with the license.
// you may obtain a copy of the license at
//
// http://www.apache.org/licenses/license-2.0
//
// unless required by applicable law or agreed to in writing, software
// distributed under the license is distributed on an "as is" basis,
// without warranties or conditions of any kind, either express or implied.
// see the license for the specific language governing permissions and
// limitations under the license.
namespace Facebook\WebDriver\Internal;
use Facebook\WebDriver\Interactions\Internal\WebDriverCoordinates;
/**
* Interface representing basic mouse operations.
*/
interface WebDriverLocatable
{
/**
* @return WebDriverCoordinates
*/
public function getCoordinates();
}

View File

@@ -0,0 +1,48 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver;
/**
* WebDriver interface implemented by drivers that support JavaScript.
*/
interface JavaScriptExecutor
{
/**
* Inject a snippet of JavaScript into the page for execution in the context
* of the currently selected frame. The executed script is assumed to be
* synchronous and the result of evaluating the script will be returned.
*
* @param string $script The script to inject.
* @param array $arguments The arguments of the script.
* @return mixed The return value of the script.
*/
public function executeScript($script, array $arguments = []);
/**
* Inject a snippet of JavaScript into the page for asynchronous execution in
* the context of the currently selected frame.
*
* The driver will pass a callback as the last argument to the snippet, and
* block until the callback is invoked.
*
* @see WebDriverExecuteAsyncScriptTestCase
*
* @param string $script The script to inject.
* @param array $arguments The arguments of the script.
* @return mixed The value passed by the script to the callback.
*/
public function executeAsyncScript($script, array $arguments = []);
}

View File

@@ -0,0 +1,85 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Net;
use Exception;
use Facebook\WebDriver\Exception\TimeOutException;
class URLChecker
{
const POLL_INTERVAL_MS = 500;
const CONNECT_TIMEOUT_MS = 500;
public function waitUntilAvailable($timeout_in_ms, $url)
{
$end = microtime(true) + $timeout_in_ms / 1000;
while ($end > microtime(true)) {
if ($this->getHTTPResponseCode($url) === 200) {
return $this;
}
usleep(self::POLL_INTERVAL_MS);
}
throw new TimeOutException(sprintf(
'Timed out waiting for %s to become available after %d ms.',
$url,
$timeout_in_ms
));
}
public function waitUntilUnavailable($timeout_in_ms, $url)
{
$end = microtime(true) + $timeout_in_ms / 1000;
while ($end > microtime(true)) {
if ($this->getHTTPResponseCode($url) !== 200) {
return $this;
}
usleep(self::POLL_INTERVAL_MS);
}
throw new TimeOutException(sprintf(
'Timed out waiting for %s to become unavailable after %d ms.',
$url,
$timeout_in_ms
));
}
private function getHTTPResponseCode($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// The PHP doc indicates that CURLOPT_CONNECTTIMEOUT_MS constant is added in cURL 7.16.2
// available since PHP 5.2.3.
if (!defined('CURLOPT_CONNECTTIMEOUT_MS')) {
define('CURLOPT_CONNECTTIMEOUT_MS', 156); // default value for CURLOPT_CONNECTTIMEOUT_MS
}
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, self::CONNECT_TIMEOUT_MS);
$code = null;
try {
curl_exec($ch);
$info = curl_getinfo($ch);
$code = $info['http_code'];
} catch (Exception $e) {
}
curl_close($ch);
return $code;
}
}

View File

@@ -0,0 +1,344 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Remote;
use Exception;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Firefox\FirefoxDriver;
use Facebook\WebDriver\Firefox\FirefoxPreferences;
use Facebook\WebDriver\Firefox\FirefoxProfile;
use Facebook\WebDriver\WebDriverCapabilities;
use Facebook\WebDriver\WebDriverPlatform;
class DesiredCapabilities implements WebDriverCapabilities
{
/**
* @var array
*/
private $capabilities;
public function __construct(array $capabilities = [])
{
$this->capabilities = $capabilities;
}
/**
* @return string The name of the browser.
*/
public function getBrowserName()
{
return $this->get(WebDriverCapabilityType::BROWSER_NAME, '');
}
/**
* @param string $browser_name
* @return DesiredCapabilities
*/
public function setBrowserName($browser_name)
{
$this->set(WebDriverCapabilityType::BROWSER_NAME, $browser_name);
return $this;
}
/**
* @return string The version of the browser.
*/
public function getVersion()
{
return $this->get(WebDriverCapabilityType::VERSION, '');
}
/**
* @param string $version
* @return DesiredCapabilities
*/
public function setVersion($version)
{
$this->set(WebDriverCapabilityType::VERSION, $version);
return $this;
}
/**
* @param string $name
* @return mixed The value of a capability.
*/
public function getCapability($name)
{
return $this->get($name);
}
/**
* @param string $name
* @param mixed $value
* @return DesiredCapabilities
*/
public function setCapability($name, $value)
{
$this->set($name, $value);
return $this;
}
/**
* @return string The name of the platform.
*/
public function getPlatform()
{
return $this->get(WebDriverCapabilityType::PLATFORM, '');
}
/**
* @param string $platform
* @return DesiredCapabilities
*/
public function setPlatform($platform)
{
$this->set(WebDriverCapabilityType::PLATFORM, $platform);
return $this;
}
/**
* @param string $capability_name
* @return bool Whether the value is not null and not false.
*/
public function is($capability_name)
{
return (bool) $this->get($capability_name);
}
/**
* @todo Remove in next major release (BC)
* @deprecated All browsers are always JS enabled except HtmlUnit and it's not meaningful to disable JS execution.
* @return bool Whether javascript is enabled.
*/
public function isJavascriptEnabled()
{
return $this->get(WebDriverCapabilityType::JAVASCRIPT_ENABLED, false);
}
/**
* This is a htmlUnit-only option.
*
* @param bool $enabled
* @throws Exception
* @return DesiredCapabilities
* @see https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#read-write-capabilities
*/
public function setJavascriptEnabled($enabled)
{
$browser = $this->getBrowserName();
if ($browser && $browser !== WebDriverBrowserType::HTMLUNIT) {
throw new Exception(
'isJavascriptEnabled() is a htmlunit-only option. ' .
'See https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#read-write-capabilities.'
);
}
$this->set(WebDriverCapabilityType::JAVASCRIPT_ENABLED, $enabled);
return $this;
}
/**
* @return array
*/
public function toArray()
{
if (isset($this->capabilities[ChromeOptions::CAPABILITY]) &&
$this->capabilities[ChromeOptions::CAPABILITY] instanceof ChromeOptions
) {
$this->capabilities[ChromeOptions::CAPABILITY] =
$this->capabilities[ChromeOptions::CAPABILITY]->toArray();
}
if (isset($this->capabilities[FirefoxDriver::PROFILE]) &&
$this->capabilities[FirefoxDriver::PROFILE] instanceof FirefoxProfile
) {
$this->capabilities[FirefoxDriver::PROFILE] =
$this->capabilities[FirefoxDriver::PROFILE]->encode();
}
return $this->capabilities;
}
/**
* @return static
*/
public static function android()
{
return new static([
WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::ANDROID,
WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANDROID,
]);
}
/**
* @return static
*/
public static function chrome()
{
return new static([
WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::CHROME,
WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY,
]);
}
/**
* @return static
*/
public static function firefox()
{
$caps = new static([
WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::FIREFOX,
WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY,
]);
// disable the "Reader View" help tooltip, which can hide elements in the window.document
$profile = new FirefoxProfile();
$profile->setPreference(FirefoxPreferences::READER_PARSE_ON_LOAD_ENABLED, false);
$caps->setCapability(FirefoxDriver::PROFILE, $profile);
return $caps;
}
/**
* @return static
*/
public static function htmlUnit()
{
return new static([
WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::HTMLUNIT,
WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY,
]);
}
/**
* @return static
*/
public static function htmlUnitWithJS()
{
$caps = new static([
WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::HTMLUNIT,
WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY,
]);
return $caps->setJavascriptEnabled(true);
}
/**
* @return static
*/
public static function internetExplorer()
{
return new static([
WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::IE,
WebDriverCapabilityType::PLATFORM => WebDriverPlatform::WINDOWS,
]);
}
/**
* @return static
*/
public static function microsoftEdge()
{
return new static([
WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::MICROSOFT_EDGE,
WebDriverCapabilityType::PLATFORM => WebDriverPlatform::WINDOWS,
]);
}
/**
* @return static
*/
public static function iphone()
{
return new static([
WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::IPHONE,
WebDriverCapabilityType::PLATFORM => WebDriverPlatform::MAC,
]);
}
/**
* @return static
*/
public static function ipad()
{
return new static([
WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::IPAD,
WebDriverCapabilityType::PLATFORM => WebDriverPlatform::MAC,
]);
}
/**
* @return static
*/
public static function opera()
{
return new static([
WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::OPERA,
WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY,
]);
}
/**
* @return static
*/
public static function safari()
{
return new static([
WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::SAFARI,
WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY,
]);
}
/**
* @return static
*/
public static function phantomjs()
{
return new static([
WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::PHANTOMJS,
WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY,
]);
}
/**
* @param string $key
* @param mixed $value
* @return DesiredCapabilities
*/
private function set($key, $value)
{
$this->capabilities[$key] = $value;
return $this;
}
/**
* @param string $key
* @param mixed $default
* @return mixed
*/
private function get($key, $default = null)
{
return isset($this->capabilities[$key])
? $this->capabilities[$key]
: $default;
}
}

View File

@@ -0,0 +1,152 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Remote;
/**
* This list of command defined in the WebDriver json wire protocol.
*
* @codeCoverageIgnore
*/
class DriverCommand
{
const GET_ALL_SESSIONS = 'getAllSessions';
const GET_CAPABILITIES = 'getCapabilities';
const NEW_SESSION = 'newSession';
const STATUS = 'status';
const CLOSE = 'close';
const QUIT = 'quit';
const GET = 'get';
const GO_BACK = 'goBack';
const GO_FORWARD = 'goForward';
const REFRESH = 'refresh';
const ADD_COOKIE = 'addCookie';
const GET_ALL_COOKIES = 'getCookies';
const DELETE_COOKIE = 'deleteCookie';
const DELETE_ALL_COOKIES = 'deleteAllCookies';
const FIND_ELEMENT = 'findElement';
const FIND_ELEMENTS = 'findElements';
const FIND_CHILD_ELEMENT = 'findChildElement';
const FIND_CHILD_ELEMENTS = 'findChildElements';
const CLEAR_ELEMENT = 'clearElement';
const CLICK_ELEMENT = 'clickElement';
const SEND_KEYS_TO_ELEMENT = 'sendKeysToElement';
const SEND_KEYS_TO_ACTIVE_ELEMENT = 'sendKeysToActiveElement';
const SUBMIT_ELEMENT = 'submitElement';
const UPLOAD_FILE = 'uploadFile';
const GET_CURRENT_WINDOW_HANDLE = 'getCurrentWindowHandle';
const GET_WINDOW_HANDLES = 'getWindowHandles';
const GET_CURRENT_CONTEXT_HANDLE = 'getCurrentContextHandle';
const GET_CONTEXT_HANDLES = 'getContextHandles';
// Switching between to window/frame/iframe
const SWITCH_TO_WINDOW = 'switchToWindow';
const SWITCH_TO_CONTEXT = 'switchToContext';
const SWITCH_TO_FRAME = 'switchToFrame';
const SWITCH_TO_PARENT_FRAME = 'switchToParentFrame';
const GET_ACTIVE_ELEMENT = 'getActiveElement';
// Information of the page
const GET_CURRENT_URL = 'getCurrentUrl';
const GET_PAGE_SOURCE = 'getPageSource';
const GET_TITLE = 'getTitle';
// Javascript API
const EXECUTE_SCRIPT = 'executeScript';
const EXECUTE_ASYNC_SCRIPT = 'executeAsyncScript';
// API getting information from an element.
const GET_ELEMENT_TEXT = 'getElementText';
const GET_ELEMENT_TAG_NAME = 'getElementTagName';
const IS_ELEMENT_SELECTED = 'isElementSelected';
const IS_ELEMENT_ENABLED = 'isElementEnabled';
const IS_ELEMENT_DISPLAYED = 'isElementDisplayed';
const GET_ELEMENT_LOCATION = 'getElementLocation';
const GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW = 'getElementLocationOnceScrolledIntoView';
const GET_ELEMENT_SIZE = 'getElementSize';
const GET_ELEMENT_ATTRIBUTE = 'getElementAttribute';
const GET_ELEMENT_VALUE_OF_CSS_PROPERTY = 'getElementValueOfCssProperty';
const ELEMENT_EQUALS = 'elementEquals';
const SCREENSHOT = 'screenshot';
// Alert API
const ACCEPT_ALERT = 'acceptAlert';
const DISMISS_ALERT = 'dismissAlert';
const GET_ALERT_TEXT = 'getAlertText';
const SET_ALERT_VALUE = 'setAlertValue';
// Timeout API
const SET_TIMEOUT = 'setTimeout';
const IMPLICITLY_WAIT = 'implicitlyWait';
const SET_SCRIPT_TIMEOUT = 'setScriptTimeout';
/** @deprecated */
const EXECUTE_SQL = 'executeSQL';
const GET_LOCATION = 'getLocation';
const SET_LOCATION = 'setLocation';
const GET_APP_CACHE = 'getAppCache';
const GET_APP_CACHE_STATUS = 'getStatus';
const CLEAR_APP_CACHE = 'clearAppCache';
const IS_BROWSER_ONLINE = 'isBrowserOnline';
const SET_BROWSER_ONLINE = 'setBrowserOnline';
// Local storage
const GET_LOCAL_STORAGE_ITEM = 'getLocalStorageItem';
const GET_LOCAL_STORAGE_KEYS = 'getLocalStorageKeys';
const SET_LOCAL_STORAGE_ITEM = 'setLocalStorageItem';
const REMOVE_LOCAL_STORAGE_ITEM = 'removeLocalStorageItem';
const CLEAR_LOCAL_STORAGE = 'clearLocalStorage';
const GET_LOCAL_STORAGE_SIZE = 'getLocalStorageSize';
// Session storage
const GET_SESSION_STORAGE_ITEM = 'getSessionStorageItem';
const GET_SESSION_STORAGE_KEYS = 'getSessionStorageKey';
const SET_SESSION_STORAGE_ITEM = 'setSessionStorageItem';
const REMOVE_SESSION_STORAGE_ITEM = 'removeSessionStorageItem';
const CLEAR_SESSION_STORAGE = 'clearSessionStorage';
const GET_SESSION_STORAGE_SIZE = 'getSessionStorageSize';
// Screen orientation
const SET_SCREEN_ORIENTATION = 'setScreenOrientation';
const GET_SCREEN_ORIENTATION = 'getScreenOrientation';
// These belong to the Advanced user interactions - an element is optional for these commands.
const CLICK = 'mouseClick';
const DOUBLE_CLICK = 'mouseDoubleClick';
const MOUSE_DOWN = 'mouseButtonDown';
const MOUSE_UP = 'mouseButtonUp';
const MOVE_TO = 'mouseMoveTo';
// Those allow interactions with the Input Methods installed on the system.
const IME_GET_AVAILABLE_ENGINES = 'imeGetAvailableEngines';
const IME_GET_ACTIVE_ENGINE = 'imeGetActiveEngine';
const IME_IS_ACTIVATED = 'imeIsActivated';
const IME_DEACTIVATE = 'imeDeactivate';
const IME_ACTIVATE_ENGINE = 'imeActivateEngine';
// These belong to the Advanced Touch API
const TOUCH_SINGLE_TAP = 'touchSingleTap';
const TOUCH_DOWN = 'touchDown';
const TOUCH_UP = 'touchUp';
const TOUCH_MOVE = 'touchMove';
const TOUCH_SCROLL = 'touchScroll';
const TOUCH_DOUBLE_TAP = 'touchDoubleTap';
const TOUCH_LONG_PRESS = 'touchLongPress';
const TOUCH_FLICK = 'touchFlick';
// Window API (beta)
const SET_WINDOW_SIZE = 'setWindowSize';
const SET_WINDOW_POSITION = 'setWindowPosition';
const GET_WINDOW_SIZE = 'getWindowSize';
const GET_WINDOW_POSITION = 'getWindowPosition';
const MAXIMIZE_WINDOW = 'maximizeWindow';
// Logging API
const GET_AVAILABLE_LOG_TYPES = 'getAvailableLogTypes';
const GET_LOG = 'getLog';
const GET_SESSION_LOGS = 'getSessionLogs';
// Mobile API
const GET_NETWORK_CONNECTION = 'getNetworkConnection';
const SET_NETWORK_CONNECTION = 'setNetworkConnection';
private function __construct()
{
}
}

View File

@@ -0,0 +1,26 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Remote;
interface ExecuteMethod
{
/**
* @param string $command_name
* @param array $parameters
* @return WebDriverResponse
*/
public function execute($command_name, array $parameters = []);
}

View File

@@ -0,0 +1,29 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Remote;
interface FileDetector
{
/**
* Try to detect whether the given $file is a file or not. Return the path
* of the file. Otherwise, return null.
*
* @param string $file
*
* @return null|string The path of the file.
*/
public function getLocalFile($file);
}

View File

@@ -0,0 +1,343 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Remote;
use BadMethodCallException;
use Facebook\WebDriver\Exception\WebDriverCurlException;
use Facebook\WebDriver\Exception\WebDriverException;
use Facebook\WebDriver\WebDriverCommandExecutor;
use InvalidArgumentException;
/**
* Command executor talking to the standalone server via HTTP.
*/
class HttpCommandExecutor implements WebDriverCommandExecutor
{
const DEFAULT_HTTP_HEADERS = [
'Content-Type: application/json;charset=UTF-8',
'Accept: application/json',
];
/**
* @see https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#command-reference
*/
protected static $commands = [
DriverCommand::ACCEPT_ALERT => ['method' => 'POST', 'url' => '/session/:sessionId/accept_alert'],
DriverCommand::ADD_COOKIE => ['method' => 'POST', 'url' => '/session/:sessionId/cookie'],
DriverCommand::CLEAR_ELEMENT => ['method' => 'POST', 'url' => '/session/:sessionId/element/:id/clear'],
DriverCommand::CLICK_ELEMENT => ['method' => 'POST', 'url' => '/session/:sessionId/element/:id/click'],
DriverCommand::CLOSE => ['method' => 'DELETE', 'url' => '/session/:sessionId/window'],
DriverCommand::DELETE_ALL_COOKIES => ['method' => 'DELETE', 'url' => '/session/:sessionId/cookie'],
DriverCommand::DELETE_COOKIE => ['method' => 'DELETE', 'url' => '/session/:sessionId/cookie/:name'],
DriverCommand::DISMISS_ALERT => ['method' => 'POST', 'url' => '/session/:sessionId/dismiss_alert'],
DriverCommand::ELEMENT_EQUALS => ['method' => 'GET', 'url' => '/session/:sessionId/element/:id/equals/:other'],
DriverCommand::FIND_CHILD_ELEMENT => ['method' => 'POST', 'url' => '/session/:sessionId/element/:id/element'],
DriverCommand::FIND_CHILD_ELEMENTS => ['method' => 'POST', 'url' => '/session/:sessionId/element/:id/elements'],
DriverCommand::EXECUTE_SCRIPT => ['method' => 'POST', 'url' => '/session/:sessionId/execute'],
DriverCommand::EXECUTE_ASYNC_SCRIPT => ['method' => 'POST', 'url' => '/session/:sessionId/execute_async'],
DriverCommand::FIND_ELEMENT => ['method' => 'POST', 'url' => '/session/:sessionId/element'],
DriverCommand::FIND_ELEMENTS => ['method' => 'POST', 'url' => '/session/:sessionId/elements'],
DriverCommand::SWITCH_TO_FRAME => ['method' => 'POST', 'url' => '/session/:sessionId/frame'],
DriverCommand::SWITCH_TO_WINDOW => ['method' => 'POST', 'url' => '/session/:sessionId/window'],
DriverCommand::GET => ['method' => 'POST', 'url' => '/session/:sessionId/url'],
DriverCommand::GET_ACTIVE_ELEMENT => ['method' => 'POST', 'url' => '/session/:sessionId/element/active'],
DriverCommand::GET_ALERT_TEXT => ['method' => 'GET', 'url' => '/session/:sessionId/alert_text'],
DriverCommand::GET_ALL_COOKIES => ['method' => 'GET', 'url' => '/session/:sessionId/cookie'],
DriverCommand::GET_ALL_SESSIONS => ['method' => 'GET', 'url' => '/sessions'],
DriverCommand::GET_AVAILABLE_LOG_TYPES => ['method' => 'GET', 'url' => '/session/:sessionId/log/types'],
DriverCommand::GET_CURRENT_URL => ['method' => 'GET', 'url' => '/session/:sessionId/url'],
DriverCommand::GET_CURRENT_WINDOW_HANDLE => ['method' => 'GET', 'url' => '/session/:sessionId/window_handle'],
DriverCommand::GET_ELEMENT_ATTRIBUTE => [
'method' => 'GET',
'url' => '/session/:sessionId/element/:id/attribute/:name',
],
DriverCommand::GET_ELEMENT_VALUE_OF_CSS_PROPERTY => [
'method' => 'GET',
'url' => '/session/:sessionId/element/:id/css/:propertyName',
],
DriverCommand::GET_ELEMENT_LOCATION => [
'method' => 'GET',
'url' => '/session/:sessionId/element/:id/location',
],
DriverCommand::GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW => [
'method' => 'GET',
'url' => '/session/:sessionId/element/:id/location_in_view',
],
DriverCommand::GET_ELEMENT_SIZE => ['method' => 'GET', 'url' => '/session/:sessionId/element/:id/size'],
DriverCommand::GET_ELEMENT_TAG_NAME => ['method' => 'GET', 'url' => '/session/:sessionId/element/:id/name'],
DriverCommand::GET_ELEMENT_TEXT => ['method' => 'GET', 'url' => '/session/:sessionId/element/:id/text'],
DriverCommand::GET_LOG => ['method' => 'POST', 'url' => '/session/:sessionId/log'],
DriverCommand::GET_PAGE_SOURCE => ['method' => 'GET', 'url' => '/session/:sessionId/source'],
DriverCommand::GET_SCREEN_ORIENTATION => ['method' => 'GET', 'url' => '/session/:sessionId/orientation'],
DriverCommand::GET_CAPABILITIES => ['method' => 'GET', 'url' => '/session/:sessionId'],
DriverCommand::GET_TITLE => ['method' => 'GET', 'url' => '/session/:sessionId/title'],
DriverCommand::GET_WINDOW_HANDLES => ['method' => 'GET', 'url' => '/session/:sessionId/window_handles'],
DriverCommand::GET_WINDOW_POSITION => [
'method' => 'GET',
'url' => '/session/:sessionId/window/:windowHandle/position',
],
DriverCommand::GET_WINDOW_SIZE => ['method' => 'GET', 'url' => '/session/:sessionId/window/:windowHandle/size'],
DriverCommand::GO_BACK => ['method' => 'POST', 'url' => '/session/:sessionId/back'],
DriverCommand::GO_FORWARD => ['method' => 'POST', 'url' => '/session/:sessionId/forward'],
DriverCommand::IS_ELEMENT_DISPLAYED => [
'method' => 'GET',
'url' => '/session/:sessionId/element/:id/displayed',
],
DriverCommand::IS_ELEMENT_ENABLED => ['method' => 'GET', 'url' => '/session/:sessionId/element/:id/enabled'],
DriverCommand::IS_ELEMENT_SELECTED => ['method' => 'GET', 'url' => '/session/:sessionId/element/:id/selected'],
DriverCommand::MAXIMIZE_WINDOW => [
'method' => 'POST',
'url' => '/session/:sessionId/window/:windowHandle/maximize',
],
DriverCommand::MOUSE_DOWN => ['method' => 'POST', 'url' => '/session/:sessionId/buttondown'],
DriverCommand::MOUSE_UP => ['method' => 'POST', 'url' => '/session/:sessionId/buttonup'],
DriverCommand::CLICK => ['method' => 'POST', 'url' => '/session/:sessionId/click'],
DriverCommand::DOUBLE_CLICK => ['method' => 'POST', 'url' => '/session/:sessionId/doubleclick'],
DriverCommand::MOVE_TO => ['method' => 'POST', 'url' => '/session/:sessionId/moveto'],
DriverCommand::NEW_SESSION => ['method' => 'POST', 'url' => '/session'],
DriverCommand::QUIT => ['method' => 'DELETE', 'url' => '/session/:sessionId'],
DriverCommand::REFRESH => ['method' => 'POST', 'url' => '/session/:sessionId/refresh'],
DriverCommand::UPLOAD_FILE => ['method' => 'POST', 'url' => '/session/:sessionId/file'], // undocumented
DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT => ['method' => 'POST', 'url' => '/session/:sessionId/keys'],
DriverCommand::SET_ALERT_VALUE => ['method' => 'POST', 'url' => '/session/:sessionId/alert_text'],
DriverCommand::SEND_KEYS_TO_ELEMENT => ['method' => 'POST', 'url' => '/session/:sessionId/element/:id/value'],
DriverCommand::IMPLICITLY_WAIT => ['method' => 'POST', 'url' => '/session/:sessionId/timeouts/implicit_wait'],
DriverCommand::SET_SCREEN_ORIENTATION => ['method' => 'POST', 'url' => '/session/:sessionId/orientation'],
DriverCommand::SET_TIMEOUT => ['method' => 'POST', 'url' => '/session/:sessionId/timeouts'],
DriverCommand::SET_SCRIPT_TIMEOUT => ['method' => 'POST', 'url' => '/session/:sessionId/timeouts/async_script'],
DriverCommand::SET_WINDOW_POSITION => [
'method' => 'POST',
'url' => '/session/:sessionId/window/:windowHandle/position',
],
DriverCommand::SET_WINDOW_SIZE => [
'method' => 'POST',
'url' => '/session/:sessionId/window/:windowHandle/size',
],
DriverCommand::SUBMIT_ELEMENT => ['method' => 'POST', 'url' => '/session/:sessionId/element/:id/submit'],
DriverCommand::SCREENSHOT => ['method' => 'GET', 'url' => '/session/:sessionId/screenshot'],
DriverCommand::TOUCH_SINGLE_TAP => ['method' => 'POST', 'url' => '/session/:sessionId/touch/click'],
DriverCommand::TOUCH_DOWN => ['method' => 'POST', 'url' => '/session/:sessionId/touch/down'],
DriverCommand::TOUCH_DOUBLE_TAP => ['method' => 'POST', 'url' => '/session/:sessionId/touch/doubleclick'],
DriverCommand::TOUCH_FLICK => ['method' => 'POST', 'url' => '/session/:sessionId/touch/flick'],
DriverCommand::TOUCH_LONG_PRESS => ['method' => 'POST', 'url' => '/session/:sessionId/touch/longclick'],
DriverCommand::TOUCH_MOVE => ['method' => 'POST', 'url' => '/session/:sessionId/touch/move'],
DriverCommand::TOUCH_SCROLL => ['method' => 'POST', 'url' => '/session/:sessionId/touch/scroll'],
DriverCommand::TOUCH_UP => ['method' => 'POST', 'url' => '/session/:sessionId/touch/up'],
];
/**
* @var string
*/
protected $url;
/**
* @var resource
*/
protected $curl;
/**
* @param string $url
* @param string|null $http_proxy
* @param int|null $http_proxy_port
*/
public function __construct($url, $http_proxy = null, $http_proxy_port = null)
{
$this->url = $url;
$this->curl = curl_init();
if (!empty($http_proxy)) {
curl_setopt($this->curl, CURLOPT_PROXY, $http_proxy);
if ($http_proxy_port !== null) {
curl_setopt($this->curl, CURLOPT_PROXYPORT, $http_proxy_port);
}
}
// Get credentials from $url (if any)
$matches = null;
if (preg_match("/^(https?:\/\/)(.*):(.*)@(.*?)/U", $url, $matches)) {
$this->url = $matches[1] . $matches[4];
$auth_creds = $matches[2] . ':' . $matches[3];
curl_setopt($this->curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($this->curl, CURLOPT_USERPWD, $auth_creds);
}
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->curl, CURLOPT_HTTPHEADER, static::DEFAULT_HTTP_HEADERS);
$this->setRequestTimeout(30000);
$this->setConnectionTimeout(30000);
}
/**
* Set timeout for the connect phase
*
* @param int $timeout_in_ms Timeout in milliseconds
* @return HttpCommandExecutor
*/
public function setConnectionTimeout($timeout_in_ms)
{
// There is a PHP bug in some versions which didn't define the constant.
curl_setopt(
$this->curl,
/* CURLOPT_CONNECTTIMEOUT_MS */
156,
$timeout_in_ms
);
return $this;
}
/**
* Set the maximum time of a request
*
* @param int $timeout_in_ms Timeout in milliseconds
* @return HttpCommandExecutor
*/
public function setRequestTimeout($timeout_in_ms)
{
// There is a PHP bug in some versions (at least for PHP 5.3.3) which
// didn't define the constant.
curl_setopt(
$this->curl,
/* CURLOPT_TIMEOUT_MS */
155,
$timeout_in_ms
);
return $this;
}
/**
* @param WebDriverCommand $command
*
* @throws WebDriverException
* @return WebDriverResponse
*/
public function execute(WebDriverCommand $command)
{
if (!isset(self::$commands[$command->getName()])) {
throw new InvalidArgumentException($command->getName() . ' is not a valid command.');
}
$raw = self::$commands[$command->getName()];
$http_method = $raw['method'];
$url = $raw['url'];
$url = str_replace(':sessionId', $command->getSessionID(), $url);
$params = $command->getParameters();
foreach ($params as $name => $value) {
if ($name[0] === ':') {
$url = str_replace($name, $value, $url);
unset($params[$name]);
}
}
if ($params && is_array($params) && $http_method !== 'POST') {
throw new BadMethodCallException(sprintf(
'The http method called for %s is %s but it has to be POST' .
' if you want to pass the JSON params %s',
$url,
$http_method,
json_encode($params)
));
}
curl_setopt($this->curl, CURLOPT_URL, $this->url . $url);
// https://github.com/facebook/php-webdriver/issues/173
if ($command->getName() === DriverCommand::NEW_SESSION) {
curl_setopt($this->curl, CURLOPT_POST, 1);
} else {
curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $http_method);
}
if (in_array($http_method, ['POST', 'PUT'])) {
// Disable sending 'Expect: 100-Continue' header, as it is causing issues with eg. squid proxy
// https://tools.ietf.org/html/rfc7231#section-5.1.1
curl_setopt($this->curl, CURLOPT_HTTPHEADER, array_merge(static::DEFAULT_HTTP_HEADERS, ['Expect:']));
} else {
curl_setopt($this->curl, CURLOPT_HTTPHEADER, static::DEFAULT_HTTP_HEADERS);
}
$encoded_params = null;
if ($http_method === 'POST' && $params && is_array($params)) {
$encoded_params = json_encode($params);
}
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $encoded_params);
$raw_results = trim(curl_exec($this->curl));
if ($error = curl_error($this->curl)) {
$msg = sprintf(
'Curl error thrown for http %s to %s',
$http_method,
$url
);
if ($params && is_array($params)) {
$msg .= sprintf(' with params: %s', json_encode($params));
}
throw new WebDriverCurlException($msg . "\n\n" . $error);
}
$results = json_decode($raw_results, true);
if ($results === null && json_last_error() !== JSON_ERROR_NONE) {
throw new WebDriverException(
sprintf(
"JSON decoding of remote response failed.\n" .
"Error code: %d\n" .
"The response: '%s'\n",
json_last_error(),
$raw_results
)
);
}
$value = null;
if (is_array($results) && array_key_exists('value', $results)) {
$value = $results['value'];
}
$message = null;
if (is_array($value) && array_key_exists('message', $value)) {
$message = $value['message'];
}
$sessionId = null;
if (is_array($results) && array_key_exists('sessionId', $results)) {
$sessionId = $results['sessionId'];
}
$status = isset($results['status']) ? $results['status'] : 0;
if ($status != 0) {
WebDriverException::throwException($status, $message, $results);
}
$response = new WebDriverResponse($sessionId);
return $response
->setStatus($status)
->setValue($value);
}
/**
* @return string
*/
public function getAddressOfRemoteServer()
{
return $this->url;
}
}

View File

@@ -0,0 +1,33 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Remote;
class LocalFileDetector implements FileDetector
{
/**
* @param string $file
*
* @return null|string
*/
public function getLocalFile($file)
{
if (is_file($file)) {
return $file;
}
return null;
}
}

View File

@@ -0,0 +1,42 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Remote;
class RemoteExecuteMethod implements ExecuteMethod
{
/**
* @var RemoteWebDriver
*/
private $driver;
/**
* @param RemoteWebDriver $driver
*/
public function __construct(RemoteWebDriver $driver)
{
$this->driver = $driver;
}
/**
* @param string $command_name
* @param array $parameters
* @return mixed
*/
public function execute($command_name, array $parameters = [])
{
return $this->driver->execute($command_name, $parameters);
}
}

View File

@@ -0,0 +1,84 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Remote;
use Facebook\WebDriver\WebDriverKeyboard;
use Facebook\WebDriver\WebDriverKeys;
/**
* Execute keyboard commands for RemoteWebDriver.
*/
class RemoteKeyboard implements WebDriverKeyboard
{
/**
* @var RemoteExecuteMethod
*/
private $executor;
/**
* @param RemoteExecuteMethod $executor
*/
public function __construct(RemoteExecuteMethod $executor)
{
$this->executor = $executor;
}
/**
* Send keys to active element
* @param string|array $keys
* @return $this
*/
public function sendKeys($keys)
{
$this->executor->execute(DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT, [
'value' => WebDriverKeys::encode($keys),
]);
return $this;
}
/**
* Press a modifier key
*
* @see WebDriverKeys
* @param string $key
* @return $this
*/
public function pressKey($key)
{
$this->executor->execute(DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT, [
'value' => [(string) $key],
]);
return $this;
}
/**
* Release a modifier key
*
* @see WebDriverKeys
* @param string $key
* @return $this
*/
public function releaseKey($key)
{
$this->executor->execute(DriverCommand::SEND_KEYS_TO_ACTIVE_ELEMENT, [
'value' => [(string) $key],
]);
return $this;
}
}

View File

@@ -0,0 +1,144 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Remote;
use Facebook\WebDriver\Interactions\Internal\WebDriverCoordinates;
use Facebook\WebDriver\WebDriverMouse;
/**
* Execute mouse commands for RemoteWebDriver.
*/
class RemoteMouse implements WebDriverMouse
{
/**
* @var RemoteExecuteMethod
*/
private $executor;
/**
* @param RemoteExecuteMethod $executor
*/
public function __construct(RemoteExecuteMethod $executor)
{
$this->executor = $executor;
}
/**
* @param null|WebDriverCoordinates $where
*
* @return RemoteMouse
*/
public function click(WebDriverCoordinates $where = null)
{
$this->moveIfNeeded($where);
$this->executor->execute(DriverCommand::CLICK, [
'button' => 0,
]);
return $this;
}
/**
* @param WebDriverCoordinates $where
*
* @return RemoteMouse
*/
public function contextClick(WebDriverCoordinates $where = null)
{
$this->moveIfNeeded($where);
$this->executor->execute(DriverCommand::CLICK, [
'button' => 2,
]);
return $this;
}
/**
* @param WebDriverCoordinates $where
*
* @return RemoteMouse
*/
public function doubleClick(WebDriverCoordinates $where = null)
{
$this->moveIfNeeded($where);
$this->executor->execute(DriverCommand::DOUBLE_CLICK);
return $this;
}
/**
* @param WebDriverCoordinates $where
*
* @return RemoteMouse
*/
public function mouseDown(WebDriverCoordinates $where = null)
{
$this->moveIfNeeded($where);
$this->executor->execute(DriverCommand::MOUSE_DOWN);
return $this;
}
/**
* @param WebDriverCoordinates $where
* @param int|null $x_offset
* @param int|null $y_offset
*
* @return RemoteMouse
*/
public function mouseMove(
WebDriverCoordinates $where = null,
$x_offset = null,
$y_offset = null
) {
$params = [];
if ($where !== null) {
$params['element'] = $where->getAuxiliary();
}
if ($x_offset !== null) {
$params['xoffset'] = $x_offset;
}
if ($y_offset !== null) {
$params['yoffset'] = $y_offset;
}
$this->executor->execute(DriverCommand::MOVE_TO, $params);
return $this;
}
/**
* @param WebDriverCoordinates $where
*
* @return RemoteMouse
*/
public function mouseUp(WebDriverCoordinates $where = null)
{
$this->moveIfNeeded($where);
$this->executor->execute(DriverCommand::MOUSE_UP);
return $this;
}
/**
* @param WebDriverCoordinates $where
*/
protected function moveIfNeeded(WebDriverCoordinates $where = null)
{
if ($where) {
$this->mouseMove($where);
}
}
}

View File

@@ -0,0 +1,117 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Remote;
use Facebook\WebDriver\WebDriver;
use Facebook\WebDriver\WebDriverAlert;
use Facebook\WebDriver\WebDriverElement;
use Facebook\WebDriver\WebDriverTargetLocator;
/**
* Used to locate a given frame or window for RemoteWebDriver.
*/
class RemoteTargetLocator implements WebDriverTargetLocator
{
/**
* @var ExecuteMethod
*/
protected $executor;
/**
* @var WebDriver
*/
protected $driver;
public function __construct($executor, $driver)
{
$this->executor = $executor;
$this->driver = $driver;
}
/**
* Switch to the main document if the page contains iframes. Otherwise, switch
* to the first frame on the page.
*
* @return WebDriver The driver focused on the top window or the first frame.
*/
public function defaultContent()
{
$params = ['id' => null];
$this->executor->execute(DriverCommand::SWITCH_TO_FRAME, $params);
return $this->driver;
}
/**
* Switch to the iframe by its id or name.
*
* @param WebDriverElement|string $frame The WebDriverElement,
* the id or the name of the frame.
* @return WebDriver The driver focused on the given frame.
*/
public function frame($frame)
{
if ($frame instanceof WebDriverElement) {
$id = ['ELEMENT' => $frame->getID()];
} else {
$id = (string) $frame;
}
$params = ['id' => $id];
$this->executor->execute(DriverCommand::SWITCH_TO_FRAME, $params);
return $this->driver;
}
/**
* Switch the focus to another window by its handle.
*
* @param string $handle The handle of the window to be focused on.
* @return WebDriver The driver focused on the given window.
* @see WebDriver::getWindowHandles
*/
public function window($handle)
{
$params = ['name' => (string) $handle];
$this->executor->execute(DriverCommand::SWITCH_TO_WINDOW, $params);
return $this->driver;
}
/**
* Switch to the currently active modal dialog for this particular driver
* instance.
*
* @return WebDriverAlert
*/
public function alert()
{
return new WebDriverAlert($this->executor);
}
/**
* Switches to the element that currently has focus within the document
* currently "switched to", or the body element if this cannot be detected.
*
* @return RemoteWebElement
*/
public function activeElement()
{
$response = $this->driver->execute(DriverCommand::GET_ACTIVE_ELEMENT, []);
$method = new RemoteExecuteMethod($this->driver);
return new RemoteWebElement($method, $response['ELEMENT']);
}
}

View File

@@ -0,0 +1,201 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Remote;
use Facebook\WebDriver\Interactions\Touch\WebDriverTouchScreen;
use Facebook\WebDriver\WebDriverElement;
/**
* Execute touch commands for RemoteWebDriver.
*/
class RemoteTouchScreen implements WebDriverTouchScreen
{
/**
* @var RemoteExecuteMethod
*/
private $executor;
/**
* @param RemoteExecuteMethod $executor
*/
public function __construct(RemoteExecuteMethod $executor)
{
$this->executor = $executor;
}
/**
* @param WebDriverElement $element
*
* @return RemoteTouchScreen The instance.
*/
public function tap(WebDriverElement $element)
{
$this->executor->execute(
DriverCommand::TOUCH_SINGLE_TAP,
['element' => $element->getID()]
);
return $this;
}
/**
* @param WebDriverElement $element
*
* @return RemoteTouchScreen The instance.
*/
public function doubleTap(WebDriverElement $element)
{
$this->executor->execute(
DriverCommand::TOUCH_DOUBLE_TAP,
['element' => $element->getID()]
);
return $this;
}
/**
* @param int $x
* @param int $y
*
* @return RemoteTouchScreen The instance.
*/
public function down($x, $y)
{
$this->executor->execute(DriverCommand::TOUCH_DOWN, [
'x' => $x,
'y' => $y,
]);
return $this;
}
/**
* @param int $xspeed
* @param int $yspeed
*
* @return RemoteTouchScreen The instance.
*/
public function flick($xspeed, $yspeed)
{
$this->executor->execute(DriverCommand::TOUCH_FLICK, [
'xspeed' => $xspeed,
'yspeed' => $yspeed,
]);
return $this;
}
/**
* @param WebDriverElement $element
* @param int $xoffset
* @param int $yoffset
* @param int $speed
*
* @return RemoteTouchScreen The instance.
*/
public function flickFromElement(WebDriverElement $element, $xoffset, $yoffset, $speed)
{
$this->executor->execute(DriverCommand::TOUCH_FLICK, [
'xoffset' => $xoffset,
'yoffset' => $yoffset,
'element' => $element->getID(),
'speed' => $speed,
]);
return $this;
}
/**
* @param WebDriverElement $element
*
* @return RemoteTouchScreen The instance.
*/
public function longPress(WebDriverElement $element)
{
$this->executor->execute(
DriverCommand::TOUCH_LONG_PRESS,
['element' => $element->getID()]
);
return $this;
}
/**
* @param int $x
* @param int $y
*
* @return RemoteTouchScreen The instance.
*/
public function move($x, $y)
{
$this->executor->execute(DriverCommand::TOUCH_MOVE, [
'x' => $x,
'y' => $y,
]);
return $this;
}
/**
* @param int $xoffset
* @param int $yoffset
*
* @return RemoteTouchScreen The instance.
*/
public function scroll($xoffset, $yoffset)
{
$this->executor->execute(DriverCommand::TOUCH_SCROLL, [
'xoffset' => $xoffset,
'yoffset' => $yoffset,
]);
return $this;
}
/**
* @param WebDriverElement $element
* @param int $xoffset
* @param int $yoffset
*
* @return RemoteTouchScreen The instance.
*/
public function scrollFromElement(WebDriverElement $element, $xoffset, $yoffset)
{
$this->executor->execute(DriverCommand::TOUCH_SCROLL, [
'element' => $element->getID(),
'xoffset' => $xoffset,
'yoffset' => $yoffset,
]);
return $this;
}
/**
* @param int $x
* @param int $y
*
* @return RemoteTouchScreen The instance.
*/
public function up($x, $y)
{
$this->executor->execute(DriverCommand::TOUCH_UP, [
'x' => $x,
'y' => $y,
]);
return $this;
}
}

View File

@@ -0,0 +1,620 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Remote;
use Facebook\WebDriver\Interactions\WebDriverActions;
use Facebook\WebDriver\JavaScriptExecutor;
use Facebook\WebDriver\WebDriver;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverCapabilities;
use Facebook\WebDriver\WebDriverCommandExecutor;
use Facebook\WebDriver\WebDriverElement;
use Facebook\WebDriver\WebDriverHasInputDevices;
use Facebook\WebDriver\WebDriverNavigation;
use Facebook\WebDriver\WebDriverOptions;
use Facebook\WebDriver\WebDriverWait;
class RemoteWebDriver implements WebDriver, JavaScriptExecutor, WebDriverHasInputDevices
{
/**
* @var HttpCommandExecutor|null
*/
protected $executor;
/**
* @var WebDriverCapabilities
*/
protected $capabilities;
/**
* @var string
*/
protected $sessionID;
/**
* @var RemoteMouse
*/
protected $mouse;
/**
* @var RemoteKeyboard
*/
protected $keyboard;
/**
* @var RemoteTouchScreen
*/
protected $touch;
/**
* @var RemoteExecuteMethod
*/
protected $executeMethod;
/**
* @param HttpCommandExecutor $commandExecutor
* @param string $sessionId
* @param WebDriverCapabilities|null $capabilities
*/
protected function __construct(
HttpCommandExecutor $commandExecutor,
$sessionId,
WebDriverCapabilities $capabilities = null
) {
$this->executor = $commandExecutor;
$this->sessionID = $sessionId;
if ($capabilities !== null) {
$this->capabilities = $capabilities;
}
}
/**
* Construct the RemoteWebDriver by a desired capabilities.
*
* @param string $selenium_server_url The url of the remote Selenium WebDriver server
* @param DesiredCapabilities|array $desired_capabilities The desired capabilities
* @param int|null $connection_timeout_in_ms Set timeout for the connect phase to remote Selenium WebDriver server
* @param int|null $request_timeout_in_ms Set the maximum time of a request to remote Selenium WebDriver server
* @param string|null $http_proxy The proxy to tunnel requests to the remote Selenium WebDriver through
* @param int|null $http_proxy_port The proxy port to tunnel requests to the remote Selenium WebDriver through
* @param DesiredCapabilities $required_capabilities The required capabilities
* @return static
*/
public static function create(
$selenium_server_url = 'http://localhost:4444/wd/hub',
$desired_capabilities = null,
$connection_timeout_in_ms = null,
$request_timeout_in_ms = null,
$http_proxy = null,
$http_proxy_port = null,
DesiredCapabilities $required_capabilities = null
) {
$selenium_server_url = preg_replace('#/+$#', '', $selenium_server_url);
$desired_capabilities = self::castToDesiredCapabilitiesObject($desired_capabilities);
$executor = new HttpCommandExecutor($selenium_server_url, $http_proxy, $http_proxy_port);
if ($connection_timeout_in_ms !== null) {
$executor->setConnectionTimeout($connection_timeout_in_ms);
}
if ($request_timeout_in_ms !== null) {
$executor->setRequestTimeout($request_timeout_in_ms);
}
if ($required_capabilities !== null) {
// TODO: Selenium (as of v3.0.1) does accept requiredCapabilities only as a property of desiredCapabilities.
// This will probably change in future with the W3C WebDriver spec, but is the only way how to pass these
// values now.
$desired_capabilities->setCapability('requiredCapabilities', $required_capabilities->toArray());
}
$command = new WebDriverCommand(
null,
DriverCommand::NEW_SESSION,
['desiredCapabilities' => $desired_capabilities->toArray()]
);
$response = $executor->execute($command);
$returnedCapabilities = new DesiredCapabilities($response->getValue());
$driver = new static($executor, $response->getSessionID(), $returnedCapabilities);
return $driver;
}
/**
* [Experimental] Construct the RemoteWebDriver by an existing session.
*
* This constructor can boost the performance a lot by reusing the same browser for the whole test suite.
* You cannot pass the desired capabilities because the session was created before.
*
* @param string $selenium_server_url The url of the remote Selenium WebDriver server
* @param string $session_id The existing session id
* @param int|null $connection_timeout_in_ms Set timeout for the connect phase to remote Selenium WebDriver server
* @param int|null $request_timeout_in_ms Set the maximum time of a request to remote Selenium WebDriver server
* @return static
*/
public static function createBySessionID(
$session_id,
$selenium_server_url = 'http://localhost:4444/wd/hub',
$connection_timeout_in_ms = null,
$request_timeout_in_ms = null
) {
$executor = new HttpCommandExecutor($selenium_server_url);
if ($connection_timeout_in_ms !== null) {
$executor->setConnectionTimeout($connection_timeout_in_ms);
}
if ($request_timeout_in_ms !== null) {
$executor->setRequestTimeout($request_timeout_in_ms);
}
return new static($executor, $session_id);
}
/**
* Close the current window.
*
* @return RemoteWebDriver The current instance.
*/
public function close()
{
$this->execute(DriverCommand::CLOSE, []);
return $this;
}
/**
* Find the first WebDriverElement using the given mechanism.
*
* @param WebDriverBy $by
* @return RemoteWebElement NoSuchElementException is thrown in HttpCommandExecutor if no element is found.
* @see WebDriverBy
*/
public function findElement(WebDriverBy $by)
{
$params = ['using' => $by->getMechanism(), 'value' => $by->getValue()];
$raw_element = $this->execute(
DriverCommand::FIND_ELEMENT,
$params
);
return $this->newElement($raw_element['ELEMENT']);
}
/**
* Find all WebDriverElements within the current page using the given mechanism.
*
* @param WebDriverBy $by
* @return RemoteWebElement[] A list of all WebDriverElements, or an empty array if nothing matches
* @see WebDriverBy
*/
public function findElements(WebDriverBy $by)
{
$params = ['using' => $by->getMechanism(), 'value' => $by->getValue()];
$raw_elements = $this->execute(
DriverCommand::FIND_ELEMENTS,
$params
);
$elements = [];
foreach ($raw_elements as $raw_element) {
$elements[] = $this->newElement($raw_element['ELEMENT']);
}
return $elements;
}
/**
* Load a new web page in the current browser window.
*
* @param string $url
*
* @return RemoteWebDriver The current instance.
*/
public function get($url)
{
$params = ['url' => (string) $url];
$this->execute(DriverCommand::GET, $params);
return $this;
}
/**
* Get a string representing the current URL that the browser is looking at.
*
* @return string The current URL.
*/
public function getCurrentURL()
{
return $this->execute(DriverCommand::GET_CURRENT_URL);
}
/**
* Get the source of the last loaded page.
*
* @return string The current page source.
*/
public function getPageSource()
{
return $this->execute(DriverCommand::GET_PAGE_SOURCE);
}
/**
* Get the title of the current page.
*
* @return string The title of the current page.
*/
public function getTitle()
{
return $this->execute(DriverCommand::GET_TITLE);
}
/**
* Return an opaque handle to this window that uniquely identifies it within this driver instance.
*
* @return string The current window handle.
*/
public function getWindowHandle()
{
return $this->execute(
DriverCommand::GET_CURRENT_WINDOW_HANDLE,
[]
);
}
/**
* Get all window handles available to the current session.
*
* @return array An array of string containing all available window handles.
*/
public function getWindowHandles()
{
return $this->execute(DriverCommand::GET_WINDOW_HANDLES, []);
}
/**
* Quits this driver, closing every associated window.
*/
public function quit()
{
$this->execute(DriverCommand::QUIT);
$this->executor = null;
}
/**
* Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame.
* The executed script is assumed to be synchronous and the result of evaluating the script will be returned.
*
* @param string $script The script to inject.
* @param array $arguments The arguments of the script.
* @return mixed The return value of the script.
*/
public function executeScript($script, array $arguments = [])
{
$params = [
'script' => $script,
'args' => $this->prepareScriptArguments($arguments),
];
return $this->execute(DriverCommand::EXECUTE_SCRIPT, $params);
}
/**
* Inject a snippet of JavaScript into the page for asynchronous execution in the context of the currently selected
* frame.
*
* The driver will pass a callback as the last argument to the snippet, and block until the callback is invoked.
*
* You may need to define script timeout using `setScriptTimeout()` method of `WebDriverTimeouts` first.
*
* @param string $script The script to inject.
* @param array $arguments The arguments of the script.
* @return mixed The value passed by the script to the callback.
*/
public function executeAsyncScript($script, array $arguments = [])
{
$params = [
'script' => $script,
'args' => $this->prepareScriptArguments($arguments),
];
return $this->execute(
DriverCommand::EXECUTE_ASYNC_SCRIPT,
$params
);
}
/**
* Take a screenshot of the current page.
*
* @param string $save_as The path of the screenshot to be saved.
* @return string The screenshot in PNG format.
*/
public function takeScreenshot($save_as = null)
{
$screenshot = base64_decode(
$this->execute(DriverCommand::SCREENSHOT)
);
if ($save_as) {
file_put_contents($save_as, $screenshot);
}
return $screenshot;
}
/**
* Construct a new WebDriverWait by the current WebDriver instance.
* Sample usage:
*
* ```
* $driver->wait(20, 1000)->until(
* WebDriverExpectedCondition::titleIs('WebDriver Page')
* );
* ```
* @param int $timeout_in_second
* @param int $interval_in_millisecond
*
* @return WebDriverWait
*/
public function wait($timeout_in_second = 30, $interval_in_millisecond = 250)
{
return new WebDriverWait(
$this,
$timeout_in_second,
$interval_in_millisecond
);
}
/**
* An abstraction for managing stuff you would do in a browser menu. For example, adding and deleting cookies.
*
* @return WebDriverOptions
*/
public function manage()
{
return new WebDriverOptions($this->getExecuteMethod());
}
/**
* An abstraction allowing the driver to access the browser's history and to navigate to a given URL.
*
* @return WebDriverNavigation
* @see WebDriverNavigation
*/
public function navigate()
{
return new WebDriverNavigation($this->getExecuteMethod());
}
/**
* Switch to a different window or frame.
*
* @return RemoteTargetLocator
* @see RemoteTargetLocator
*/
public function switchTo()
{
return new RemoteTargetLocator($this->getExecuteMethod(), $this);
}
/**
* @return RemoteMouse
*/
public function getMouse()
{
if (!$this->mouse) {
$this->mouse = new RemoteMouse($this->getExecuteMethod());
}
return $this->mouse;
}
/**
* @return RemoteKeyboard
*/
public function getKeyboard()
{
if (!$this->keyboard) {
$this->keyboard = new RemoteKeyboard($this->getExecuteMethod());
}
return $this->keyboard;
}
/**
* @return RemoteTouchScreen
*/
public function getTouch()
{
if (!$this->touch) {
$this->touch = new RemoteTouchScreen($this->getExecuteMethod());
}
return $this->touch;
}
/**
* Construct a new action builder.
*
* @return WebDriverActions
*/
public function action()
{
return new WebDriverActions($this);
}
/**
* Set the command executor of this RemoteWebdriver
*
* @deprecated To be removed in the future. Executor should be passed in the constructor.
* @internal
* @codeCoverageIgnore
* @param WebDriverCommandExecutor $executor Despite the typehint, it have be an instance of HttpCommandExecutor.
* @return RemoteWebDriver
*/
public function setCommandExecutor(WebDriverCommandExecutor $executor)
{
$this->executor = $executor;
return $this;
}
/**
* Get the command executor of this RemoteWebdriver
*
* @return HttpCommandExecutor
*/
public function getCommandExecutor()
{
return $this->executor;
}
/**
* Set the session id of the RemoteWebDriver.
*
* @deprecated To be removed in the future. Session ID should be passed in the constructor.
* @internal
* @codeCoverageIgnore
* @param string $session_id
* @return RemoteWebDriver
*/
public function setSessionID($session_id)
{
$this->sessionID = $session_id;
return $this;
}
/**
* Get current selenium sessionID
*
* @return string
*/
public function getSessionID()
{
return $this->sessionID;
}
/**
* Get capabilities of the RemoteWebDriver.
*
* @return WebDriverCapabilities
*/
public function getCapabilities()
{
return $this->capabilities;
}
/**
* Returns a list of the currently active sessions.
*
* @param string $selenium_server_url The url of the remote Selenium WebDriver server
* @param int $timeout_in_ms
* @return array
*/
public static function getAllSessions($selenium_server_url = 'http://localhost:4444/wd/hub', $timeout_in_ms = 30000)
{
$executor = new HttpCommandExecutor($selenium_server_url);
$executor->setConnectionTimeout($timeout_in_ms);
$command = new WebDriverCommand(
null,
DriverCommand::GET_ALL_SESSIONS,
[]
);
return $executor->execute($command)->getValue();
}
public function execute($command_name, $params = [])
{
$command = new WebDriverCommand(
$this->sessionID,
$command_name,
$params
);
if ($this->executor) {
$response = $this->executor->execute($command);
return $response->getValue();
}
return null;
}
/**
* Prepare arguments for JavaScript injection
*
* @param array $arguments
* @return array
*/
protected function prepareScriptArguments(array $arguments)
{
$args = [];
foreach ($arguments as $key => $value) {
if ($value instanceof WebDriverElement) {
$args[$key] = ['ELEMENT' => $value->getID()];
} else {
if (is_array($value)) {
$value = $this->prepareScriptArguments($value);
}
$args[$key] = $value;
}
}
return $args;
}
/**
* @return RemoteExecuteMethod
*/
protected function getExecuteMethod()
{
if (!$this->executeMethod) {
$this->executeMethod = new RemoteExecuteMethod($this);
}
return $this->executeMethod;
}
/**
* Return the WebDriverElement with the given id.
*
* @param string $id The id of the element to be created.
* @return RemoteWebElement
*/
protected function newElement($id)
{
return new RemoteWebElement($this->getExecuteMethod(), $id);
}
/**
* Cast legacy types (array or null) to DesiredCapabilities object. To be removed in future when instance of
* DesiredCapabilities will be required.
*
* @param array|DesiredCapabilities|null $desired_capabilities
* @return DesiredCapabilities
*/
protected static function castToDesiredCapabilitiesObject($desired_capabilities = null)
{
if ($desired_capabilities === null) {
return new DesiredCapabilities();
}
if (is_array($desired_capabilities)) {
return new DesiredCapabilities($desired_capabilities);
}
return $desired_capabilities;
}
}

View File

@@ -0,0 +1,453 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Remote;
use Facebook\WebDriver\Exception\WebDriverException;
use Facebook\WebDriver\Interactions\Internal\WebDriverCoordinates;
use Facebook\WebDriver\Internal\WebDriverLocatable;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverDimension;
use Facebook\WebDriver\WebDriverElement;
use Facebook\WebDriver\WebDriverKeys;
use Facebook\WebDriver\WebDriverPoint;
use ZipArchive;
/**
* Represents an HTML element.
*/
class RemoteWebElement implements WebDriverElement, WebDriverLocatable
{
/**
* @var RemoteExecuteMethod
*/
protected $executor;
/**
* @var string
*/
protected $id;
/**
* @var UselessFileDetector
*/
protected $fileDetector;
/**
* @param RemoteExecuteMethod $executor
* @param string $id
*/
public function __construct(RemoteExecuteMethod $executor, $id)
{
$this->executor = $executor;
$this->id = $id;
$this->fileDetector = new UselessFileDetector();
}
/**
* If this element is a TEXTAREA or text INPUT element, this will clear the value.
*
* @return RemoteWebElement The current instance.
*/
public function clear()
{
$this->executor->execute(
DriverCommand::CLEAR_ELEMENT,
[':id' => $this->id]
);
return $this;
}
/**
* Click this element.
*
* @return RemoteWebElement The current instance.
*/
public function click()
{
$this->executor->execute(
DriverCommand::CLICK_ELEMENT,
[':id' => $this->id]
);
return $this;
}
/**
* Find the first WebDriverElement within this element using the given mechanism.
*
* @param WebDriverBy $by
* @return RemoteWebElement NoSuchElementException is thrown in
* HttpCommandExecutor if no element is found.
* @see WebDriverBy
*/
public function findElement(WebDriverBy $by)
{
$params = [
'using' => $by->getMechanism(),
'value' => $by->getValue(),
':id' => $this->id,
];
$raw_element = $this->executor->execute(
DriverCommand::FIND_CHILD_ELEMENT,
$params
);
return $this->newElement($raw_element['ELEMENT']);
}
/**
* Find all WebDriverElements within this element using the given mechanism.
*
* @param WebDriverBy $by
* @return RemoteWebElement[] A list of all WebDriverElements, or an empty
* array if nothing matches
* @see WebDriverBy
*/
public function findElements(WebDriverBy $by)
{
$params = [
'using' => $by->getMechanism(),
'value' => $by->getValue(),
':id' => $this->id,
];
$raw_elements = $this->executor->execute(
DriverCommand::FIND_CHILD_ELEMENTS,
$params
);
$elements = [];
foreach ($raw_elements as $raw_element) {
$elements[] = $this->newElement($raw_element['ELEMENT']);
}
return $elements;
}
/**
* Get the value of a the given attribute of the element.
*
* @param string $attribute_name The name of the attribute.
* @return string|null The value of the attribute.
*/
public function getAttribute($attribute_name)
{
$params = [
':name' => $attribute_name,
':id' => $this->id,
];
return $this->executor->execute(
DriverCommand::GET_ELEMENT_ATTRIBUTE,
$params
);
}
/**
* Get the value of a given CSS property.
*
* @param string $css_property_name The name of the CSS property.
* @return string The value of the CSS property.
*/
public function getCSSValue($css_property_name)
{
$params = [
':propertyName' => $css_property_name,
':id' => $this->id,
];
return $this->executor->execute(
DriverCommand::GET_ELEMENT_VALUE_OF_CSS_PROPERTY,
$params
);
}
/**
* Get the location of element relative to the top-left corner of the page.
*
* @return WebDriverPoint The location of the element.
*/
public function getLocation()
{
$location = $this->executor->execute(
DriverCommand::GET_ELEMENT_LOCATION,
[':id' => $this->id]
);
return new WebDriverPoint($location['x'], $location['y']);
}
/**
* Try scrolling the element into the view port and return the location of
* element relative to the top-left corner of the page afterwards.
*
* @return WebDriverPoint The location of the element.
*/
public function getLocationOnScreenOnceScrolledIntoView()
{
$location = $this->executor->execute(
DriverCommand::GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW,
[':id' => $this->id]
);
return new WebDriverPoint($location['x'], $location['y']);
}
/**
* @return WebDriverCoordinates
*/
public function getCoordinates()
{
$element = $this;
$on_screen = null; // planned but not yet implemented
$in_view_port = function () use ($element) {
return $element->getLocationOnScreenOnceScrolledIntoView();
};
$on_page = function () use ($element) {
return $element->getLocation();
};
$auxiliary = $this->getID();
return new WebDriverCoordinates(
$on_screen,
$in_view_port,
$on_page,
$auxiliary
);
}
/**
* Get the size of element.
*
* @return WebDriverDimension The dimension of the element.
*/
public function getSize()
{
$size = $this->executor->execute(
DriverCommand::GET_ELEMENT_SIZE,
[':id' => $this->id]
);
return new WebDriverDimension($size['width'], $size['height']);
}
/**
* Get the (lowercase) tag name of this element.
*
* @return string The tag name.
*/
public function getTagName()
{
// Force tag name to be lowercase as expected by JsonWire protocol for Opera driver
// until this issue is not resolved :
// https://github.com/operasoftware/operadriver/issues/102
// Remove it when fixed to be consistent with the protocol.
return mb_strtolower($this->executor->execute(
DriverCommand::GET_ELEMENT_TAG_NAME,
[':id' => $this->id]
));
}
/**
* Get the visible (i.e. not hidden by CSS) innerText of this element,
* including sub-elements, without any leading or trailing whitespace.
*
* @return string The visible innerText of this element.
*/
public function getText()
{
return $this->executor->execute(
DriverCommand::GET_ELEMENT_TEXT,
[':id' => $this->id]
);
}
/**
* Is this element displayed or not? This method avoids the problem of having
* to parse an element's "style" attribute.
*
* @return bool
*/
public function isDisplayed()
{
return $this->executor->execute(
DriverCommand::IS_ELEMENT_DISPLAYED,
[':id' => $this->id]
);
}
/**
* Is the element currently enabled or not? This will generally return true
* for everything but disabled input elements.
*
* @return bool
*/
public function isEnabled()
{
return $this->executor->execute(
DriverCommand::IS_ELEMENT_ENABLED,
[':id' => $this->id]
);
}
/**
* Determine whether or not this element is selected or not.
*
* @return bool
*/
public function isSelected()
{
return $this->executor->execute(
DriverCommand::IS_ELEMENT_SELECTED,
[':id' => $this->id]
);
}
/**
* Simulate typing into an element, which may set its value.
*
* @param mixed $value The data to be typed.
* @return RemoteWebElement The current instance.
*/
public function sendKeys($value)
{
$local_file = $this->fileDetector->getLocalFile($value);
if ($local_file === null) {
$params = [
'value' => WebDriverKeys::encode($value),
':id' => $this->id,
];
$this->executor->execute(DriverCommand::SEND_KEYS_TO_ELEMENT, $params);
} else {
$remote_path = $this->upload($local_file);
$params = [
'value' => WebDriverKeys::encode($remote_path),
':id' => $this->id,
];
$this->executor->execute(DriverCommand::SEND_KEYS_TO_ELEMENT, $params);
}
return $this;
}
/**
* Set the fileDetector in order to let the RemoteWebElement to know that
* you are going to upload a file.
*
* Basically, if you want WebDriver trying to send a file, set the fileDetector
* to be LocalFileDetector. Otherwise, keep it UselessFileDetector.
*
* eg. `$element->setFileDetector(new LocalFileDetector);`
*
* @param FileDetector $detector
* @return RemoteWebElement
* @see FileDetector
* @see LocalFileDetector
* @see UselessFileDetector
*/
public function setFileDetector(FileDetector $detector)
{
$this->fileDetector = $detector;
return $this;
}
/**
* If this current element is a form, or an element within a form, then this will be submitted to the remote server.
*
* @return RemoteWebElement The current instance.
*/
public function submit()
{
$this->executor->execute(
DriverCommand::SUBMIT_ELEMENT,
[':id' => $this->id]
);
return $this;
}
/**
* Get the opaque ID of the element.
*
* @return string The opaque ID.
*/
public function getID()
{
return $this->id;
}
/**
* Test if two element IDs refer to the same DOM element.
*
* @param WebDriverElement $other
* @return bool
*/
public function equals(WebDriverElement $other)
{
return $this->executor->execute(DriverCommand::ELEMENT_EQUALS, [
':id' => $this->id,
':other' => $other->getID(),
]);
}
/**
* Return the WebDriverElement with $id
*
* @param string $id
*
* @return static
*/
protected function newElement($id)
{
return new static($this->executor, $id);
}
/**
* Upload a local file to the server
*
* @param string $local_file
*
* @throws WebDriverException
* @return string The remote path of the file.
*/
protected function upload($local_file)
{
if (!is_file($local_file)) {
throw new WebDriverException('You may only upload files: ' . $local_file);
}
// Create a temporary file in the system temp directory.
$temp_zip = tempnam(sys_get_temp_dir(), 'WebDriverZip');
$zip = new ZipArchive();
if ($zip->open($temp_zip, ZipArchive::CREATE) !== true) {
return false;
}
$info = pathinfo($local_file);
$file_name = $info['basename'];
$zip->addFile($local_file, $file_name);
$zip->close();
$params = [
'file' => base64_encode(file_get_contents($temp_zip)),
];
$remote_path = $this->executor->execute(
DriverCommand::UPLOAD_FILE,
$params
);
unlink($temp_zip);
return $remote_path;
}
}

View File

@@ -0,0 +1,68 @@
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Facebook\WebDriver\Remote\Service;
use Facebook\WebDriver\Exception\WebDriverException;
use Facebook\WebDriver\Remote\DriverCommand;
use Facebook\WebDriver\Remote\HttpCommandExecutor;
use Facebook\WebDriver\Remote\WebDriverCommand;
use Facebook\WebDriver\Remote\WebDriverResponse;
/**
* A HttpCommandExecutor that talks to a local driver service instead of
* a remote server.
*/
class DriverCommandExecutor extends HttpCommandExecutor
{
/**
* @var DriverService
*/
private $service;
public function __construct(DriverService $service)
{
parent::__construct($service->getURL());
$this->service = $service;
}
/**
* @param WebDriverCommand $command
*
* @throws WebDriverException
* @throws \Exception
* @return WebDriverResponse
*/
public function execute(WebDriverCommand $command)
{
if ($command->getName() === DriverCommand::NEW_SESSION) {
$this->service->start();
}
try {
$value = parent::execute($command);
if ($command->getName() === DriverCommand::QUIT) {
$this->service->stop();
}
return $value;
} catch (\Exception $e) {
if (!$this->service->isRunning()) {
throw new WebDriverException('The driver server has died.');
}
throw $e;
}
}
}

Some files were not shown because too many files have changed in this diff Show More