Repository navigation
Expand file tree
/
Copy pathbehat.php
More file actions
119 lines (111 loc) 路 5.68 KB
/
Copy pathbehat.php
File metadata and controls
119 lines (111 loc) 路 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
declare(strict_types=1);
use Behat\Config\Config;
use Behat\Config\Extension;
use Behat\Config\Filter\TagFilter;
use Behat\Config\GherkinOptions;
use Behat\Config\Profile;
use Behat\Config\Suite;
use Behat\MinkExtension\Context\MinkContext;
use Behat\MinkExtension\ServiceContainer\MinkExtension;
use ConsumerProject\Backend\Alias\HeadlineAlias;
use DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension;
use DrevOps\BehatPhpServer\PhpServerContext;
use DrevOps\BehatScreenshotExtension\Context\ScreenshotContext;
use DrevOps\BehatScreenshotExtension\ServiceContainer\BehatScreenshotExtension;
use DrevOps\BehatSteps\Extension\ServiceContainer\BehatStepsExtension;
use DVDoug\Behat\CodeCoverage\Extension as CodeCoverageExtension;
$suite = (new Suite('default'))
->withPaths('%paths.base%/tests/behat/features')
->addContext(FeatureContext::class)
->addContext(BehatCliContext::class)
->addContext(MinkContext::class)
->addContext(ScreenshotContext::class)
->addContext(PhpServerContext::class, [
'webroot' => '%paths.base%/tests/behat/fixtures',
'protocol' => 'http',
'host' => '0.0.0.0',
'port' => 8888,
'debug' => FALSE,
]);
// A scenario tagged '@test-drupal:<major>' runs on that fixture only, so the
// tags of every other fixture under tests/behat/fixtures_drupal are filtered
// out along with '@test-skipped'.
$drupal_major = (string) (getenv('DRUPAL_VERSION') ?: '11');
$fixture_majors = array_map(static fn(string $dir): string => substr(basename($dir), 1), glob(__DIR__ . '/tests/behat/fixtures_drupal/d*', GLOB_ONLYDIR) ?: []);
$other_majors = array_filter($fixture_majors, static fn(string $major): bool => $major !== $drupal_major);
$tag_filter = implode('&&', ['~@test-skipped', ...array_map(static fn(string $major): string => '~@test-drupal:' . $major, $other_majors)]);
$default = (new Profile('default', ['autoload' => ['%paths.base%/tests/behat/bootstrap']]))
// The Gherkin cache is disabled during development.
->withGherkinOptions((new GherkinOptions(['cache' => '']))->withFilter(new TagFilter($tag_filter)))
->withSuite($suite)
->withExtension(new Extension(MinkExtension::class, [
'base_url' => 'http://nginx:8080',
'files_path' => '%paths.base%/tests/behat/fixtures',
'browser_name' => 'chrome',
'javascript_session' => 'selenium2',
'sessions' => [
'browserkit_http' => ['browserkit_http' => NULL],
'selenium2' => [
'selenium2' => [
'wd_host' => 'http://chrome:4444/wd/hub',
'capabilities' => [
'browser' => 'chrome',
'extra_capabilities' => [
// '--disable-gpu' is required where no GPU is available, such as
// containers and CI runners. The rest increase stability and speed.
'goog:chromeOptions' => ['args' => ['--disable-gpu', '--disable-extensions', '--disable-infobars', '--disable-popup-blocking', '--disable-translate', '--no-first-run', '--test-type']],
],
],
],
],
],
]))
->withExtension(new Extension(BehatStepsExtension::class, [
'backends' => ['drupal', 'drush', 'blackbox'],
'blackbox' => NULL,
// Behat runs from within "build", so both roots are relative to it.
// 'HeadlineAlias' resolves the 'headline' column of the content scenario
// that covers 'creation_aliases'. 'CommentStatusHandler' sits in the
// bootstrap directory, which only the 'autoload' paths above load.
'drupal' => ['drupal_root' => 'web', 'field_handlers' => ['comment' => CommentStatusHandler::class], 'creation_aliases' => [HeadlineAlias::class]],
'drush' => [
'root' => 'web',
// Drush resolves a request URI for every command and does not
// bootstrap without one.
'global_options' => '--uri=http://nginx:8080',
],
'regions' => ['content' => '#content', 'sidebar' => '#sidebar', 'footer' => '#footer'],
'steps' => [
'message' => ['selectors' => ['default' => '.messages', 'error' => '.messages.messages--error', 'success' => '.messages.messages--status', 'warning' => '.messages.messages--warning']],
'mapping' => ['groups' => ['paths' => ['User Login' => '/user/login', 'User Registration' => '/user/register']]],
],
]))
->withExtension(new Extension(BehatScreenshotExtension::class, [
'dir' => '%paths.base%/.logs/screenshots',
'purge' => FALSE,
'on_failed' => TRUE,
'always_fullscreen' => TRUE,
'info_types' => ['url', 'feature', 'step', 'datetime'],
]));
// A build that cannot install the coverage extension runs without it.
if (class_exists(CodeCoverageExtension::class)) {
$default->withExtension(new Extension(CodeCoverageExtension::class, [
'filter' => ['include' => ['directories' => ['%paths.base%/src' => NULL]]],
'reports' => [
'text' => ['showColors' => TRUE, 'showOnlySummary' => TRUE],
'html' => ['target' => '%paths.base%/.logs/coverage/behat/.coverage-html'],
'cobertura' => ['target' => '%paths.base%/.logs/coverage/behat/cobertura.xml'],
'php' => ['target' => '%paths.base%/.logs/coverage/behat/phpcov.php'],
],
]));
}
// The "chrome_headless" profile, run with "behat -p chrome_headless", drives
// headless Chrome directly over the DevTools Protocol, with no Selenium
// server. It inherits the "default" profile and swaps only the JavaScript
// session to "chrome", a session on the driver that ChromeExtension
// registers.
$chrome_headless = (new Profile('chrome_headless'))
->withExtension(new Extension(ChromeExtension::class))
->withExtension(new Extension(MinkExtension::class, ['javascript_session' => 'chrome', 'sessions' => ['chrome' => ['chrome' => ['api_url' => 'http://chrome_headless:9222']]]]));
return (new Config())->withProfile($default)->withProfile($chrome_headless);