Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@
],
"default": "3way",
"description": "%configuration.playwright.updateSourceMethod%"
},
"playwright.recordStartUrl": {
"type": "string",
"default": "",
"pattern": "^$|^[a-zA-Z]+://",
"patternErrorMessage": "%configuration.playwright.recordStartUrl.patternErrorMessage%",
"description": "%configuration.playwright.recordStartUrl%"
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions package.nls.de.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"configuration.playwright.pickLocatorCopyToClipboard": "Markierten Locator automatisch in die Zwischenablage kopieren.",
"configuration.playwright.updateSnapshots": "Snapshots aktualisieren",
"configuration.playwright.updateSourceMethod": "Quellmethode aktualisieren",
"configuration.playwright.recordStartUrl": "URL, zu der beim Aufzeichnen eines neuen Tests navigiert wird.",
"configuration.playwright.recordStartUrl.patternErrorMessage": "URL muss ein Schema enthalten, z.B. https://example.com",
"views.test.pw.extension.locatorsView": "Locator",
"views.test.pw.extension.settingsView": "Playwright"
}
2 changes: 2 additions & 0 deletions package.nls.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"configuration.playwright.pickLocatorCopyToClipboard": "Copier automatiquement le locator sélectionné dans le presse-papiers.",
"configuration.playwright.updateSnapshots": "Mettre à jour les captures d'écran",
"configuration.playwright.updateSourceMethod": "Mettre à jour la méthode source",
"configuration.playwright.recordStartUrl": "URL vers laquelle naviguer lors de l'enregistrement d'un nouveau test.",
"configuration.playwright.recordStartUrl.patternErrorMessage": "L'URL doit inclure un schéma, par ex. https://example.com",
"views.test.pw.extension.locatorsView": "Localisateurs",
"views.test.pw.extension.settingsView": "Playwright"
}
2 changes: 2 additions & 0 deletions package.nls.it.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"configuration.playwright.pickLocatorCopyToClipboard": "Copia automaticamente il locator selezionato negli appunti.",
"configuration.playwright.updateSnapshots": "Aggiorna gli snapshot",
"configuration.playwright.updateSourceMethod": "Aggiorna il metodo sorgente",
"configuration.playwright.recordStartUrl": "URL a cui navigare durante la registrazione di un nuovo test.",
"configuration.playwright.recordStartUrl.patternErrorMessage": "L'URL deve includere lo schema, ad es. https://example.com",
"views.test.pw.extension.locatorsView": "Localizzatori",
"views.test.pw.extension.settingsView": "Playwright"
}
2 changes: 2 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"configuration.playwright.pickLocatorCopyToClipboard": "Automatically copy picked locator to clipboard.",
"configuration.playwright.updateSnapshots": "Update snapshots",
"configuration.playwright.updateSourceMethod": "Update source method",
"configuration.playwright.recordStartUrl": "URL to navigate to when recording a new test.",
"configuration.playwright.recordStartUrl.patternErrorMessage": "URL must include a scheme, e.g. https://example.com",
"views.test.pw.extension.locatorsView": "Locators",
"views.test.pw.extension.settingsView": "Playwright"
}
2 changes: 2 additions & 0 deletions package.nls.zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"configuration.playwright.pickLocatorCopyToClipboard": "自动将选中的定位器复制到剪贴板",
"configuration.playwright.updateSnapshots": "更新快照",
"configuration.playwright.updateSourceMethod": "更新源方法",
"configuration.playwright.recordStartUrl": "录制新测试时要导航到的 URL。",
"configuration.playwright.recordStartUrl.patternErrorMessage": "URL 必须包含协议,例如 https://example.com",
"views.test.pw.extension.locatorsView": "定位器",
"views.test.pw.extension.settingsView": "Playwright"
}
10 changes: 8 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,9 +813,14 @@ export class Extension implements RunHooks {
if (!file)
return;

let gotoLine = '';
const recordStartUrl = this._vscode.workspace.getConfiguration('playwright').get<string>('recordStartUrl', '').trim() || undefined;
if (recordStartUrl)
gotoLine = `\n await page.goto(${JSON.stringify(recordStartUrl)});`;

await fs.promises.writeFile(file, `import { test, expect } from '@playwright/test';

test('test', async ({ page }) => {
test('test', async ({ page }) => {${gotoLine}
// Recording...
});`);

Expand All @@ -824,7 +829,8 @@ test('test', async ({ page }) => {

const document = await this._vscode.workspace.openTextDocument(file);
const editor = await this._vscode.window.showTextDocument(document);
editor.selection = new this._vscode.Selection(new this._vscode.Position(3, 2), new this._vscode.Position(3, 2 + '// Recording...'.length));
const recordingLine = recordStartUrl ? 4 : 3;
editor.selection = new this._vscode.Selection(new this._vscode.Position(recordingLine, 2), new this._vscode.Position(recordingLine, 2 + '// Recording...'.length));

return file;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/codegen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ test('test', async ({ page }) => {
}]);
});

test('should navigate to recordStartUrl when recording', async ({ activate }) => {
test.slow();

const { vscode } = await activate({
'playwright.config.js': `module.exports = {}`,
});

const configuration = vscode.workspace.getConfiguration('playwright');
configuration.update('recordStartUrl', 'https://example.com');

const webView = vscode.webViews.get('pw.extension.settingsView')!;
await webView.getByText('Record new').click();
await expect.poll(() => vscode.lastWithProgressData, { timeout: 0 }).toEqual({ message: 'recording\u2026' });

const browser = await connectToSharedBrowser(vscode);
const page = await waitForPage(browser);
// The test template includes page.goto() which navigates before recording starts.
await expect.poll(() => page.url()).toBe('https://example.com/');
});

test('running test should stop the recording', async ({ activate, showBrowser }) => {
test.skip(!showBrowser);

Expand Down