-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SelenoidHelper.php
71 lines (59 loc) · 2.3 KB
/
SelenoidHelper.php
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
<?php
namespace Tienvx\Bundle\MbtBundle\Service;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\WebDriverCapabilityType;
use Tienvx\Bundle\MbtBundle\Model\BugInterface;
use Tienvx\Bundle\MbtBundle\Model\TaskInterface;
class SelenoidHelper implements SelenoidHelperInterface
{
private const BUG = 'bug';
private const TASK = 'task';
protected string $webdriverUri;
public function setWebdriverUri(string $webdriverUri): void
{
$this->webdriverUri = $webdriverUri;
}
public function getVideoUrl(TaskInterface|BugInterface $entity): string
{
return sprintf('%s/video/%s', $this->webdriverUri, $this->getVideoName($entity));
}
public function getLogUrl(TaskInterface|BugInterface $entity): string
{
return sprintf('%s/logs/%s', $this->webdriverUri, $this->getLogName($entity));
}
public function createDriver(DesiredCapabilities $capabilities): RemoteWebDriver
{
return RemoteWebDriver::create(
$this->webdriverUri . '/wd/hub',
$capabilities
);
}
public function getCapabilities(TaskInterface|BugInterface $entity, bool $debug = false): DesiredCapabilities
{
$task = $entity instanceof BugInterface ? $entity->getTask() : $entity;
$caps = [
WebDriverCapabilityType::BROWSER_NAME => $task->getBrowser()->getName(),
WebDriverCapabilityType::VERSION => $task->getBrowser()->getVersion(),
'enableVNC' => false,
'enableLog' => $debug,
'enableVideo' => $debug,
];
if ($debug) {
$caps += [
'logName' => $this->getLogName($entity),
'videoName' => $this->getVideoName($entity),
'videoFrameRate' => 60,
];
}
return new DesiredCapabilities($caps);
}
public function getVideoName(TaskInterface|BugInterface $entity): string
{
return sprintf('%s-%d.mp4', $entity instanceof TaskInterface ? static::TASK : static::BUG, $entity->getId());
}
public function getLogName(TaskInterface|BugInterface $entity): string
{
return sprintf('%s-%d.log', $entity instanceof TaskInterface ? static::TASK : static::BUG, $entity->getId());
}
}