testing - BackstopJS 测试整个应用程序页面
问题描述
如何测试 backstop JS 中的所有页面。我只能测试一页。因为我只给出一个 url 和 referenceURL。我们怎样才能让它测试应用程序中的所有页面。只提供了一张截图。需要找到应用程序中的所有屏幕截图和更改。
解决方案
您可以为每个页面设置不同的场景并运行测试。或者你可以有两个文件来保持它的通用性和可重用性,并在一个文件中声明所有页面和设备详细信息,如下所示
基本配置.js
const projectId = "test"; //
let baseUrl = "YourURL"; //
// Replace the values of the below array with the relative URLs of your website. E.g., "/about", "/contact", "/pricing", etc.
// Use just "/" to test the homepage of your website.
// Add as many relative URLs as you need.
const relativeUrls =[
"/about",
"/documentation",
"/case-studies/",
"/solutions/",
"/blog/"
];
// Leave the below array as is if you want to test your website using the viewports listed below.
// The suported viewports are: phone (320px X 480px), tablet (1024px X 768px), and desktop (1280px X 1024px).
// No other viewports are supported.
// You can remove the viewports that you don't need, but at least one of them is required.
const viewports = [
"phone",
"tablet",
"desktop",
];
module.exports = {
baseUrl,
projectId,
relativeUrls,
viewports
};
在其他文件中,保留场景配置。
mainConfig.js
const THREE_SECONDS_IN_MS = 3000;
const scenarios = [];
const viewports = [];
basicConfig.relativeUrls.map(relativeUrl => {
scenarios.push({
label: relativeUrl,
url: `${basicConfig.baseUrl}${relativeUrl}`,
requireSameDimensions: false
});
});
basicConfig.viewports.map(viewport => {
if (viewport === "phone") {
pushViewport(viewport, 320, 480);
}
if (viewport === "tablet") {
pushViewport(viewport, 1024, 768);
}
if (viewport === "desktop") {
pushViewport(viewport, 1280, 1024);
}
});
function pushViewport(viewport, width, height) {
viewports.push({
name: viewport,
width,
height,
});
}
module.exports = {
id: basicConfig.projectId,
viewports,
scenarios,
paths: {
bitmaps_reference: "test/backstop_data/bitmaps_reference",
bitmaps_test: "test/backstop_data/bitmaps_test",
html_report: "test/backstop_data/html_report"
},
report: ["CI"],
engine: "puppeteer",
engineOptions: {
args: ["--no-sandbox"]
},
asyncCaptureLimit: 5,
asyncCompareLimit: 50,
};
希望对您有所帮助,如果您需要任何其他帮助,请告诉我。
谢谢!
推荐阅读
- node.js - ECS Fargate 上的 EFS 挂载 - 非 root 用户的读/写权限被拒绝
- c++ - 如何在 VS Code 或 Visual Studio 上运行 MPI?
- mongodb - 列出所有产品并检查它们是否已经在您的收藏夹中或不在 MongoDB 中
- javascript - Html2pdf.js 结果是 vue 中的空白 PDF
- python - 根据python中的子字符串和字典重命名列
- elasticsearch - 计算索引大小的最佳方法是什么
- javascript - 在 mongodb 中的 1 个变量下定义 2 种类型
- css - 嵌套内联元素“垂直对齐”在 Chrome 和 Firefox 上的行为不同
- javascript - 保护 API 调用不暴露给第三方
- kotlin - 如何删除集合视图中的图像?