cypress - Cypress - 如何使用 cypress 命令验证 PDF 文件中的数据
问题描述
以下是我在柏树中的代码。如何使用 cypress .contains 或 .eq 打印“pdf”内容并验证内容?当我运行代码时它会打印 object{6} 但我想打印我的 pdf 文件内容。我非常感谢您的帮助。
**Plugins/index.js:**
const fs = require('fs')
const pdf = require('pdf-parse')
const path = require('path')
const repoRoot = path.join("C:/Users/XXXXX/Downloads/loginCy-excel")
const parsePdf = async (pdfName) => {
const pdfPathname = path.join(repoRoot, pdfName)
let dataBuffer = fs.readFileSync(pdfPathname);
return await pdf(dataBuffer)
}
module.exports = (on, config) => {
on('task', {
getPdfContent (pdfName) {
return parsePdf(pdfName)
},
})
}
**cypress spec file has these code:**
it('tests a pdf', () => {
cy.task('getPdfContent', 'sample.pdf').then(content => {
cy.log(content)
})
})
解决方案
pdf
方法将返回一个 object,所以我想cy.log()
不能那样打印它。如果您想查看函数在您的 pdf 文件中收集的内容,可以将结果字符串化:
cy
.log(JSON.stringify(content));
如果您只想从 pdf 中获取文本,则需要使用text
属性:
cy
.log(content.text);
推荐阅读
- azure - 在 RESTful api 中传递超过 1000 个参数
- amazon-s3 - 使用 S3 的 api 网关代理从 S3 读取羽毛文件
- solidity - 即使我有一个应付回退功能来接收 eth,但当我在不发送 eth 的情况下进行部署时,它仍然可以正常工作
- arrays - 如何使用数组搜索内爆数组?
- javascript - 使用 state 或 material-top-tab,最佳实践是什么?
- python - 只能从 TKinter 窗口中清除一项
- firefox - 如何在 Firefox(applescript)中“等待网页加载”?
- python - 如何使用 Flask/python 在特定时间间隔内记录物联网数据
- python - 试图让一个不和谐的机器人在启动时加入
- plot - 为什么 Plot 在 Octave 中隐藏另一个 Plot?