dmore/chrome-mink-driver 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

dmore/chrome-mink-driver

Composer 安装命令:

composer require dmore/chrome-mink-driver

包简介

Mink driver for controlling chrome without selenium

README 文档

README

Mink driver for controlling Chrome without the overhead of Selenium.

It communicates directly with Google Chrome over HTTP and WebSockets, which allows it to work at least twice as fast as Chrome with Selenium. For Chrome 59+ it supports headless mode, eliminating the need to install a display server, and the overhead that comes with it. This driver is tested and benchmarked against a behat suite of 1800 scenarios and 19000 steps. It can successfully run it in less than 18 minutes with Chrome 60 headless. The same suite running against Chrome 58 with xvfb and Selenium takes ~60 minutes.

Gitlab CI pipeline OpenSSF Best Practices

Installation

composer require dmore/chrome-mink-driver

Requirements

  • Google Chrome or Chromium running with remote debugging.

Example:

google-chrome-stable --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222

or headless (v59+):

google-chrome-unstable --disable-gpu --headless --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222

It is recommended to start Chrome with the --disable-extensions flag.

See https://gitlab.com/DMore/behat-chrome-skeleton for a fully working example.

Checking Chrome connectivity

To manually test connectivity, you can use curl or similar and request the json/version endpoint:

curl http://localhost:9222/json/version

Contributing

Contributions are welcome! Use the issue queue and merge requests to propose changes. Please refer to Gitlab documentation for how to use the Gitlab interface.

  • To report an issue (bug, feature request etc) use the issue queue.
  • If you are reporting a potential security issue, please check "This issue is confidential" when reporting the issue to the project.
  • To propose code changes or a solution for an issue, use merge requests.
  • Test coverage is executed on merge requests. Contributions should extend test coverage where possible and ensure all tests pass.
  • Coding standards checks are executed on merge requests. Contributions should maintain coding standards.
  • PHP code should adhere to PSR12.
  • composer.json should be normalized using composer normalize.

Tests

The base test coverage is that from upstream mink/driver-testsuite, and validates that core DriverInterface functionality is correct per those expectations.

Test execution requires a webserver configured to serve fixtures from minkphp/driver-testsuite, which is provided by a docker image from the related behat-chrome/docker-chrome-headless project.

Tests are executed on each merge request via Gitlab CI. New functionality or bugfixes should seek to expand test or at least maintain existing coverage.

Using make to execute commands in Docker

commandpurpose
make installInstall dependencies with composer
make testRun tests with phpunit
make phpcbfTidy code using phpcbf
make phpcsCheck coding standards with phpcs

Docker environment to run commands

To perform these tasks without make, you can execute the same commands as above in a container. To run the tests using phpunit:

docker run --rm -it -v .:/code -e DOCROOT=/code/vendor/mink/driver-testsuite/web-fixtures registry.gitlab.com/behat-chrome/docker-chrome-headless bash

then, in the container shell:

composer install
vendor/bin/phpunit

Executing Gitlab CI pipeline locally

You can also run the Gitlab CI pipeline in your local environment, using firecow/gitlab-ci-local!

Versioning & releases

Making a release

When it's time to release:

  1. Ensure a header for the release is added to CHANGELOG.md, retaining the "Unreleased" header at top.
  2. A new release should be created using Gitlab's Release UI
    • The release title and tag is the version only.
    • The release notes are the CHANGELOG entries for the version.
  3. Packagist will detect the new release and make it available.

Usage

use Behat\Mink\Mink;
use Behat\Mink\Session;
use DMore\ChromeDriver\ChromeDriver;

$mink = new Mink([
  'browser' => new Session(new ChromeDriver('http://localhost:9222', null, 'http://www.google.com'))
]);

Configuration

OptionValueDescription
socketTimeoutint, default: 10Connection timeout (seconds)
domWaitTimeoutint, default: 3000DOM ready waiting timeout (milliseconds)
downloadBehaviorallow, default, denyChrome switch to permit downloads. (v62+)
downloadPathe.g. /tmp/ (the default)Where to download files to, if permitted.

Pass configuration values as the third parameter to new ChromeDriver().

Rendering PDF and Screenshots

Despite the Mink functionality the driver supports printing PDF pages or capturing a screenshot.

use Behat\Mink\Mink;
use Behat\Mink\Session;
use DMore\ChromeDriver\ChromeDriver;
$mink = new Mink(array(
    'browser' => new Session(new ChromeDriver('http://localhost:9222', null, 'http://www.google.com'))
));
$mink->setDefaultSessionName('browser');
$mink->getSession()->visit('https://gitlab.com/behat-chrome/chrome-mink-driver/blob/master/README.md');
$driver = $mink->getSession()->getDriver();
$driver->printToPdf('/tmp/readme.pdf');

The available options are documented here: https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF

Screenshots are supported using the Mink driver interface method getScreenshot().

Related projects

Behat extension

To use this driver with Behat, try the dmore/behat-chrome-extension Behat extension.

Docker image

A Docker image is used to execute tests against the targeted browser(s), and includes recent Chrome Stable, Chrome Beta and Chromium.

dmore/chrome-mink-driver 适用场景与选型建议

dmore/chrome-mink-driver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15.28M 次下载、GitHub Stars 达 67, 最近一次更新时间为 2017 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 dmore/chrome-mink-driver 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 15.28M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 75
  • 点击次数: 32
  • 依赖项目数: 372
  • 推荐数: 3

GitHub 信息

  • Stars: 67
  • Watchers: 0
  • Forks: 88
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-05-13