|
| 1 | + |
| 2 | +const fse = require('fs-extra'); |
| 3 | +const outputDirectory = 'build/screenshots'; |
| 4 | + |
| 5 | +//console.info('Building bpmn-visualization html documentation'); |
| 6 | + |
| 7 | +// clean existing screenshots |
| 8 | +fse.removeSync(outputDirectory); |
| 9 | +fse.ensureDirSync(outputDirectory); |
| 10 | + |
| 11 | + |
| 12 | +// Set options as a parameter, environment variable, or rc file. |
| 13 | +// eslint-disable-next-line no-global-assign |
| 14 | + |
| 15 | +// Notice a proper package name in require |
| 16 | +const {chromium} = require('playwright-chromium'); |
| 17 | + |
| 18 | +// TODO for each version, access the page, wait for load, do a screenshot, save it as a file |
| 19 | + |
| 20 | +(async () => { |
| 21 | + const browser = await chromium.launch({headless: false}); |
| 22 | + const page = await browser.newPage(); |
| 23 | + // if we want to set the viewport dimensions |
| 24 | + // could be interesting to avoid blank around the diagram and avoid cropping during post-processing |
| 25 | + // browser.newContext({ |
| 26 | + // viewport: { |
| 27 | + // width: 800, |
| 28 | + // height: 600, |
| 29 | + // }, |
| 30 | + // }); |
| 31 | + // browserContext.newPage() |
| 32 | + // await browserContext.close(); |
| 33 | + // or await page.setViewportSize({ width: 1600, height: 1200 }); |
| 34 | + |
| 35 | + // TODO to be retrieved by checking the resources directory |
| 36 | + const versions = [ |
| 37 | + '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', |
| 38 | + '0.2.0', '0.3.0', '0.5.0', '0.6.0', '0.7.0', '0.10.0',]; |
| 39 | + let counter = 0; |
| 40 | + for (let version of versions) { |
| 41 | + counter++; |
| 42 | + |
| 43 | + // TODO choose the miwg-test-suite file to load by passing a query parameter |
| 44 | + await page.goto(`http://localhost:8002/tools/version-comparator/resources/${version}/index.html`); |
| 45 | + // TODO check that the title matches the version? |
| 46 | + const title = await page.title(); |
| 47 | + console.info('page title', title); |
| 48 | + |
| 49 | + // TODO wait for generated element instead of waiting for 1 second (risk of flaky generation, see https://playwright.dev/docs/api/class-page#pagewaitfortimeouttimeout) |
| 50 | + // we do this in tests (for specific elements, this require data attribute that are not available in all versions or the attribute name changes from version to version |
| 51 | + // we could at least check mxgraph initialization (svg node in the bpmn-container, but it may not have the same id in all pages) |
| 52 | + // or check the existence of bpmn svg nodes (probably the easiest way as they will be present for all versions) |
| 53 | + console.info('Waiting for diagram rendering...'); |
| 54 | + await page.waitForTimeout(1000); |
| 55 | + console.info('Wait done'); |
| 56 | + |
| 57 | + const countValue = String(counter).padStart(2, '0') |
| 58 | + await page.screenshot({ path: `${outputDirectory}/B.2.0-${countValue}-${version}.png` }); |
| 59 | + } |
| 60 | + |
| 61 | + // TODO properly exit the script |
| 62 | + await browser.close(); |
| 63 | + process.exit(0); |
| 64 | +})(); |
| 65 | + |
| 66 | +// https://playwright.dev/docs/screenshots |
0 commit comments