Skip to content

Commit b5f9f3a

Browse files
committed
fix: actions, playwright, pw_test, stepbystep report, webapi
1 parent 6f5f03b commit b5f9f3a

File tree

5 files changed

+40
-47
lines changed

5 files changed

+40
-47
lines changed

lib/helper/Playwright.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import recorder from '../recorder.js';
99
import { includes as stringIncludes } from '../assert/include.js';
1010
import { urlEquals, equals } from '../assert/equal.js';
1111
import { empty } from '../assert/empty.js';
12-
import { truth } from '../assert/truth';
12+
import { truth } from '../assert/truth.js';
1313

1414
import {
1515
xpathLocator,
@@ -25,34 +25,28 @@ import {
2525
normalizeSpacesInString,
2626
} from '../utils.js';
2727

28-
import { isColorProperty, convertColorToRGBA } from '../colorUtils';
28+
import { isColorProperty, convertColorToRGBA } from '../colorUtils.js';
2929
import ElementNotFound from './errors/ElementNotFound.js';
30-
import RemoteBrowserConnectionRefused from './errors/RemoteBrowserConnectionRefused';
31-
import Popup from './extras/Popup';
32-
import Console from './extras/Console';
33-
import { findByPlaywrightLocator, findReact, findVue } from './extras/PlaywrightReactVueLocator';
30+
import RemoteBrowserConnectionRefused from './errors/RemoteBrowserConnectionRefused.js';
31+
import Popup from './extras/Popup.js';
32+
import Console from './extras/Console.js';
33+
import { findByPlaywrightLocator, findReact, findVue } from './extras/PlaywrightReactVueLocator.js';
3434

3535
import {
3636
setRestartStrategy, restartsSession, restartsContext, restartsBrowser,
37-
} from './extras/PlaywrightRestartOpts';
38-
import { createValueEngine, createDisabledEngine } from './extras/PlaywrightPropEngine';
37+
} from './extras/PlaywrightRestartOpts.js';
38+
import { createValueEngine, createDisabledEngine } from './extras/PlaywrightPropEngine.js';
3939

4040
import {
4141
seeElementError,
4242
dontSeeElementError,
4343
dontSeeElementInDOMError,
4444
seeElementInDOMError,
45-
} from './errors/ElementAssertion';
46-
47-
import {
48-
createAdvancedTestResults,
49-
allParameterValuePairsMatchExtreme,
50-
extractQueryObjects,
51-
} from './network/utils.js';
45+
} from './errors/ElementAssertion.js';
5246

5347
import {
5448
dontSeeTraffic, seeTraffic, grabRecordedNetworkTraffics, stopRecordingTraffic, flushNetworkTraffics,
55-
} from './network/actions';
49+
} from './network/actions.js';
5650

5751
let playwright;
5852
let perfTiming;

lib/helper/network/actions.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const assert = require('assert');
2-
const { isInTraffic, createAdvancedTestResults, getTrafficDump } = require('./utils');
1+
import assert from 'assert'
2+
import { isInTraffic, createAdvancedTestResults, getTrafficDump } from './utils.js';
33

4-
function dontSeeTraffic({ name, url }) {
4+
export function dontSeeTraffic({ name, url }) {
55
if (!this.recordedAtLeastOnce) {
66
throw new Error('Failure in test automation. You use "I.dontSeeTraffic", but "I.startRecordingTraffic" was never called before.');
77
}
@@ -19,7 +19,7 @@ function dontSeeTraffic({ name, url }) {
1919
}
2020
}
2121

22-
async function seeTraffic({
22+
export async function seeTraffic({
2323
name, url, parameters, requestPostData, timeout = 10,
2424
}) {
2525
if (!name) {
@@ -65,7 +65,7 @@ async function seeTraffic({
6565
}
6666
}
6767

68-
async function grabRecordedNetworkTraffics() {
68+
export async function grabRecordedNetworkTraffics() {
6969
if (!this.recording || !this.recordedAtLeastOnce) {
7070
throw new Error('Failure in test automation. You use "I.grabRecordedNetworkTraffics", but "I.startRecordingTraffic" was never called before.');
7171
}
@@ -104,20 +104,13 @@ async function grabRecordedNetworkTraffics() {
104104
return Promise.all(promises);
105105
}
106106

107-
function stopRecordingTraffic() {
107+
export function stopRecordingTraffic() {
108108
// @ts-ignore
109109
this.page.removeAllListeners('request');
110110
this.recording = false;
111111
}
112112

113-
function flushNetworkTraffics() {
113+
export function flushNetworkTraffics() {
114114
this.requests = [];
115115
}
116116

117-
module.exports = {
118-
dontSeeTraffic,
119-
seeTraffic,
120-
grabRecordedNetworkTraffics,
121-
stopRecordingTraffic,
122-
flushNetworkTraffics,
123-
};

lib/plugin/stepByStepReport.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export default function (config) {
151151
try {
152152
await helper.saveScreenshot(path.relative(reportDir, path.join(dir, fileName)), config.fullPageScreenshots);
153153
} catch (err) {
154-
output.plugin(`Can't save step screenshot: ${err}`);
154+
output.output.plugin(`Can't save step screenshot: ${err}`);
155155
error = err;
156156
return;
157157
} finally {
@@ -164,7 +164,7 @@ export default function (config) {
164164

165165
const allureReporter = Container.plugins('allure');
166166
if (allureReporter && config.screenshotsForAllureReport) {
167-
output.plugin('stepByStepReport', 'Adding screenshot to Allure');
167+
output.output.plugin('stepByStepReport', 'Adding screenshot to Allure');
168168
allureReporter.addAttachment(`Screenshot of step ${step}`, fs.readFileSync(path.join(dir, fileName)), 'image/png');
169169
}
170170
}

test/helper/Playwright_test.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
import path from 'path';
22
import fs from 'fs';
33
import playwright from 'playwright';
4-
import TestHelper from '../support/TestHelper';
5-
import Playwright from '../../lib/helper/Playwright';
4+
import TestHelper from '../support/TestHelper.js';
5+
import Playwright from '../../lib/helper/Playwright.js';
66
import AssertionFailedError from '../../lib/assert/error.js';
7-
import webApiTests from './webapi';
7+
import * as webApiTests from './webapi.js';
88
import FileSystem from '../../lib/helper/FileSystem.js';
99
import { deleteDir } from '../../lib/utils.js';
1010
import Secret from '../../lib/secret.js';
1111

12-
let assert;
13-
let expect;
14-
import('chai').then(chai => {
15-
assert = chai.assert;
16-
expect = chai.expect;
17-
});
18-
global.codeceptjs = require('../../lib');
12+
import { expect, assert } from 'chai';
13+
import test from '../../lib/utils.js'; // importing test method
14+
global.codeceptjs = '../../lib'
15+
16+
// To get __dirname in ESM
17+
import { fileURLToPath } from 'url';
18+
const __filename = fileURLToPath(import.meta.url);
19+
const __dirname = path.dirname(__filename);
1920

21+
// Path to data file
2022
const dataFile = path.join(__dirname, '/../data/app/db');
21-
const formContents = require('../../lib/utils.js').test.submittedData(dataFile);
23+
24+
// Accessing formContents from test.submittedData
25+
const formContents = test.submittedData(dataFile);
2226

2327
let I;
2428
let page;
29+
let browser;
2530
let FS;
2631
const siteUrl = TestHelper.siteUrl();
2732

test/helper/webapi.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import test from '../../lib/utils.js'; // importing test method
1010

1111
// To get __dirname in ESM
1212
import { fileURLToPath } from 'url';
13+
import {unlinkSync} from "node:fs";
1314
const __filename = fileURLToPath(import.meta.url);
1415
const __dirname = path.dirname(__filename);
1516

@@ -25,17 +26,17 @@ let I;
2526
let data;
2627
let siteUrl;
2728

28-
export const init = function (testData) {
29+
export function init (testData) {
2930
data = testData;
30-
};
31+
}
3132

32-
export const tests = function () {
33+
export function tests () {
3334
const isHelper = helperName => I.constructor.name === helperName;
3435

3536
beforeEach(() => {
3637
I = data.I;
3738
siteUrl = data.siteUrl;
38-
if (fileExists(dataFile)) require('fs').unlinkSync(dataFile);
39+
if (fileExists(dataFile)) unlinkSync(dataFile);
3940
});
4041

4142
describe('#saveElementScreenshot', () => {

0 commit comments

Comments
 (0)