shimabox/selenium-downloader

下载selenium-server-standalone、ChromeDriver、geckodriver和IEDriverServer。

v0.3.2 2020-04-29 02:37 UTC

This package is auto-updated.

Last update: 2024-09-29 04:43:28 UTC


README

下载selenium-server-standalone、ChromeDriver、geckodriver和IEDriverServer。

License Build Status

功能

演示

交互式。

demo-interaction

通过选项(非交互式)。

demo-option

需求

  • PHP 5.5+ 或更高版本

安装

通过Composer

$ composer require shimabox/selenium-downloader

请参阅以下链接。
##instant-download

开发

$ git clone https://github.com/shimabox/selenium-downloader
$ cd selenium-downloader
$ composer install

设置(.env)

如果您需要更改默认设置,请复制 .env.default 文件,创建一个 .env 文件,并修改 .env 文件。
默认设置查看 .env.default 文件。

$ cp .env.dafault .env
$ vim .env

// The default of output directory path(Output to "selenium-downloader/xxx" if not set).
DEFAULT_OUTPUT_DIR=
// The default version of selenium-server-standalone.
// Why 3.8.1? Because there are cases where it will not work unless pass-through mode can be set to false(-enablePassThrough false).
DEFAULT_SELENIUM_VER='3.8.1'
// The default version of ChromeDriver.
DEFAULT_CHROMEDRIVER_VER='81.0.4044.69'
// The default version of geckodriver.
DEFAULT_GECKODRIVER_VER='0.26.0'
// The default version of IEDriverServer.
DEFAULT_IEDRIVER_VER='3.141.59'

如果未设置 DEFAULT_OUTPUT_DIR,则下载的资源将输出到 selenium-downloader/xxx

使用方法

在交互式模式下。

# Run without option.
$ php selenium_downloader.php

例如)

# "m" or "w" or "l" is mandatory.
Please select platform. [m]ac, [w]indows, [l]inux: w
# Specify the directory path to output.
# If not specified, it is output to the path specified by .env.dafault|.env(DEFAULT_OUTPUT_DIR).
# If there is still no value, it is output to "selenium-downloader/xxx".
Please enter the output directory
Default[/default/output/path]:
# Default "No".
Do you need Selenium? [N]o, [y]es: y
# Default "3.8.1".
# Why 3.8.1? Because there are cases where it will not work unless pass-through mode can be set to false(-enablePassThrough false).
Please enter selenium-server-standalone version Default [3.8.1]: 3.8.1
# Default "No".
Do you need ChromeDriver? [N]o, [y]es: y
# Default "81.0.4044.69".
Please enter ChromeDriver version Default [81.0.4044.69]:
# Default "No".
Do you need GeckoDriver? [N]o, [y]es: y
# Default "0.26.0".
Please enter GeckoDriver version Default [0.26.0]:
# Default "No".
Do you need IEDriver? [N]o, [y]es: y
# Default "3.141.59".
Please enter IEDriver version Default [3.141.59]:
# Default "32" (Because key input is earlier than 64bit version).
Please enter OS bit version [32]bit, [64]bit, Default[32]:
Done.

在指定选项(非交互式)的情况下。

支持以下选项。

帮助信息。

$ php selenium_downloader.php -h
Usage:
  -h,--help
    Display help message and exit.
  -p platform (required)
    Select platform [m]ac or [w]indows or [l]inux.
    Required except that "--help, -h" is specified.
  -d output_dir_path
    Enter the output directory path.
    If not specified, it is output to the path specified by .env.dafault|.env(DEFAULT_OUTPUT_DIR).
    If there is still no value, it is output to "selenium-downloader/xxx".
  -s selenium-standalone-server_ver
    Enter the version of selenium-standalone-server. (e.g 3.8.1, 3.7(3.7.0)
    (Recommend version 3.8.1)
  -c ChromeDriver_ver
    Enter the version of ChromeDriver. (e.g 81.0.4044.69, 2.43
  -g geckodriver_ver
    Enter the version of GeckoDriver. (e.g 0.26(0.26.0), 0.20.1
  -i IEDriverServer_ver
    Enter the version of IEDriverServer. (e.g 3.141.59, 3.14(3.14.0)
  -b bit_of_os
    Enter the number of OS bits (32 or 64).
    Default is "32" (Because key input is earlier than 64bit version).
    Valid only when IEDriverServer is specified.

e.g) 1 Basic.
$ php selenium_downloader.php -p m -s 3.8.1 -c 81.0.4044.69 -g 0.26
e.g) 2 When specifying the output directory.
$ php selenium_downloader.php -p m -d /your/path/to -s 3.8.1
e.g) 3 When downloading the 64 bit version of the IEDriverServer.
$ php selenium_downloader.php -p w -i 3.141.59 -b 64
e.g) 4 When downloading only geckodriver.
$ php selenium_downloader.php -p m -g 0.26
or
$ php selenium_downloader.php -p m -s "" -c "" -g 0.26

即时下载

例如,创建 instant_selenium.php

<?php
require_once 'vendor/autoload.php';

use SMB\SeleniumDownloader\Downloader;
// Interface
use SMB\SeleniumDownloader\Argument\Optionable;

// Prepare a class that implements the optionable interface.
class InstantSelenium implements Optionable
{
    /**
     * Returns true if option is specified.
     *
     * @return boolean
     */
    public function isSpecified()
    {
        return true;
    }

    /**
     * If true it will output a help message.
     *
     * @return boolean
     */
    public function isSpecifiedHelp()
    {
        return false;
    }

    /**
     * Create help message.
     *
     * @return string
     */
    public function createHelpMessage()
    {
        return '';
    }

    /**
     * Get optional arguments.
     *
     * e.g)
     * <code>
     * return [
     *     'p' => 'w',            // Select platform [m]ac or [w]indows or [l]inux.
     *     'd' => '.',            // Enter the output directory path.
     *     's' => '3.8.1',        // Enter the version of selenium-standalone-server. (e.g 3.8.1, 3.7(3.7.0)
     *     'c' => '81.0.4044.69', // Enter the version of ChromeDriver. (e.g 81.0.4044.69, 2.43
     *     'g' => '0.26.0',       // Enter the version of GeckoDriver. (e.g 0.26(0.26.0), 0.20.1
     *     'i' => '3.141.59',     // Enter the version of IEDriverServer. (e.g 3.141.59, 3.14(3.14.0)
     *     'b' => '32',           // Enter the number of OS bits (32 or 64).
     * ];
     * </code>
     *
     * @return array
     */
    public function get()
    {
        return [
            'p' => 'm', // Select mac.
            's' => '3.8.1',
            'c' => '81.0.4044.69',
            'g' => '0.26.0',
        ];
    }
}

$downloader = new Downloader(new InstantSelenium());
$downloader->execute();

执行

$ php instant_selenium.php

demo-instant

注意

如果有同名文件,将被覆盖。

许可

MIT 许可证(MIT)。更多信息请参阅 许可文件