Skip to content

Commit 43b4f55

Browse files
committed
Revert "cleanup"
This reverts commit c5f7391.
1 parent c5f7391 commit 43b4f55

6 files changed

Lines changed: 57 additions & 50 deletions

File tree

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
### v2.0.59
2+
* added basic support for #16 `Support 'global' page object` and #3 `support nested page object models`
3+
4+
### v2.0.57
5+
* updated readme, recorded demo video
6+
7+
### v2.0.56
8+
* cli command fix
9+
10+
### v2.0.53
11+
* Display currently executing lines of code in repl on-screen
12+
* fix many issues after page navigation (tool only worked for SPAs previously)
13+
* changed (broken) postinstall to cli command `npx @dnvgl/playwright-live-recorder`
14+
15+
### v2.0.52
16+
* UI rework
17+
* Now aware of Page Object Model helper methods
18+
19+
### v2.0.48
20+
* Live code execution method much simplified and much more robust (todo: write tech doc about this)
21+
* bugfix: Make page object model tools build correct paths on non-windows filesystems
22+
23+
----
24+
25+
126
![Playwright live recorder infographic](docs/playwright-live-recorder-infographic.png "Playwright live recorder infographic")
227

328

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"lodash": "^4.17.21",
3636
"ts-morph": "^16.0.0",
3737
"ts-node": "^10.9.2",
38-
"typescript": "^5.8.3"
38+
"typescript": "^4.8.2"
3939
},
4040
"packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
4141
}

src/main.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import { testFileWriter } from "./testFileWriter";
99
import { hotModuleReload } from "./hotModuleReload";
1010
import { pageObjectModel } from "./pageObjectModel";
1111
import { getTestCallingLocation } from "./utility";
12+
import fs from 'fs/promises';
1213
import process from 'node:process';
13-
import { pathToFileURL } from 'node:url';
14+
import { ts } from "ts-morph";
1415
import { PlaywrightLiveRecorderConfig, PlaywrightLiveRecorderConfigFile, PlaywrightLiveRecorderConfig_recorder, PlaywrightLiveRecorderConfig_pageObjectModel, PlaywrightLiveRecorderConfig_diagnostic, TestCallingLocation } from "./types";
1516
export { PlaywrightLiveRecorderConfig, PlaywrightLiveRecorderConfigFile, PlaywrightLiveRecorderConfig_recorder, PlaywrightLiveRecorderConfig_pageObjectModel, PlaywrightLiveRecorderConfig_diagnostic, TestCallingLocation };
1617

@@ -165,7 +166,7 @@ export class ${className} {
165166
await page.addScriptTag({ path: config.recorder.path });
166167
await page.addScriptTag({ path: config.diagnostic.browserCodeJSPath });
167168
await page.addStyleTag({ path: config.diagnostic.browserCodeCSSPath });
168-
await pageObjectModel.reloadAll(page);
169+
await pageObjectModel.reloadAll(config.pageObjectModel.path, page);
169170
});
170171

171172
page.on('dialog', dialog => {/* allow user interaction for browser input dialog interaction */ });
@@ -183,15 +184,25 @@ export class ${className} {
183184

184185
export let configFilePath = './live-recorder.config.ts';
185186
export async function _configFromFile() {
187+
//todo - try rewriting to use dynamic import instead
186188
try {
187-
const cacheBustedUrl = `${pathToFileURL(nodePath.resolve(configFilePath)).href}?t=${Date.now()}`;
188-
return (await import(cacheBustedUrl)).default as PlaywrightLiveRecorderConfig | undefined;
189-
} catch (err: any) {
190-
if (err.code === 'ERR_MODULE_NOT_FOUND' || err.code === 'MODULE_NOT_FOUND') return;
191-
console.error('Error loading config file:', err);
189+
const fileContents = await fs.readFile(configFilePath, { encoding: 'utf8' });
190+
const transpiled = ts.transpileModule(fileContents, { compilerOptions: { module: ts.ModuleKind.ESNext, strict: false } });
191+
const cleanedUp = _cleanUpTranspiledSource(transpiled.outputText);
192+
const obj = eval(cleanedUp);
193+
return <PlaywrightLiveRecorderConfig | undefined>obj;
194+
} catch (err) {
195+
if ((<any>err).code === 'MODULE_NOT_FOUND') return;
196+
console.error(err);
192197
}
193198
}
194199

200+
function _cleanUpTranspiledSource(transpiled: string) {
201+
return transpiled
202+
.replaceAll(/\bimport\b\s*({?\s*[^};]+}?)\s*from\s*([^;]*);?/g, '')
203+
.replace('export default ', '');
204+
}
205+
195206

196207

197208

src/pageObjectModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export module pageObjectModel {
179179
function classNameFromPath(path: string) { return /([^/]+).ts/.exec(path)![1]; }
180180
function fullRelativePath(path: string, config: { path: string }) { return nodePath.normalize(nodePath.join(config.path, path)); }
181181

182-
export async function reloadAll(page: Page) {
182+
export async function reloadAll(configPath: string, page: Page) {
183183
if (!currentPageFilePath) return;
184184
await reload(page);
185185
}

src/types.d.ts

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,26 @@ export type PlaywrightLiveRecorderConfig_pageObjectModel = {
4949
/**
5050
* @remarks use to override/alias url fragments to page object model name
5151
* @example { '': 'home', 'login/corporate' : 'login', 'login/personal' : 'login' } //redirect from root address to 'home' pom. use same pom for login/corporate and login/personal
52-
* @default {}
5352
*/ aliases: {[key: string]: string},
5453
/** @remarks Use this to find list of all selectors, and lookup method from selector @default /(.+)_selector\b/*/
5554
propertySelectorRegex: RegExp,
5655
/** @remarks Use this to find list of nested page objects within a given page object model file @default /(.+)_page\b/*/
5756
propertyNestedTypeRegex: RegExp,
58-
/** @remarks Use this to specify the text appended when LEFT clicked on in record mode @default [ ['input[type="text"], input[type=""], textarea', 'await $1.fill("");'], ['*', 'await $1.click();'] ] */
57+
/** @remarks Use this to specify the text appended when LEFT clicked on in record mode @default [ ["input[type="text"]", 'fill()'], ["textarea", 'fill()'], ["/.*\/", "click()"] ] */
5958
primaryActionByCssSelector: [string, string][],
60-
/** @remarks Use this to specify the text appended when RIGHT clicked on in record mode @default [ ['input[type="text"], textarea', 'await expect($1.innerText()).toContain("");'], ['*', 'await expect($1.innerText()).toContain("");'], ['*', 'await expect($1).toBeVisible();'], ['*', 'await expect($1).toBeEnabled();'] ]*/
59+
/** @remarks Use this to specify the text appended when RIGHT clicked on in record mode @default [ ["input[type="text"]", "await expect($1.innerText()).toContain('')"], ["textarea", "innerText().toContain('')"], ["/.*\/", ""]]*/
6160
secondaryActionByCssSelector: [string, string][],
6261
/** @default (className) =>
63-
`import type { Page } from '@playwright/test';
62+
`import { Page } from "@playwright/test";
6463
65-
export class ${className} {
64+
export class ${className} {
6665
67-
}`,
66+
}`,
6867
*/
6968
generateClassTemplate: (className: string) => string,
7069
/** @default (name, selector) =>
7170
` private static ${name}_selector = \`${selector}\`;\r\n` +
72-
` static ${name}(page: Page) { return page.locator(this.${name}_selector); }\r\n\r\n`,
71+
` static ${name}(page: Page) { return page.locator(\`this.${name}_selector\`); }\r\n\r\n`,
7372
*/
7473
generatePropertyTemplate: (name: string, selector: string) => string,
7574

@@ -81,42 +80,14 @@ export class ${className} {
8180
/** @default 'salmon' */
8281
color: string,
8382
/** @default (el, color) => {
84-
if (el.getAttribute('data-background') == null) el.setAttribute('data-background', el.style.background);
85-
el.style.background = color ?? 'salmon';
83+
el.setAttribute('data-background', el.style.background);
84+
el.style.background = color;
8685
},
8786
*/
8887
on: (el: HTMLElement, color: string) => void,
8988
/** @default (el) => el.style.background = el.getAttribute('data-background') ?? '', */
9089
off: (el: HTMLElement) => void,
9190
},
92-
/** @default `data:text/javascript,
93-
import { promises as fs } from 'fs';
94-
import { fileURLToPath } from 'url';
95-
96-
const resolvedFilenames = new Set();
97-
98-
export async function resolve(specifier, context, nextResolve) {
99-
const resolved = await nextResolve(specifier, context);
100-
if (!resolved.url.endsWith('.ts')) return resolved;
101-
102-
const urlFilename = fileURLToPath(resolved.url);
103-
const modifyMs = await fs.stat(urlFilename).then(stat => Math.floor(stat.mtimeMs));
104-
resolved.url = resolved.url.replace(/.ts$/, '.cachebust.' + modifyMs + '.ts');
105-
return resolved;
106-
}
107-
108-
export async function load(url, context, nextLoad) {
109-
const original = url.replace(/\\.cachebust\\.\\d+.ts$/, '.ts');
110-
if (original === url || resolvedFilenames.has(url)) return await nextLoad(url, context);
111-
const urlFilename = fileURLToPath(url);
112-
const originalFilename = fileURLToPath(original);
113-
await fs.copyFile(originalFilename, urlFilename);
114-
const result = await nextLoad(url, context);
115-
await fs.rm(urlFilename);
116-
resolvedFilenames.add(url);
117-
return result;
118-
}
119-
` */
12091
importerCustomizationHooks: string,
12192
}
12293

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,10 +2091,10 @@ tsutils@^2.29.0:
20912091
dependencies:
20922092
tslib "^1.8.1"
20932093

2094-
typescript@^5.8.3:
2095-
version "5.8.3"
2096-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.8.3.tgz#92f8a3e5e3cf497356f4178c34cd65a7f5e8440e"
2097-
integrity sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==
2094+
typescript@^4.8.2:
2095+
version "4.8.2"
2096+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.2.tgz#e3b33d5ccfb5914e4eeab6699cf208adee3fd790"
2097+
integrity sha512-C0I1UsrrDHo2fYI5oaCGbSejwX4ch+9Y5jTQELvovfmFkK3HHSZJB8MSJcWLmCUBzQBchCrZ9rMRV6GuNrvGtw==
20982098

20992099
undici-types@~6.20.0:
21002100
version "6.20.0"

0 commit comments

Comments
 (0)