Mink

minkphpMIT活跃维护

PHP 的浏览器模拟抽象层,统一封装多种无头浏览器驱动,让自动化测试和网页抓取代码不绑定具体实现。

PHP web browser emulator abstraction

v1.13.0发布于 2025-11-22 12:21 UTC1,606star285fork同步于 2026-11-07 07:31 UTC

怎么上手

由 README 提炼,执行前请确认
curl -sS https://getcomposer.org/installer | php
php composer.phar install
硬件要求按 README 说明

README 未说明,纯 PHP 库,无 GPU 或显存要求

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

PHP 浏览器模拟抽象层,用统一 API 驱动多种浏览器后端做 Web 测试

PHP 的浏览器模拟抽象层,统一封装多种无头浏览器驱动,让自动化测试和网页抓取代码不绑定具体实现。

核心能力

  • 用统一 Session 与 Driver 接口抽象不同浏览器后端
  • 支持注册多个命名会话并在同一测试中混用
  • 通过 getPage 提供 findLink 等页面元素查找与点击
  • 默认会话机制让无参 getSession 直接返回指定会话
  • 可自定义 Driver 接入自有浏览器实现

容易踩的坑

README 只给了抽象层,实际驱动(如 GoutteDriver)需自行安装对应后端包;示例中的 MyCustomDriver 需自己实现,不能直接运行;需先安装 Composer 才能执行安装命令

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v1.13.0
  1. v1.13.01.13.0最新正式版2025-11-22 · 2025-11-22 12:21 UTC

    New features:

    • Added support for symfony/css-selector 8
    • Improve PHPStorm's autocomplete for DriverInterface methods

    Testsuite:

    • Added CI jobs for PHP 8.5
  2. v1.12.01.12.02024-10-30 · 2024-10-30 18:49 UTC
    查看更新说明

    Bug fixes:

    • Explicitly mark method parameters with null default values as nullable to avoid deprecation notice in PHP 8.4
  3. v1.11.01.11.02023-12-09 · 2023-12-09 11:25 UTC
    查看更新说明

    New features:

    • Added support for symfony/css-selector 7
    • Added constants for the supported key modifiers
    • Improved types to help static analysis
    • Added parameter types for most methods

    Testsuite:

    • Added CI jobs for PHP 8.2 and 8.3
    • Added static analysis in our CI
  4. v1.10.01.10.02022-03-28 · 2022-03-28 14:24 UTC
    查看更新说明

    New features:

    • Added support for symfony/css-selector 6
    • Added WebAssert::elementAttributeNotExists

    Removed:

    • Removed support for PHP <7.2
    • Removed support for symfony/css-selector <4.4

    Bug fixes:

    • Fixed phpdoc for a bunch of arguments that were not properly marked as nullable
  5. v1.9.01.9.02021-10-11 · 2021-10-11 12:00 UTC
    查看更新说明

    New features:

    • Fixed deprecation warnings on PHP 8.1
    • Improved responsiveness of Element::waitFor
    • Allowed selectors and replacements to be registered late

    Removed:

    • Removed support for PHP 5.3

    Testsuite:

    • Added CI jobs for PHP 8.0 and 8.1

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Mink

    Latest Stable Version Latest Unstable Version Total Downloads CI License

    Useful Links

    Usage Example

    <?php
    
    use Behat\Mink\Mink,
        Behat\Mink\Session,
        Behat\Mink\Driver\GoutteDriver,
        Behat\Mink\Driver\Goutte\Client as GoutteClient;
    
    $startUrl = 'http://example.com';
    
    // init Mink and register sessions
    $mink = new Mink(array(
        'goutte1' => new Session(new GoutteDriver(new GoutteClient())),
        'goutte2' => new Session(new GoutteDriver(new GoutteClient())),
        'custom'  => new Session(new MyCustomDriver($startUrl))
    ));
    
    // set the default session name
    $mink->setDefaultSessionName('goutte2');
    
    // visit a page
    $mink->getSession()->visit($startUrl);
    
    // call to getSession() without argument will always return a default session if has one (goutte2 here)
    $mink->getSession()->getPage()->findLink('Downloads')->click();
    echo $mink->getSession()->getPage()->getContent();
    
    // call to getSession() with argument will return session by its name
    $mink->getSession('custom')->getPage()->findLink('Downloads')->click();
    echo $mink->getSession('custom')->getPage()->getContent();
    
    // this all is done to make possible mixing sessions
    $mink->getSession('goutte1')->getPage()->findLink('Chat')->click();
    $mink->getSession('goutte2')->getPage()->findLink('Chat')->click();
    

    Install Dependencies

    $> curl -sS https://getcomposer.org/installer | php
    $> php composer.phar install
    

    Contributors