我似乎在官方文档或任何地方都找不到任何关于这方面的东西,我想测试一下我的网站标题中是否有所有正确的meta标签和OG数据。
使用CodeceptJs和Puppeteer可以做到这一点吗?
发布于 2020-04-20 17:34:46
您可以使用seeElementInDOM方法在DOM中查找元素。
或者,您可以使用grabSource抓取页面HTML源代码,并将元标记检查为包含在该源代码中的字符串
发布于 2020-04-20 21:36:16
通过使用帮助器解决了它
class CustomHelper extends Helper {
async getPageOGTitle() {
const page = this.helpers['Puppeteer'].page;
const description = await page.$eval(
"head > meta[property='og:title']",
element => element.content
);
return description;
}
}然后在我的测试中使用它
Scenario('Page Have OG title', async I => {
const OGTitle = await I.getPageOGTitle();
console.log(OGTitle);
});https://stackoverflow.com/questions/61316062
复制相似问题