Skip to content

Commit ac3326a

Browse files
committed
factory class for the web driver, solid/grasp adjustments, readme: installation/examples
1 parent 61f4370 commit ac3326a

6 files changed

Lines changed: 522 additions & 111 deletions

File tree

README.md

Lines changed: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,27 @@ This is a direct port of [RemoteWebDriver](https://github.com/php-webdriver/php-
55
logic from the [php-webdriver/webdriver](https://github.com/php-webdriver/php-webdriver) package, which utilizes [ReactPHP](https://github.com/reactphp/reactphp)
66
event loop and promise API for browser interaction w/o execution flow blocking.
77

8-
Usage example:
8+
## Installation
9+
10+
With [composer](https://getcomposer.org/download):
11+
12+
```
13+
$ composer require itnelo/reactphp-webdriver:0.x@dev
14+
```
15+
16+
## How to use
17+
18+
Call a factory method to get your instance (recommended):
919

1020
```php
1121
use React\EventLoop\Factory as LoopFactory;
12-
use Itnelo\React\WebDriver\Client\W3CClient;
22+
use Itnelo\React\WebDriver\WebDriverFactory;
1323

1424
$loop = LoopFactory::create();
15-
16-
$webdriver = new W3CClient(
25+
26+
$webDriver = WebDriverFactory::create(
1727
$loop,
1828
[
19-
'server' => [
20-
'host' => 'selenium-hub',
21-
'port' => 4444,
22-
],
23-
'command' => [
24-
'timeout' => 30,
25-
],
2629
'browser' => [
2730
'tcp' => [
2831
'bindto' => '192.168.56.10:0',
@@ -32,12 +35,67 @@ $webdriver = new W3CClient(
3235
'verify_peer_name' => false,
3336
],
3437
],
38+
'hub' => [
39+
'host' => 'selenium-hub',
40+
'port' => 4444,
41+
],
42+
'command' => [
43+
'timeout' => 30,
44+
],
45+
]
46+
);
47+
```
48+
49+
Manual configuration (if you want to configure each component as a separate service, e.g. compiling a DI container
50+
and want to reuse existing service definitions):
51+
52+
```php
53+
use React\EventLoop\Factory as LoopFactory;
54+
use React\Socket\Connector as SocketConnector;
55+
use React\Http\Browser;
56+
use Itnelo\React\WebDriver\Client\W3CClient;
57+
use Itnelo\React\WebDriver\SeleniumHubDriver;
58+
59+
$loop = LoopFactory::create();
60+
61+
$socketConnector = new SocketConnector(
62+
$loop,
63+
[
64+
'tcp' => [
65+
'bindto' => '192.168.56.10:0',
66+
],
67+
'tls' => [
68+
'verify_peer' => false,
69+
'verify_peer_name' => false,
70+
],
71+
],
72+
);
73+
$browser = new Browser($loop, $socketConnector);
74+
75+
$hubClient = new W3CClient(
76+
$browser,
77+
[
78+
'server' => [
79+
'host' => 'selenium-hub',
80+
'port' => 4444,
81+
],
82+
]
83+
);
84+
85+
$webDriver = new SeleniumHubDriver(
86+
$loop,
87+
$hubClient,
88+
[
89+
'command' => [
90+
'timeout' => 30,
91+
],
3592
]
3693
);
3794
```
3895

39-
See a self-documented [ClientInterface.php](src/ClientInterface.php) for the API details. Not all methods and arguments
40-
are ported (only the most necessary), so feel free to open an issue / make a pull request if you want more.
96+
See a self-documented [WebDriverInterface.php](src/WebDriverInterface.php) (and [ClientInterface.php](src/ClientInterface.php))
97+
for the API details. Not all methods and arguments are ported (only the most necessary), so feel free to open
98+
an issue / make a pull request if you want more.
4199

42100
## See also
43101

0 commit comments

Comments
 (0)