reportportal / behat
用于将Behat-baset测试框架与Report Portal(http://reportportal.io/)集成的特定类。
dev-master
2019-07-29 10:19 UTC
Requires
- behat/behat: *
- reportportal/basic: 1.0.x-dev
This package is auto-updated.
Last update: 2024-09-29 05:01:25 UTC
README
先决条件
- Behat框架(版本3.4.1)。
- Report Portal(RP)实例。
步骤
1) 在Behat-based测试框架的根目录中创建名为‘config.yaml’的文件,包含以下字段
UUID - 您自己的访问密钥。
Host - RP实例地址。
projectName - 创建启动的项目名称。
timeZone - 您的时区。
2) 更新您框架的composer.json文件,添加"reportportal/behat" : "1.0.x-dev"依赖项。
注意:"reportportal/behat" : "1.0.x-dev"已在behat 3.4.1和phpunit 3.7.30上测试过。
3) 在根目录中打开终端并执行“composer update”命令。
4) 更新/创建您的“base feature context”类,添加以下依赖项。
注意:BaseFeatureContext是一个扩展RawMinkContext类的类,并实现Comtext和SnippetAcceptingContext接口。没有这个类,您无法创建基于Behat的框架。
use BehatReportPortal\BehatReportPortalAnnotations;
use BehatReportPortal\BehatReportPortalService;
use ReportPortalBasic\Service\ReportPortalHTTPService;
基础特征上下文类应实现BehatReportPortalAnnotations。
5) 在基本上下文类(如图所示的BaseFeatureContext)中实现BehatReportPortalAnnotations的方法。
public static function startLaunch(HookScope $event)
public static function startFeature(HookScope $event)
public static function startScenario(HookScope $event)
public static function startStep(HookScope $event)
public static function finishStep(HookScope $event)
public static function finishScenario(HookScope $event)
public static function finishFeature(HookScope $event)
public static function finishLaunch(HookScope $event)
public static function startLaunch(HookScope $event)
{
if (!ReportPortalHTTPService::isSuiteRunned()) {
ReportPortalHTTPService::configureReportPortalHTTPService('config.yaml');
BehatReportPortalService::startLaunch($event);
}
}
public static function startFeature(HookScope $event)
{
if (!ReportPortalHTTPService::isFeatureRunned()) {
BehatReportPortalService::startFeature($event);
}
}
public static function startScenario(HookScope $event)
{
if (!ReportPortalHTTPService::isScenarioRunned()) {
BehatReportPortalService::startScenario($event);
}
}
public static function startStep(HookScope $event)
{
if (!ReportPortalHTTPService::isStepRunned()) {
BehatReportPortalService::startStep($event);
}
}
public static function finishStep(HookScope $event)
{
if (ReportPortalHTTPService::isStepRunned()) {
$pictureAsString = '';
if ($event->getTestResult()->getResultCode() === TestResult::FAILED) {
$session = Service::getSession();
if ($session != null) {
$pictureAsString = $session->getDriver()->getScreenshot();
}
}
BehatReportPortalService::finishStep($event, $pictureAsString);
}
}
public static function finishScenario(HookScope $event)
{
if (ReportPortalHTTPService::isScenarioRunned()) {
Service::sessionToNull();
BehatReportPortalService::finishScenario($event);
}
}
public static function finishFeature(HookScope $event)
{
if (ReportPortalHTTPService::isFeatureRunned()) {
BehatReportPortalService::finishFeature($event);
}
}
public static function finishLaunch(HookScope $event)
{
if (ReportPortalHTTPService::isSuiteRunned()) {
BehatReportPortalService::finishLaunch($event);
}
}