Skip to content

Commit

Permalink
fix: actions, playwright, pw_test, stepbystep report, webapi
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Sep 23, 2024
1 parent 6f5f03b commit b5f9f3a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 47 deletions.
26 changes: 10 additions & 16 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import recorder from '../recorder.js';
import { includes as stringIncludes } from '../assert/include.js';
import { urlEquals, equals } from '../assert/equal.js';
import { empty } from '../assert/empty.js';
import { truth } from '../assert/truth';
import { truth } from '../assert/truth.js';

import {
xpathLocator,
Expand All @@ -25,34 +25,28 @@ import {
normalizeSpacesInString,
} from '../utils.js';

import { isColorProperty, convertColorToRGBA } from '../colorUtils';
import { isColorProperty, convertColorToRGBA } from '../colorUtils.js';
import ElementNotFound from './errors/ElementNotFound.js';
import RemoteBrowserConnectionRefused from './errors/RemoteBrowserConnectionRefused';
import Popup from './extras/Popup';
import Console from './extras/Console';
import { findByPlaywrightLocator, findReact, findVue } from './extras/PlaywrightReactVueLocator';
import RemoteBrowserConnectionRefused from './errors/RemoteBrowserConnectionRefused.js';
import Popup from './extras/Popup.js';
import Console from './extras/Console.js';
import { findByPlaywrightLocator, findReact, findVue } from './extras/PlaywrightReactVueLocator.js';

import {
setRestartStrategy, restartsSession, restartsContext, restartsBrowser,
} from './extras/PlaywrightRestartOpts';
import { createValueEngine, createDisabledEngine } from './extras/PlaywrightPropEngine';
} from './extras/PlaywrightRestartOpts.js';
import { createValueEngine, createDisabledEngine } from './extras/PlaywrightPropEngine.js';

import {
seeElementError,
dontSeeElementError,
dontSeeElementInDOMError,
seeElementInDOMError,
} from './errors/ElementAssertion';

import {
createAdvancedTestResults,
allParameterValuePairsMatchExtreme,
extractQueryObjects,
} from './network/utils.js';
} from './errors/ElementAssertion.js';

import {
dontSeeTraffic, seeTraffic, grabRecordedNetworkTraffics, stopRecordingTraffic, flushNetworkTraffics,
} from './network/actions';
} from './network/actions.js';

let playwright;
let perfTiming;
Expand Down
21 changes: 7 additions & 14 deletions lib/helper/network/actions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const assert = require('assert');
const { isInTraffic, createAdvancedTestResults, getTrafficDump } = require('./utils');
import assert from 'assert'
import { isInTraffic, createAdvancedTestResults, getTrafficDump } from './utils.js';

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

async function seeTraffic({
export async function seeTraffic({
name, url, parameters, requestPostData, timeout = 10,
}) {
if (!name) {
Expand Down Expand Up @@ -65,7 +65,7 @@ async function seeTraffic({
}
}

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

function stopRecordingTraffic() {
export function stopRecordingTraffic() {
// @ts-ignore
this.page.removeAllListeners('request');
this.recording = false;
}

function flushNetworkTraffics() {
export function flushNetworkTraffics() {
this.requests = [];
}

module.exports = {
dontSeeTraffic,
seeTraffic,
grabRecordedNetworkTraffics,
stopRecordingTraffic,
flushNetworkTraffics,
};
4 changes: 2 additions & 2 deletions lib/plugin/stepByStepReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export default function (config) {
try {
await helper.saveScreenshot(path.relative(reportDir, path.join(dir, fileName)), config.fullPageScreenshots);
} catch (err) {
output.plugin(`Can't save step screenshot: ${err}`);
output.output.plugin(`Can't save step screenshot: ${err}`);
error = err;
return;
} finally {
Expand All @@ -164,7 +164,7 @@ export default function (config) {

const allureReporter = Container.plugins('allure');
if (allureReporter && config.screenshotsForAllureReport) {
output.plugin('stepByStepReport', 'Adding screenshot to Allure');
output.output.plugin('stepByStepReport', 'Adding screenshot to Allure');
allureReporter.addAttachment(`Screenshot of step ${step}`, fs.readFileSync(path.join(dir, fileName)), 'image/png');
}
}
Expand Down
27 changes: 16 additions & 11 deletions test/helper/Playwright_test.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
import path from 'path';
import fs from 'fs';
import playwright from 'playwright';
import TestHelper from '../support/TestHelper';
import Playwright from '../../lib/helper/Playwright';
import TestHelper from '../support/TestHelper.js';
import Playwright from '../../lib/helper/Playwright.js';
import AssertionFailedError from '../../lib/assert/error.js';
import webApiTests from './webapi';
import * as webApiTests from './webapi.js';
import FileSystem from '../../lib/helper/FileSystem.js';
import { deleteDir } from '../../lib/utils.js';
import Secret from '../../lib/secret.js';

let assert;
let expect;
import('chai').then(chai => {
assert = chai.assert;
expect = chai.expect;
});
global.codeceptjs = require('../../lib');
import { expect, assert } from 'chai';
import test from '../../lib/utils.js'; // importing test method
global.codeceptjs = '../../lib'

// To get __dirname in ESM
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Path to data file
const dataFile = path.join(__dirname, '/../data/app/db');
const formContents = require('../../lib/utils.js').test.submittedData(dataFile);

// Accessing formContents from test.submittedData
const formContents = test.submittedData(dataFile);

let I;
let page;
let browser;
let FS;
const siteUrl = TestHelper.siteUrl();

Expand Down
9 changes: 5 additions & 4 deletions test/helper/webapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import test from '../../lib/utils.js'; // importing test method

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

Expand All @@ -25,17 +26,17 @@ let I;
let data;
let siteUrl;

export const init = function (testData) {
export function init (testData) {
data = testData;
};
}

export const tests = function () {
export function tests () {
const isHelper = helperName => I.constructor.name === helperName;

beforeEach(() => {
I = data.I;
siteUrl = data.siteUrl;
if (fileExists(dataFile)) require('fs').unlinkSync(dataFile);
if (fileExists(dataFile)) unlinkSync(dataFile);
});

describe('#saveElementScreenshot', () => {
Expand Down

0 comments on commit b5f9f3a

Please sign in to comment.