1 | <?php |
||
2 | |||
3 | namespace Bavix\Cases; |
||
4 | |||
5 | class TestCase extends \PHPUnit\Framework\TestCase |
||
6 | { |
||
7 | |||
8 | protected $providers = [ |
||
9 | 'chrome' => Provider\ChromeProvider::class, |
||
10 | 'firefox' => Provider\GeckoProvider::class, |
||
11 | ]; |
||
12 | |||
13 | /** |
||
14 | * @var Params |
||
15 | */ |
||
16 | protected $params; |
||
17 | |||
18 | /** |
||
19 | * @var RemoteWebDriver |
||
20 | */ |
||
21 | protected $driver; |
||
22 | |||
23 | /** |
||
24 | * @return Provider |
||
25 | */ |
||
26 | protected function caps(): Provider |
||
27 | { |
||
28 | $browser = $this->params->getBrowser(); |
||
29 | if (empty($this->providers[$browser])) { |
||
30 | throw new \RuntimeException('Browser not supported'); |
||
31 | } |
||
32 | |||
33 | $class = $this->providers[$browser]; |
||
34 | return new $class($this->params); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @inheritdoc |
||
39 | */ |
||
40 | public function setUp() |
||
41 | { |
||
42 | $this->params = new Params($this->getAnnotations()); |
||
43 | $provider = $this->caps(); |
||
44 | $caps = $provider->handle(); |
||
45 | |||
46 | $this->driver = RemoteWebDriver::create($provider->serverUrl(), $caps); |
||
47 | $this->driver->setBaseUrl($_ENV['BASE_URL']); |
||
48 | $this->driver->get($this->params->getPath()); |
||
49 | $provider->configure($this->driver); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * This method is called after each test. |
||
54 | */ |
||
55 | protected function tearDown() |
||
56 | { |
||
57 | try { |
||
58 | $this->driver->close(); |
||
59 | $this->driver->quit(); |
||
60 | } catch (\Throwable $throwable) { |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
![]() |
|||
61 | |||
62 | } |
||
63 | } |
||
64 | |||
65 | } |
||
66 |