我尝试从多个页面中截取屏幕截图,这些页面应完全加载(包括延迟加载的图像),以便以后进行比较。
我发现了lazyimages_without_scroll_events.js示例,该示例很有帮助。
使用以下代码,屏幕快照看起来不错,但是存在一些主要问题。
async function takeScreenshot(browser, viewport, route) {
return browser.newPage().then(async (page) => {
const fileName = `${viewport.directory}/${getFilename(route)}`;
await page.setViewport({
width: viewport.width,
height: 500,
});
await page.goto(
`${config.server.master}${route}.html`,
{
waitUntil: 'networkidle0',
}
);
await page.evaluate(() => {
/* global document,requestAnimationFrame */
let lastScrollTop = document.scrollingElement.scrollTop;
// Scroll to bottom of page until we can't scroll anymore.
const scroll = () => {
document.scrollingElement.scrollTop += 100;
if (document.scrollingElement.scrollTop !== lastScrollTop) {
lastScrollTop = document.scrollingElement.scrollTop;
requestAnimationFrame(scroll);
}
}; …Run Code Online (Sandbox Code Playgroud) 我尝试使用带有后备包的 JS ES 模块,由 rollup.js 生成。
标准import没有问题。但是我有动态导入的问题。
我在这里上传了完整的设置示例:https : //www.file-upload.net/download-13588759/gulp-setup-example.zip.html
Run:
1. yarn install
2. gulp test
The setup of the gulpfile.babel.js is:
import buffer from 'vinyl-buffer';
import gulp from 'gulp';
import loadPlugins from 'gulp-load-plugins';
import rollup from 'rollup-stream';
import rollupPluginBabel from 'rollup-plugin-babel';
import source from 'vinyl-source-stream';
const $_ = loadPlugins();
/*
* JavaScript
*/
function processJavaScriptMain() {
return rollup({
input: 'src/main.mjs',
format: 'es',
sourcemap: true,
plugins: [
rollupPluginBabel({
exclude: 'node_modules/**',
}),
],
})
.pipe(source('main.mjs', …Run Code Online (Sandbox Code Playgroud) javascript ×2
babeljs ×1
es6-modules ×1
gulp ×1
node.js ×1
puppeteer ×1
rollupjs ×1
testing ×1