commit | author | age
|
2207d6
|
1 |
# php-webdriver – Selenium WebDriver bindings for PHP |
W |
2 |
|
|
3 |
[![Latest Stable Version](https://img.shields.io/packagist/v/facebook/webdriver.svg?style=flat-square)](https://packagist.org/packages/facebook/webdriver) |
|
4 |
[![Travis Build](https://img.shields.io/travis/facebook/php-webdriver/community.svg?style=flat-square)](https://travis-ci.org/facebook/php-webdriver) |
|
5 |
[![Sauce Test Status](https://saucelabs.com/buildstatus/php-webdriver)](https://saucelabs.com/u/php-webdriver) |
|
6 |
[![Total Downloads](https://img.shields.io/packagist/dt/facebook/webdriver.svg?style=flat-square)](https://packagist.org/packages/facebook/webdriver) |
|
7 |
[![License](https://img.shields.io/packagist/l/facebook/webdriver.svg?style=flat-square)](https://packagist.org/packages/facebook/webdriver) |
|
8 |
|
|
9 |
## Description |
|
10 |
Php-webdriver library is PHP language binding for Selenium WebDriver, which allows you to control web browsers from PHP. |
|
11 |
|
|
12 |
This library is compatible with Selenium server version 2.x and 3.x. |
|
13 |
It implements the [JsonWireProtocol](https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol), which is currently supported |
|
14 |
by the Selenium server and will also implement the [W3C WebDriver](https://w3c.github.io/webdriver/webdriver-spec.html) specification in the future. |
|
15 |
|
|
16 |
The concepts of this library are very similar to the "official" Java, .NET, Python and Ruby bindings from the |
|
17 |
[Selenium project](https://github.com/SeleniumHQ/selenium/). |
|
18 |
|
|
19 |
**As of 2013, this PHP client has been rewritten from scratch.** |
|
20 |
Using the old version? Check out [Adam Goucher's fork](https://github.com/Element-34/php-webdriver) of it. |
|
21 |
|
|
22 |
Looking for API documentation of php-webdriver? See [https://facebook.github.io/php-webdriver/](https://facebook.github.io/php-webdriver/latest/) |
|
23 |
|
|
24 |
Any complaints, questions, or ideas? Post them in the user group https://www.facebook.com/groups/phpwebdriver/. |
|
25 |
|
|
26 |
## Installation |
|
27 |
|
|
28 |
Installation is possible using [Composer](https://getcomposer.org/). |
|
29 |
|
|
30 |
If you don't already use Composer, you can download the `composer.phar` binary: |
|
31 |
|
|
32 |
curl -sS https://getcomposer.org/installer | php |
|
33 |
|
|
34 |
Then install the library: |
|
35 |
|
|
36 |
php composer.phar require facebook/webdriver |
|
37 |
|
|
38 |
## Getting started |
|
39 |
|
|
40 |
### Start Server |
|
41 |
|
|
42 |
The required server is the `selenium-server-standalone-#.jar` file provided here: http://selenium-release.storage.googleapis.com/index.html |
|
43 |
|
|
44 |
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**. |
|
45 |
|
|
46 |
java -jar selenium-server-standalone-#.jar |
|
47 |
|
|
48 |
**NOTE:** If using Firefox, see alternate command below. |
|
49 |
|
|
50 |
### Create a Browser Session |
|
51 |
|
|
52 |
When creating a browser session, be sure to pass the url of your running server. |
|
53 |
|
|
54 |
```php |
|
55 |
// This would be the url of the host running the server-standalone.jar |
|
56 |
$host = 'http://localhost:4444/wd/hub'; // this is the default |
|
57 |
``` |
|
58 |
|
|
59 |
##### Launch Chrome |
|
60 |
|
|
61 |
Make sure to have latest Chrome and [Chromedriver](https://sites.google.com/a/chromium.org/chromedriver/downloads) versions installed. |
|
62 |
|
|
63 |
```php |
|
64 |
$driver = RemoteWebDriver::create($host, DesiredCapabilities::chrome()); |
|
65 |
``` |
|
66 |
|
|
67 |
##### Launch Firefox |
|
68 |
|
|
69 |
Make sure to have latest Firefox and [Geckodriver](https://github.com/mozilla/geckodriver/releases) installed. |
|
70 |
|
|
71 |
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)), |
|
72 |
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: |
|
73 |
|
|
74 |
java -jar selenium-server-standalone-3.8.1.jar -enablePassThrough false |
|
75 |
|
|
76 |
Now you can start Firefox from your code: |
|
77 |
|
|
78 |
```php |
|
79 |
$driver = RemoteWebDriver::create($host, DesiredCapabilities::firefox()); |
|
80 |
``` |
|
81 |
|
|
82 |
### Customize Desired Capabilities |
|
83 |
|
|
84 |
```php |
|
85 |
$desired_capabilities = DesiredCapabilities::firefox(); |
|
86 |
$desired_capabilities->setCapability('acceptSslCerts', false); |
|
87 |
$driver = RemoteWebDriver::create($host, $desired_capabilities); |
|
88 |
``` |
|
89 |
|
|
90 |
* See https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities for more details. |
|
91 |
|
|
92 |
**NOTE:** Above snippets are not intended to be a working example by simply copy-pasting. See [example.php](example.php) for working example. |
|
93 |
|
|
94 |
## Changelog |
|
95 |
For latest changes see [CHANGELOG.md](CHANGELOG.md) file. |
|
96 |
|
|
97 |
## More information |
|
98 |
|
|
99 |
Some how-tos are provided right here in [our GitHub wiki](https://github.com/facebook/php-webdriver/wiki). |
|
100 |
|
|
101 |
You may also want to check out the Selenium [docs](http://docs.seleniumhq.org/docs/) and [wiki](https://github.com/SeleniumHQ/selenium/wiki). |
|
102 |
|
|
103 |
## Testing framework integration |
|
104 |
|
|
105 |
To take advantage of automatized testing you may want to integrate php-webdriver to your testing framework. |
|
106 |
There are some projects already providing this: |
|
107 |
|
|
108 |
- [Steward](https://github.com/lmc-eu/steward) integrates php-webdriver directly to [PHPUnit](https://phpunit.de/), and provides parallelization |
|
109 |
- [Codeception](http://codeception.com) testing framework provides BDD-layer on top of php-webdriver in its [WebDriver module](http://codeception.com/docs/modules/WebDriver) |
|
110 |
- 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 |
|
111 |
|
|
112 |
## Support |
|
113 |
|
|
114 |
We have a great community willing to help you! |
|
115 |
|
|
116 |
- **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 |
|
117 |
- **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 |
|
118 |
- **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 |
|
119 |
|
|
120 |
## Contributing |
|
121 |
|
|
122 |
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. |