Skip to content

Instantly share code, notes, and snippets.

@ycabon
Last active October 9, 2018 21:40
Show Gist options
  • Save ycabon/91592e380976a4ccf678c62fa53ec7fc to your computer and use it in GitHub Desktop.
Save ycabon/91592e380976a4ccf678c62fa53ec7fc to your computer and use it in GitHub Desktop.
Using Puppeter with MapView
const puppeteer = require('puppeteer');
const viewport = {
width: 1920,
height: 1080
}
async function testPage(name, url) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport(viewport);
await page.setCacheEnabled(false);
await page.goto(url);
let MapViewHandle;
let viewInstances;
try {
// Get the MapView prototype
MapViewHandle = await page.evaluateHandle(`require("esri/views/MapView").prototype`);
// Query of all the instances of MapViews
viewInstances = await page.queryObjects(MapViewHandle);
await page.waitFor(
views => views.every(view => {
return view.ready && view.stationary && !view.updating
}),
{
timeout: 120000
},
viewInstances
);
}
catch(error) {
console.error(`Skipping "${name}"`, error);
await browser.close();
return null;
}
await page.screenshot({path: `screenshots/${name}.png`});
MapViewHandle && await MapViewHandle.dispose();
viewInstances && await viewInstances.dispose();
await browser.close();
}
(async () => {
await testPage('layers-csv-projection', `https://developers.arcgis.com/javascript/latest/sample-code/layers-csv-projection/live/index.html`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment