如果我确实将屏幕截图与实时应用程序进行比较,那么它就会失败。最好的方法是什么以及如何比较 Cypress 中的屏幕截图
输出:在 cypress 上获取错误日志
用于比较屏幕截图的已安装依赖项
npm install --save-dev cypress-image-snapshot @types/cypress-image-snapshot
Run Code Online (Sandbox Code Playgroud)
// code on commond.js file.
const compareSnapshotCommand = require('cypress-image-diff-js/dist/command')
compareSnapshotCommand();
// code on cypress.config.json
const getCompareSnapshotsPlugin = require('cypress-image-diff-js/dist/plugin')
getCompareSnapshotsPlugin(on, config)
// .js test scenario on test file
describe('compare the homepage screen shot with the application homepage', () => {
it('should compare the homepage', () => {
cy.visit("/");
cy.compareSnapshot('fixtures/healthcaresuccess-page.png', 0.001);
}
Run Code Online (Sandbox Code Playgroud) 我想在 Cypress 中检查名称文档列的所有行中的内容是否相同。比方说
名称 文件 | 签发日期 |
---|---|
戈尔 | 2023年6月21日 |
戈尔 | 2023年5月30日 |
该表没有固定的行数。
附加问题:如何检查最新的(发布日期列)是否位于顶部?
我试图将断言传递给 if 条件,并在满足条件时执行一个逻辑,在条件失败时执行另一个逻辑。
由于测试因断言失败而失败,我无法达到预期的结果。
我尝试了以下...
if(cy.get("div").length \> 0) {
cy.log("print this")
} else {
cy.log("print this")
}
Run Code Online (Sandbox Code Playgroud)
或者
if(cy.get("div").should('have.length.greaterThan', 0) {
cy.log("print this")
} else {
cy.log("print this")
}
Run Code Online (Sandbox Code Playgroud) 我制作的 bash 脚本遇到了问题。对于上下文,我编写了 NPM 脚本来在命令行上运行 Cypress 测试。我的目标是拥有一个 bash 脚本来运行每个 NPM 脚本,并在命令行中执行 Cypress。另外供参考,我的 script.sh 位于项目文件夹中。
如果我从终端手动运行 NPM 脚本,就没有问题。赛普拉斯有效。这是我拥有的 NPM 脚本的示例:
"cypress:window": "./node_modules/.bin/cypress open",
Run Code Online (Sandbox Code Playgroud)
问题是当我将这些命令放入 bash 脚本中时。现在,当 script.sh 运行时,它以 code=1 执行,并且实际上根本不运行 Cypress。我的 script.sh 只是:
npm run cypress:window
Run Code Online (Sandbox Code Playgroud) cypress ×4
automation ×1
bash ×1
cypress-conditional-testing ×1
html-table ×1
javascript ×1
node.js ×1
npm ×1
screenshot ×1
sh ×1