Skip to content

Commit 8b758e8

Browse files
committed
implemented artifacts
1 parent b29698e commit 8b758e8

File tree

6 files changed

+91
-14
lines changed

6 files changed

+91
-14
lines changed

server.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22
const express = require('express');
33
const Playwright = require('codeceptjs/lib/helper/Playwright');
4+
const path = require('path');
45
const app = express();
56
const port = 8191;
67
app.use(express.json());
@@ -47,13 +48,6 @@ app.get('/test/:id', async (req, res) => {
4748
res.status(200).json(tests[id]);
4849
});
4950

50-
app.post('/test', async (req, res) => {
51-
const { id, title } = req.body;
52-
53-
if (!tests[id]) tests[id] = { title }
54-
55-
});
56-
5751
app.post('/hook', async (req, res) => {
5852
const { command, arguments } = req.body;
5953

@@ -73,16 +67,19 @@ app.post('/hook', async (req, res) => {
7367
const fileName = `${id}_failed.png`;
7468
try {
7569
await playwright.saveScreenshot(fileName);
76-
tests[id].artifacts ||= {}
77-
tests[id].artifacts.screenshot = fileName;
70+
if (!tests[id]) tests[id] = { title }
71+
if (!tests[id].artifacts) tests[id].artifacts = {}
72+
tests[id].artifacts.screenshot = path.join(output_dir, fileName);
7873
} catch (err) {
74+
console.error('Error saving screenshot: ', err);
7975
// not matter
8076
}
8177
default:
8278
result = await playwright[`_${hook}`](tests[id]);
8379
}
8480

85-
res.status(200).json({ result, test: tests[id] });
81+
const test = tests[id];
82+
res.status(200).json({ result, test });
8683
} catch (error) {
8784
const message = error.inspect ? error.inspect() : error.message;
8885
res.status(500).json({ message });

src/Playwright.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,18 @@ public function _after(TestInterface $test): void
9292
'id' => $this->testId,
9393
], 'hook');
9494
}
95-
$this->sendCommand('_after', [
95+
$this->sendCommand('after', [
9696
'id' => $this->testId,
9797
], 'hook');
9898

99-
if ($this->currentTest && $this->currentTest['artifacts']) {
99+
if ($this->currentTest) {
100+
101+
$this->debugSection('Test', $this->currentTest);
102+
103+
if (isset($this->currentTest['artifacts'])) {
100104
foreach ($this->currentTest['artifacts'] as $artifact => $file) {
101-
$test->getMetadata()->addReport($artifact, $file);
105+
$test->getMetadata()->addReport($artifact, $file);
106+
}
102107
}
103108
unset($this->currentTest);
104109
}
@@ -894,6 +899,10 @@ private function sendCommand(string $command, array $arguments = [], string $end
894899

895900
$url = $this->config['pw_server'];
896901

902+
if (!str_starts_with($endpoint, '/')) {
903+
$endpoint = '/' . $endpoint;
904+
}
905+
897906
$ch = curl_init($url . $endpoint);
898907
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
899908
curl_setopt($ch, CURLOPT_POST, true);

tests/E2e.suite.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
actor: E2eTester
2+
suite_namespace: \E2e
3+
modules:
4+
enabled:
5+
- Playwright:
6+
url: http://127.0.0.1:8000
7+
browser: chromium
8+
window_size: 1200x768
9+
timeout: 1000
10+
show: false
11+
restart: true
12+
pw_debug: true
13+
video: true
14+
trace: true

tests/E2e/DemoCest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace E2e;
4+
5+
use \E2eTester;
6+
7+
class DemoCest
8+
{
9+
public function _before(E2eTester $I)
10+
{
11+
}
12+
13+
// tests
14+
public function tryToTest(E2eTester $I)
15+
{
16+
$I->amOnPage('/');
17+
$I->see('Welcome');
18+
// $I->see('Welcome back');
19+
}
20+
}

tests/support/E2eTester.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
/**
7+
* Inherited Methods
8+
* @method void wantTo($text)
9+
* @method void wantToTest($text)
10+
* @method void execute($callable)
11+
* @method void expectTo($prediction)
12+
* @method void expect($prediction)
13+
* @method void amGoingTo($argumentation)
14+
* @method void am($role)
15+
* @method void lookForwardTo($achieveValue)
16+
* @method void comment($description)
17+
* @method void pause($vars = [])
18+
*
19+
* @SuppressWarnings(PHPMD)
20+
*/
21+
class E2eTester extends \Codeception\Actor
22+
{
23+
use _generated\E2eTesterActions;
24+
25+
/**
26+
* Define custom actions here
27+
*/
28+
}

tests/web/WebDriverTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,18 @@ public function testWaiters()
455455
$this->module->amOnPage('/');
456456
$this->module->waitForElementClickable('#link');
457457
$this->module->waitForElementVisible('#link');
458-
458+
459459
$this->module->amOnPage('/info');
460460
$this->module->waitForElementNotVisible('Invisible text');
461+
462+
}
463+
464+
#[Skip('Bug in CodeceptJS')]
465+
public function testWaitForText()
466+
{
467+
$this->module->amOnPage('/');
468+
$this->module->waitForText('debug!');
469+
$this->module->waitForText('"debug!"');
461470
}
462471

463472
public function testGrabPageSourceWhenOnPage()

0 commit comments

Comments
 (0)