silverstripe-australia / ssautesting
扩展默认的 SS 测试结构,允许在 CI 构建中进行参数化,并提供一个 selenium 测试框架。
Requires
- codeception/codeception: ~2.3
- phpunit/phpunit: ^5.7
- silverstripe/framework: ~4.0
Replaces
- dev-master / 4.1.x-dev
- 4.1.2
- 4.1.1
- 4.1.0
- 4.0.1
- 4.0.0
- 3.0.x-dev
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.7.x-dev
- 1.7.1
- 1.7.0
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.x-dev
- 1.2.1
- 1.2.0
- 1.1.x-dev
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.x-dev
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-legacy
This package is not auto-updated.
Last update: 2022-02-01 12:45:36 UTC
README
向基础 SilverStripe 测试框架添加几个助手,通过参数化几个配置选项来简化测试过程与 CI 服务器(如 Jenkins)的连接。
此外,该模块提供 SymbioteSeleniumTestCase
,它为编写 Selenium 测试提供更简单的 API。
命令行参数
为了帮助测试执行,有几个参数可以在反复运行测试时加快速度。
build=0
- 在测试初始化期间不执行 dev/buildclean=0
- 不要清除现有的数据库状态flush=0
- 在测试初始化期间不执行 manifest flush
Selenium
要仅运行 selenium 测试,可以使用如下命令行
php vendor/silverstripe/framework/cli-script.php dev/tests/module/test-assist \
flush=1 build=1 selenium_host=127.0.0.1 browser=firefox \
test_url=http://my.silverstripe.site/ test_type=SymbioteSeleniumTestCase SkipTests=symbioteseleniumtestcase \
admin_user=admin admin_pass=admin
注意:URL 末尾的斜杠非常重要!
这将使你开始。注意,你需要 必须 运行 selenium 服务器 才能工作。以下命令将在虚拟帧缓冲区中启动 selenium 服务器,这意味着窗口不会全部出现在你的屏幕上!
#!/bin/sh
/usr/bin/xvfb-run -e /var/log/selenium/xvfb-selenium.log -n 10 \
-s "-screen 10 1024x768x8" \
java -jar /home/path/to/programs/selenium-server-standalone-2.39.0.jar \
-port 4444 -log /var/log/selenium/server.log
但是,直接从命令行运行 selenium 服务器来调试测试失败的原因可能很有用。
诊断工具
将 DB 配置中的 MySQLDatabase 更换为 DevMySQLDatabase
--- Name: dev_filters --- Injector: RequestProcessor: properties: filters: - %$QueryDisplayFilter - %$RequestTimerFilter
Codeception
要将 Codeception 连接到你的项目,你需要在项目顶层创建一个 codeception.yml 配置文件。
include:
- mymodule/codeception
paths:
log: path/to/logdir
codeception.yml 定义了测试运行中要包含的模块的路径。
在你的模块中,你可以创建一个具有特定名称空间的项目特定测试集合,并将其包含在该顶层路径中。
- mkdir modulename/codeception
- cd modulename/codeception
- ../../vendor/bin/codecept bootstrap --namespace modulenamespace
- mv codeception.yml codeception.dist.yml
- touch .gitignore
注意,'modulenamespace' 可以是任何内容,只要它是一个有效的 PHP 命名空间字符串即可。
接下来,创建一个新的 codeception.yml
文件,其中包含 仅 你的本地环境 codeception 配置;这通常是开发测试的本地 URL,即
modules:
config:
WebDriver:
url: http://project.clients.sslocal
browser: chrome
更新 modulename/codeception/tests/functional.suite.xml
并添加一些模块
class_name: FunctionalTester
modules:
enabled:
- \modulename\Helper\Functional
- WebDriver # new
- \Symbiote\TestAssist\SilverstripeFunctional # new
更新 modulename/codeception/tests/_bootstrap.php
以包含 SilverstripFunctional 辅助函数
<?php
// This is global bootstrap for autoloading
include_once 'test-assist/code/codeception/SilverstripeFunctional.php';
更新 modulename/codeception/tests/unit/_bootstrap.php
以设置单元测试的环境
<?php
// Unit testing specific setup
include_once 'vendor/silverstripe/framework/tests/bootstrap.php';
现在,将以下内容添加到 .gitignore
codeception.yml
/tests/_output/
将你的模块包含在顶层的 codeception.yml
include:
- modulename/codeception
最后,开始编写测试!在 modulename/codeception/tests/functional/FirstTestCept.php
<?php
use \Codeception\Util\Locator;
$I = new \modulenamespace\FunctionalTester($scenario);
$I->wantTo("Test the homepage");
$I->amOnPage("/");
$I->see("Home");
在 modulename/codeception/tests/unit/SmokeTest.php
<?php
class PageTest extends SapphireTest {
public function testMyMethod() {
$this->assertEquals(2, Page::MyMethod());
}
}
从项目的顶层开始
$ ./vendor/bin/codecept run
关于更好的按钮的说明
如果安装了更好的按钮,一些内置的辅助方法可能无法正常工作。如果是这种情况,请在代码中添加以下内容:
\Symbiote\TestAssist\SilverstripeFunctional.use_better_buttons: true
到 codeception.dist.yml 文件中