Record tests using same setup as the test runner

no issue
This commit is contained in:
Sam Lord 2022-12-07 10:59:45 +00:00
parent 8c41807978
commit d6072ea0e8
3 changed files with 12 additions and 27 deletions

View File

@ -1,46 +1,29 @@
const {chromium} = require('@playwright/test'); const {chromium} = require('@playwright/test');
const Command = require('./command'); const Command = require('./command');
const testUtils = require('../../test/utils'); const playwrightConfig = require('../../playwright.config');
const {globalSetup} = require('../../test/e2e-browser/utils');
module.exports = class RecordTest extends Command { module.exports = class RecordTest extends Command {
setup() { setup() {
this.help('Use PlayWright to record a browser-based test'); this.help('Use PlayWright to record a browser-based test');
this.argument('--admin', {type: 'boolean', defaultValue: false, desc: 'Start browser-based test in Ghost admin'});
this.argument('--no-setup', {type: 'boolean', defaultValue: false, desc: 'Disable the default setup, for testing Ghost admin setup'});
this.argument('--fixtures', {type: 'array', defaultValue: [], delimiter: ',', desc: 'A list of comma-separated fixtures to include'});
} }
permittedEnvironments() { permittedEnvironments() {
return ['testing-browser']; return ['testing-browser'];
} }
async handle(argv) { async handle() {
const app = await testUtils.startGhost(); await globalSetup({
projects: [playwrightConfig]
if (argv.fixtures.length > 0) { });
await testUtils.initFixtures(...argv.fixtures);
}
const browser = await chromium.launch({headless: false}); const browser = await chromium.launch({headless: false});
const baseURL = argv.admin ? `${app.url}ghost/` : app.url; const context = await browser.newContext(playwrightConfig.use);
const context = await browser.newContext({
baseURL
});
// Pause the page, and start recording manually. // Pause the page, and start recording manually.
const page = await context.newPage(); const page = await context.newPage();
await page.goto(''); await page.goto('/ghost');
if (argv.admin && !argv['no-setup']) {
await page.getByPlaceholder('The Daily Awesome').click();
await page.getByPlaceholder('The Daily Awesome').fill('The Local Test');
await page.getByPlaceholder('Jamie Larson').fill('Testy McTesterson');
await page.getByPlaceholder('jamie@example.com').fill('testy@example.com');
await page.getByPlaceholder('At least 10 characters').fill('Mc.T3ster$0n');
await page.getByPlaceholder('At least 10 characters').press('Enter');
await page.locator('.gh-done-pink').click();
}
await page.pause(); await page.pause();
} }

View File

@ -4,7 +4,6 @@ const {spawn, exec} = require('child_process');
const {knex} = require('../../../core/server/data/db'); const {knex} = require('../../../core/server/data/db');
const {setupGhost, setupStripe} = require('./e2e-browser-utils'); const {setupGhost, setupStripe} = require('./e2e-browser-utils');
const {chromium} = require('@playwright/test'); const {chromium} = require('@playwright/test');
const models = require('../../../core/server/models');
const {startGhost} = require('../../utils/e2e-framework'); const {startGhost} = require('../../utils/e2e-framework');
const {stopGhost} = require('../../utils/e2e-utils'); const {stopGhost} = require('../../utils/e2e-utils');

View File

@ -1 +1,4 @@
module.exports = require('./e2e-browser-utils'); module.exports = {
...require('./e2e-browser-utils'),
globalSetup: require('./global-setup')
};