定制 itnelo/reactphp-webdriver 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

itnelo/reactphp-webdriver

Composer 安装命令:

composer require itnelo/reactphp-webdriver

包简介

An async, W3C compliant PHP client for Selenium Grid server (hub)

README 文档

README

This is a direct port of RemoteWebDriver logic from the php-webdriver/webdriver package, which utilizes ReactPHP event loop and promise API for browser interaction w/o execution flow blocking.

Selenium WebDriver is a software that is used to manipulate browsers from the code (primarily, for testing and web scraping). You can find more here: https://selenium.dev.

This PHP client sends async HTTP requests to the Grid. It is a central endpoint for commands, a bridge between your code and browser instances. See SeleniumHQ/docker-selenium to get your own remote browser (or a cluster).

Enjoy!

Requirements

  • PHP 7.4 or higher.
  • ReactPHP v1 (http ^1, stream ^1).
  • Symfony conflicts: 5.1 (or newer) environments are preferred; the package uses (and will use) some components from there, and their code / version constraints may need a review, to include a wider range of supported environments (otherwise, you need to adjust your platform).

Installation

With composer:

$ composer require itnelo/reactphp-webdriver:^0.4

How to use

Call a factory method to get your instance (recommended). The minimal configuration is:

use React\EventLoop\Factory as LoopFactory;
use Itnelo\React\WebDriver\WebDriverFactory;

$loop = LoopFactory::create();

$webDriver = WebDriverFactory::create(
    $loop,
    [
        'hub' => [
            'host' => 'selenium-hub',
            'port' => 4444,
        ],
    ]
);

You can customize a set of parameters for the underlying ReactPHP Browser and tune driver options:

use React\EventLoop\Factory as LoopFactory;
use Itnelo\React\WebDriver\WebDriverFactory;

$loop = LoopFactory::create();

$webDriver = WebDriverFactory::create(
    $loop,
    [
        'browser' => [
            'tcp' => [
                'bindto' => '192.169.56.10:0',
            ],
            'tls' => [
                'verify_peer' => false,
                'verify_peer_name' => false,
            ],
        ],
        'hub' => [
            'host' => 'selenium-hub',
            'port' => 4444,
        ],
        'command' => [
            'timeout' => 30,
        ],
    ]
);

Manual configuration (if you prefer to configure each component as a separate service, e.g. compiling a DI container and want to reuse existing service definitions):

use React\EventLoop\Factory as LoopFactory;
use React\Socket\Connector as SocketConnector;
use React\Http\Browser;
use Itnelo\React\WebDriver\Client\W3CClient;
use Itnelo\React\WebDriver\Timeout\Interceptor as TimeoutInterceptor;
use Itnelo\React\WebDriver\SeleniumHubDriver;

$loop = LoopFactory::create();

$socketConnector = new SocketConnector(
    $loop,
    [
        'tcp' => [
            'bindto' => '192.169.56.10:0',
        ],
        'tls' => [
            'verify_peer' => false,
            'verify_peer_name' => false,
        ],
    ]
);
$browser = new Browser($loop, $socketConnector);
$browser = $browser->withRejectErrorResponse(false);

$hubClient = new W3CClient(
    $browser,
    [
        'server' => [
            'host' => 'selenium-hub',
            'port' => 4444,
        ],
    ]
);

$timeoutInterceptor = new TimeoutInterceptor($loop, 30);

$webDriver = new SeleniumHubDriver(
    $loop,
    $hubClient,
    $timeoutInterceptor
);

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

See also

  • php-webdriver/webdriver — the original, "blocking" implementation; to get information how to use some advanced methods. For example, WebDriverKeys helper describes Unicode strings for sending special inputs to page elements (e.g. Ctrl, Alt and other keys).

Changelog

All notable changes to this project will be documented in CHANGELOG.md.

itnelo/reactphp-webdriver 适用场景与选型建议

itnelo/reactphp-webdriver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 261 次下载、GitHub Stars 达 4, 最近一次更新时间为 2020 年 11 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「selenium」 「webdriver」 「reactphp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 itnelo/reactphp-webdriver 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 itnelo/reactphp-webdriver 我们能提供哪些服务?
定制开发 / 二次开发

基于 itnelo/reactphp-webdriver 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 261
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 9
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-30