initbiz/oc-selenium2tests-plugin

此包已被弃用且不再维护。作者建议使用 https://github.com/initbiz/selenium2tests-plugin 包。

使用 Selenium 2 在 OctoberCMS 中编写测试

安装: 485

依赖: 0

建议者: 0

安全: 0

星星: 1

关注者: 2

分支: 2

公开问题: 0

类型:october-plugin

dev-master 2024-02-05 14:43 UTC

This package is auto-updated.

Last update: 2024-02-05 14:43:51 UTC


README

Selenium 2 Tests banner

这是一个由 InIT.biz 创建的 OctoberCMS 插件仓库。

如何使用

系统要求

  1. Java 8 已安装在你的平台默认位置(例如 Linux 的 /usr/bin/java
  2. 用于测试的浏览器的驱动程序(例如 ChromeDriver

Linux 用户注意事项

从你的包管理器安装 Chromium 应该会为你安装 ChromeDriver

Mac 用户注意事项

你可能需要按照以下链接描述将较新版本的 Java 链接到默认路径:这里

安装

  1. 你可以使用三种方法来安装此插件
  2. OctoberCMS 市场place,
  3. 从 GitHub 克隆代码到 /plugins/initbiz/selenium2tests 目录或
  4. 使用 Composer 安装 composer require --dev initbiz/oc-selenium2tests-plugin
  5. "laravel/dusk": "^2.0" 添加到 composer.json 文件的 require-dev 部分
  6. 转到 /plugins/initbiz/selenium2tests
  7. selenium.php.example 复制到 selenium.php 并配置你的环境

你还可以在你的根目录中创建 selenium.php 文件,它将在插件目录中的文件不存在时被读取

测试 OctoberCMS 基础

不要将测试和开发目的使用相同的数据库是一个好习惯。

为了配置用于测试目的的不同数据库,请在 config 目录中创建 testing 目录并将 database.php 复制到新创建的目录中。然后按需更改默认连接。

之后,如果你在 .env 文件中使用 APP_ENV=testing,则将从 testing 目录使用配置。

在 Selenium 2 中编写测试

tests/example 目录中有使用 Ui2TestCase 类的示例测试。

运行测试

首先,你必须运行包含在包中的 Selenium 2 独立服务器。为了启动 Selenium 2 服务器,请转到 <project_root>/plugins/initbiz/selenium2tests 并运行 java -jar selenium.jar

现在你可以使用 OctoberCMS 的 vendor/bin/phpunit 运行测试了。

你可以将测试文件放在任何位置,但插件的 .gitignore 将排除除 /tests/examples 之外的所有 /tests 目录下的文件。

浏览器选项(例如无头模式)

如果您想例如以无头模式运行浏览器,可以将该行添加到您的 selenium.php 文件中

define('TEST_SELENIUM_BROWSER_OPTIONS', ['--headless']);